trait

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package trait handles trait processing for component rendering.

Traits can create new resources and patch existing resources generated by the ComponentType.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindTargetResources

func FindTargetResources(resources []map[string]any, target TargetSpec) []map[string]any

FindTargetResources filters resources based on Kind, Group, and Version.

Matching is done in order:

  1. If target.Kind is set, resource.kind must match
  2. If target.Group is set, the group portion of resource.apiVersion must match
  3. If target.Version is set, the version portion of resource.apiVersion must match

An empty field in the target spec means "match any value".

apiVersion is split into group/version:

  • "apps/v1" → group="apps", version="v1"
  • "v1" → group="", version="v1" (core API)

Note: Additional filtering (e.g., by name or custom where clauses) should be done by the caller after calling this function.

Types

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

Processor handles trait creates and patches.

func NewProcessor

func NewProcessor(templateEngine *template.Engine) *Processor

NewProcessor creates a new trait processor.

func (*Processor) ApplyTraitCreates

func (p *Processor) ApplyTraitCreates(
	resources []map[string]any,
	trait *v1alpha1.Trait,
	traitContext map[string]any,
) ([]map[string]any, error)

ApplyTraitCreates renders and adds new resources from trait.spec.creates.

func (*Processor) ApplyTraitPatches

func (p *Processor) ApplyTraitPatches(
	resources []map[string]any,
	trait *v1alpha1.Trait,
	traitContext map[string]any,
) error

ApplyTraitPatches applies trait patches to existing resources.

This function handles the orchestration of:

  • forEach iteration over collections
  • Resource targeting (finding which resources to patch)
  • CEL rendering of patch operations and where clauses
  • Delegating to patch.ApplyPatches for the actual patching

The patch package itself only handles the low-level mechanics of applying operations to a single resource.

func (*Processor) ProcessTraits

func (p *Processor) ProcessTraits(
	resources []map[string]any,
	trait *v1alpha1.Trait,
	traitContext map[string]any,
) ([]map[string]any, error)

ProcessTraits applies all traits to the base resources.

For each trait:

  1. Apply creates (new resources)
  2. Apply patches (modify existing resources)

The resources slice is modified in place by patches.

type TargetSpec

type TargetSpec struct {
	Kind    string
	Group   string
	Version string
	Where   string
}

TargetSpec describes how to locate a resource when applying patches.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL