component

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VarParameters     = "parameters"
	VarWorkload       = "workload"
	VarConfigurations = "configurations"
	VarComponent      = "component"
	VarMetadata       = "metadata"
	VarDataplane      = "dataplane"
)

Variable names available in component rendering context

View Source
const (
	VarTrait = "trait"
)

Variable names specific to trait rendering context

Variables

ComponentAllowedVariables lists all variables available in component rendering

View Source
var TraitAllowedVariables = []string{
	VarParameters,
	VarTrait,
	VarComponent,
	VarMetadata,
}

TraitAllowedVariables lists all variables available in trait rendering

Functions

func BuildComponentCELEnv

func BuildComponentCELEnv() (*cel.Env, error)

BuildComponentCELEnv creates a CEL environment for validating component resources. This environment matches the context created by BuildComponentContext in the pipeline.

func BuildTraitCELEnv

func BuildTraitCELEnv() (*cel.Env, error)

BuildTraitCELEnv creates a CEL environment for validating trait resources. This environment matches the context created by BuildTraitContext in the pipeline.

func ExtendEnvWithForEach

func ExtendEnvWithForEach(env *cel.Env, info *ForEachInfo) (*cel.Env, error)

ExtendEnvWithForEach extends a CEL environment with the forEach loop variable. The variable is typed appropriately based on the forEach analysis.

func GetForEachDescription

func GetForEachDescription(info *ForEachInfo) string

GetForEachDescription returns a human-readable description of the forEach variable

func ValidateComponentTypeResources

func ValidateComponentTypeResources(ct *v1alpha1.ComponentType) field.ErrorList

ValidateComponentTypeResources validates all resources in a ComponentType. It checks CEL expressions, forEach loops, and ensures proper variable usage.

func ValidatePatchOperation

func ValidatePatchOperation(
	op v1alpha1.JSONPatchOperation,
	validator *CELValidator,
	env *cel.Env,
	basePath *field.Path,
) field.ErrorList

ValidatePatchOperation validates a single patch operation

func ValidatePatchTarget

func ValidatePatchTarget(
	target v1alpha1.PatchTarget,
	validator *CELValidator,
	env *cel.Env,
	basePath *field.Path,
) field.ErrorList

ValidatePatchTarget validates a patch target specification

func ValidateResourceTemplate

func ValidateResourceTemplate(
	tmpl v1alpha1.ResourceTemplate,
	validator *CELValidator,
	basePath *field.Path,
) field.ErrorList

ValidateResourceTemplate validates a single resource template including forEach handling

func ValidateResourceTemplateStructure

func ValidateResourceTemplateStructure(template runtime.RawExtension, fieldPath *field.Path) (*metav1.PartialObjectMetadata, field.ErrorList)

ValidateResourceTemplateStructure validates that a resource template has required Kubernetes fields and returns the parsed metadata for reuse by callers

func ValidateTemplateBody

func ValidateTemplateBody(
	body runtime.RawExtension,
	validator *CELValidator,
	env *cel.Env,
	basePath *field.Path,
) field.ErrorList

ValidateTemplateBody walks through a template body and validates all CEL expressions

func ValidateTraitCreate

func ValidateTraitCreate(
	create v1alpha1.TraitCreate,
	validator *CELValidator,
	basePath *field.Path,
) field.ErrorList

ValidateTraitCreate validates a single trait create operation

func ValidateTraitCreatesAndPatches

func ValidateTraitCreatesAndPatches(trait *v1alpha1.Trait) field.ErrorList

ValidateTraitCreatesAndPatches validates all creates and patches in a Trait. It checks CEL expressions, forEach loops, and ensures proper variable usage.

func ValidateTraitPatch

func ValidateTraitPatch(
	patch v1alpha1.TraitPatch,
	validator *CELValidator,
	basePath *field.Path,
) field.ErrorList

ValidateTraitPatch validates a single trait patch operation

func ValidateWorkloadResources

