trait

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 8 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 []renderer.RenderedResource, target TargetSpec) []renderer.RenderedResource

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

Matching rules:

  • If target.TargetPlane is set, resource.TargetPlane must match
  • 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

func NewProcessor(templateEngine *template.Engine) *Processor

NewProcessor creates a new trait processor.

func (*Processor) ApplyTraitCreates

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

ApplyTraitCreates renders and adds new resources from trait.spec.creates with targetPlane metadata.

func (*Processor) ApplyTraitPatches

func (p *Processor) ApplyTraitPatches(
	resources []renderer.RenderedResource,
	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, respecting targetPlane)
  • 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 []renderer.RenderedResource,
	trait *v1alpha1.Trait,
	traitContext map[string]any,
) ([]renderer.RenderedResource, error)

ProcessTraits applies all traits to the base resources.

For each trait:

  • Apply creates (new resources with targetPlane)
  • Apply patches (modify existing resources, respecting targetPlane)

type TargetSpec

type TargetSpec struct {
	Kind        string
	Group       string
	Version     string
	Where       string
	TargetPlane 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