Documentation
¶
Overview ¶
Package trait handles trait processing for component rendering.
Traits can create new resources and patch existing resources generated by the ComponentType.
Index ¶
- func FindTargetResources(resources []map[string]any, target TargetSpec) []map[string]any
- type Processor
- func (p *Processor) ApplyTraitCreates(resources []map[string]any, trait *v1alpha1.Trait, traitContext map[string]any) ([]map[string]any, error)
- func (p *Processor) ApplyTraitPatches(resources []map[string]any, trait *v1alpha1.Trait, traitContext map[string]any) error
- func (p *Processor) ProcessTraits(resources []map[string]any, trait *v1alpha1.Trait, traitContext map[string]any) ([]map[string]any, error)
- type TargetSpec
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:
- If target.Kind is set, resource.kind must match
- If target.Group is set, the group portion of resource.apiVersion must match
- 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 ¶
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:
- Apply creates (new resources)
- Apply patches (modify existing resources)
The resources slice is modified in place by patches.