func ValidateWorkloadResources(workloadType string, resources []v1alpha1.ResourceTemplate, basePath *field.Path) field.ErrorList

ValidateWorkloadResources validates resource templates and ensures workloadType matches a resource kind

Types

type CELValidator

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

CELValidator provides comprehensive CEL expression validation with AST analysis

func NewCELValidator

func NewCELValidator(resourceType ResourceType) (*CELValidator, error)

NewCELValidator creates a validator for the specified resource type. The validator uses different environments for ComponentType vs Trait resources to enforce proper variable access (e.g., traits can't access workload).

func (*CELValidator) GetBaseEnv

func (v *CELValidator) GetBaseEnv() *cel.Env

GetBaseEnv returns the base CEL environment for this validator

func (*CELValidator) ValidateBooleanExpression

func (v *CELValidator) ValidateBooleanExpression(expr string, env *cel.Env) error

ValidateBooleanExpression ensures the expression returns a boolean value. Used for includeWhen conditions and where filters.

func (*CELValidator) ValidateExpression

func (v *CELValidator) ValidateExpression(expr string) error

ValidateExpression validates a CEL expression with the base environment

func (*CELValidator) ValidateIterableExpression

func (v *CELValidator) ValidateIterableExpression(expr string, env *cel.Env) error

ValidateIterableExpression ensures the expression returns a list or map (for forEach).

func (*CELValidator) ValidateWithEnv

func (v *CELValidator) ValidateWithEnv(expr string, env *cel.Env) error

ValidateWithEnv validates a CEL expression with a specific environment. This is used when the environment has been extended with forEach variables.

type ExpressionWalker

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

ExpressionWalker walks through data structures to find and validate CEL expressions

func NewExpressionWalker

func NewExpressionWalker(validator *CELValidator, env *cel.Env) *ExpressionWalker

NewExpressionWalker creates a walker for finding and validating CEL expressions

func (*ExpressionWalker) Walk

func (w *ExpressionWalker) Walk(data interface{}, basePath *field.Path) field.ErrorList

Walk recursively walks through the data structure and validates CEL expressions

type ForEachInfo

type ForEachInfo struct {
	// Type indicates whether forEach iterates over a list or map
	Type ForEachType

	// VarName is the name of the loop variable (default: "item")
	VarName string

	// VarType is the CEL type of the loop variable
	// For maps: ObjectType with "key" and "value" fields
	// For lists: The element type
	VarType *cel.Type

	// KeyType is the type of map keys (only for ForEachMap)
	KeyType *cel.Type

	// ValueType is the type of map values (only for ForEachMap)
	ValueType *cel.Type

	// ElementType is the type of list elements (only for ForEachList)
	ElementType *cel.Type
}

ForEachInfo contains information about a forEach expression and its loop variable

func AnalyzeForEachExpression

func AnalyzeForEachExpression(forEachExpr string, varName string, env *cel.Env) (*ForEachInfo, error)

AnalyzeForEachExpression analyzes a forEach expression to determine iteration type and variable types. This allows proper type checking of the loop variable usage within the forEach body.

For map iteration, the loop variable will have .key and .value fields. For list iteration, the loop variable type matches the list element type.

type ForEachType

type ForEachType int

ForEachType represents the type of iteration in a forEach expression

const (
	// ForEachUnknown indicates the forEach expression type cannot be determined
	ForEachUnknown ForEachType = iota
	// ForEachList indicates forEach iterates over a list
	ForEachList
	// ForEachMap indicates forEach iterates over a map
	ForEachMap
)

func (ForEachType) String

func (t ForEachType) String() string

String returns the string representation of ForEachType

type ResourceType

type ResourceType int

ResourceType indicates which type of resource is being validated

const (
	// ComponentTypeResource indicates validation for ComponentType resources
	ComponentTypeResource ResourceType = iota
	// TraitResource indicates validation for Trait resources
	TraitResource
)

Jump to

Keyboard shortcuts

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