Documentation
¶
Index ¶
- func BuildComponentCELEnv(opts SchemaOptions) (*cel.Env, error)
- func BuildTraitCELEnv(opts SchemaOptions) (*cel.Env, error)
- func ExtendEnvWithForEach(env *cel.Env, info *ForEachInfo) (*cel.Env, error)
- func ValidateAllowedTraits(compTraits []v1alpha1.ComponentTrait, allowedTraits []v1alpha1.TraitRef) error
- func ValidateClusterComponentTypeResourcesWithSchema(cct *v1alpha1.ClusterComponentType, parametersSchema *apiextschema.Structural, ...) field.ErrorList
- func ValidateClusterTraitCreatesAndPatchesWithSchema(ct *v1alpha1.ClusterTrait, parametersSchema *apiextschema.Structural, ...) field.ErrorList
- func ValidateComponentTypeResourcesWithSchema(ct *v1alpha1.ComponentType, parametersSchema *apiextschema.Structural, ...) field.ErrorList
- func ValidatePatchOperation(op v1alpha1.JSONPatchOperation, validator *CELValidator, env *cel.Env, ...) field.ErrorList
- func ValidatePatchTarget(target v1alpha1.PatchTarget, validator *CELValidator, env *cel.Env, ...) field.ErrorList
- func ValidateResourceTemplate(tmpl v1alpha1.ResourceTemplate, validator *CELValidator, basePath *field.Path) field.ErrorList
- func ValidateResourceTemplateStructure(template runtime.RawExtension, fieldPath *field.Path) (*metav1.PartialObjectMetadata, field.ErrorList)
- func ValidateTemplateBody(body runtime.RawExtension, validator *CELValidator, env *cel.Env, ...) field.ErrorList
- func ValidateTraitCreate(create v1alpha1.TraitCreate, validator *CELValidator, basePath *field.Path) field.ErrorList
- func ValidateTraitCreatesAndPatchesWithSchema(trait *v1alpha1.Trait, parametersSchema *apiextschema.Structural, ...) field.ErrorList
- func ValidateTraitInstanceNameUniqueness(compTraits []v1alpha1.ComponentTrait, ...) error
- func ValidateTraitPatch(patch v1alpha1.TraitPatch, validator *CELValidator, basePath *field.Path) field.ErrorList
- func ValidateValidationRule(rule v1alpha1.ValidationRule, validator *CELValidator, basePath *field.Path) field.ErrorList
- func ValidateWorkloadResources(workloadType string, resources []v1alpha1.ResourceTemplate, ...) field.ErrorList
- type CELValidator
- func (v *CELValidator) GetBaseEnv() *cel.Env
- func (v *CELValidator) ValidateBooleanExpression(expr string, env *cel.Env) error
- func (v *CELValidator) ValidateExpression(expr string) error
- func (v *CELValidator) ValidateIterableExpression(expr string, env *cel.Env) error
- func (v *CELValidator) ValidateWithEnv(expr string, env *cel.Env) error
- type ExpressionWalker
- type ForEachInfo
- type ForEachType
- type ResourceType
- type SchemaOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildComponentCELEnv ¶
func BuildComponentCELEnv(opts SchemaOptions) (*cel.Env, error)
BuildComponentCELEnv creates a schema-aware CEL environment for component validation. Variables are derived from ComponentContext struct fields:
- parameters, environmentConfigs: Schema-aware types (or empty object if not provided)
- metadata, dataplane, workload, configurations: Types derived via reflection
func BuildTraitCELEnv ¶
func BuildTraitCELEnv(opts SchemaOptions) (*cel.Env, error)
BuildTraitCELEnv creates a schema-aware CEL environment for trait validation. Variables are derived from TraitContext struct fields:
- parameters, environmentConfigs: Schema-aware types (or empty object if not provided)
- trait, metadata, dataplane, workload, configurations: Types derived via reflection
func ExtendEnvWithForEach ¶
ExtendEnvWithForEach extends a CEL environment with the forEach loop variable. The variable is typed appropriately based on the forEach analysis.
func ValidateAllowedTraits ¶ added in v1.0.0
func ValidateAllowedTraits(compTraits []v1alpha1.ComponentTrait, allowedTraits []v1alpha1.TraitRef) error
ValidateAllowedTraits checks that all component-level traits are permitted by the ComponentType's allowedTraits list. If allowedTraits is empty, no component-level traits are allowed.
func ValidateClusterComponentTypeResourcesWithSchema ¶ added in v0.16.0
func ValidateClusterComponentTypeResourcesWithSchema( cct *v1alpha1.ClusterComponentType, parametersSchema *apiextschema.Structural, environmentConfigsSchema *apiextschema.Structural, ) field.ErrorList
ValidateClusterComponentTypeResourcesWithSchema validates all resources in a ClusterComponentType with schema-aware type checking.
func ValidateClusterTraitCreatesAndPatchesWithSchema ¶ added in v0.16.0
func ValidateClusterTraitCreatesAndPatchesWithSchema( ct *v1alpha1.ClusterTrait, parametersSchema *apiextschema.Structural, environmentConfigsSchema *apiextschema.Structural, ) field.ErrorList
ValidateClusterTraitCreatesAndPatchesWithSchema validates all creates, patches, and validations in a ClusterTrait with schema-aware type checking.
func ValidateComponentTypeResourcesWithSchema ¶ added in v0.9.0
func ValidateComponentTypeResourcesWithSchema( ct *v1alpha1.ComponentType, parametersSchema *apiextschema.Structural, environmentConfigsSchema *apiextschema.Structural, ) field.ErrorList
ValidateComponentTypeResourcesWithSchema validates all resources in a ComponentType with schema-aware type checking.
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. It validates includeWhen (must return boolean), forEach (must return iterable), and the template body with schema-aware type checking.
func ValidateTraitCreatesAndPatchesWithSchema ¶ added in v0.9.0
func ValidateTraitCreatesAndPatchesWithSchema( trait *v1alpha1.Trait, parametersSchema *apiextschema.Structural, environmentConfigsSchema *apiextschema.Structural, ) field.ErrorList
ValidateTraitCreatesAndPatchesWithSchema validates all creates and patches in a Trait with schema-aware type checking. It checks CEL expressions, forEach loops, and ensures proper variable usage.
Parameters:
- trait: The Trait to validate
- parametersSchema: Structural schema for parameters (from Trait.Spec.Parameters schema)
- environmentConfigsSchema: Structural schema for environmentConfigs (from Trait.Spec.EnvironmentConfigs schema)
If schemas are nil, DynType will be used for those variables (no static type checking). This provides better error messages by catching type errors at validation time.
func ValidateTraitInstanceNameUniqueness ¶ added in v1.0.0
func ValidateTraitInstanceNameUniqueness(compTraits []v1alpha1.ComponentTrait, embeddedTraits []v1alpha1.ComponentTypeTrait) error
ValidateTraitInstanceNameUniqueness checks that: - embedded trait instance names are unique among themselves - component-level trait instance names are unique among themselves - component-level trait instance names do not collide with embedded trait instance names
func ValidateTraitPatch ¶
func ValidateTraitPatch( patch v1alpha1.TraitPatch, validator *CELValidator, basePath *field.Path, ) field.ErrorList
ValidateTraitPatch validates a single trait patch operation
func ValidateValidationRule ¶ added in v0.15.0
func ValidateValidationRule( rule v1alpha1.ValidationRule, validator *CELValidator, basePath *field.Path, ) field.ErrorList
ValidateValidationRule validates a single validation rule's CEL expression. The rule must be wrapped in ${...} and must compile to a boolean expression.
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, opts SchemaOptions) (*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). Provides schema-aware type checking when schemas are provided in opts.
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
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 )
type SchemaOptions ¶ added in v0.9.0
type SchemaOptions struct {
// ParametersSchema is the structural schema for parameters.
// If nil, an empty object type will be used.
ParametersSchema *apiextschema.Structural
// EnvironmentConfigsSchema is the structural schema for environmentConfigs.
// If nil, an empty object type will be used.
EnvironmentConfigsSchema *apiextschema.Structural
}
SchemaOptions provides schema configuration for CEL environment and validation. Used by both component and trait CEL environments.