context

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildStructuralSchemas added in v0.7.0

func BuildStructuralSchemas(input *SchemaInput) (*apiextschema.Structural, *apiextschema.Structural, error)

BuildStructuralSchemas builds separate structural schemas for parameters and envOverrides while unmarshaling types only once.

Returns (parametersSchema, envOverridesSchema, error). Either schema can be nil if not provided.

func MergeWorkloadOverrides added in v0.6.0

MergeWorkloadOverrides merges workload overrides into the base workload. Currently, supports merging container env and file configurations.

Types

type ComponentContext added in v0.6.0

type ComponentContext struct {
	// Metadata provides structured naming and labeling information.
	// Accessed via ${metadata.name}, ${metadata.namespace}, ${metadata.componentName}, etc.
	Metadata MetadataContext `json:"metadata"`

	// DataPlane provides data plane configuration.
	// Accessed via ${dataplane.secretStore}, ${dataplane.publicVirtualHost}
	DataPlane DataPlaneData `json:"dataplane"`

	// Parameters are merged component parameters with defaults applied.
	// Dynamic - depends on ComponentType schema.
	Parameters map[string]any `json:"parameters"`

	// Workload contains workload specification (containers, endpoints, connections).
	// Accessed via ${workload.name}, ${workload.containers}, etc.
	Workload WorkloadData `json:"workload"`

	// Configurations are extracted configuration items from workload.
	// Keyed by container name, contains configs and secrets.
	// Accessed via ${configurations["containerName"].configs.envs}, etc.
	Configurations map[string]ContainerConfigurations `json:"configurations"`
}

ComponentContext represents the evaluated context for rendering component resources. This is the output of BuildComponentContext and is used by the template engine.

func BuildComponentContext

func BuildComponentContext(input *ComponentContextInput) (*ComponentContext, error)

BuildComponentContext builds a CEL evaluation context for rendering component resources.

The context includes:

  • parameters: Component parameters with environment overrides and schema defaults applied
  • workload: Workload specification (image, resources, etc.)
  • component: Component metadata (name, etc.)
  • environment: Environment name
  • metadata: Additional metadata

Parameter precedence (highest to lowest):

  • ReleaseBinding.Spec.ComponentTypeEnvOverrides (environment-specific)
  • Component.Spec.Parameters (component defaults)
  • Schema defaults from ComponentType

func (*ComponentContext) ToMap added in v0.6.0

func (c *ComponentContext) ToMap() map[string]any

ToMap converts the ComponentContext to map[string]any for CEL evaluation.

type ComponentContextInput

type ComponentContextInput struct {
	// Component is the component definition.
	Component *v1alpha1.Component `validate:"required"`

	// ComponentType is the type definition for the component.
	ComponentType *v1alpha1.ComponentType `validate:"required"`

	// ReleaseBinding contains release reference and environment-specific overrides.
	ReleaseBinding *v1alpha1.ReleaseBinding

	// Workload contains the workload specification with the built image.
	Workload *v1alpha1.Workload

	// DataPlane contains the data plane configuration.
	// Required - controller must provide this.
	DataPlane *v1alpha1.DataPlane `validate:"required"`

	// SecretReferences is a map of SecretReference objects needed for rendering.
	// Keyed by SecretReference name.
	// Optional - can be nil if no secret references need to be resolved.
	SecretReferences map[string]*v1alpha1.SecretReference

	// Metadata provides structured naming and labeling information.
	// Required - controller must provide this.
	Metadata MetadataContext `validate:"required"`

	// DiscardComponentEnvOverrides when true, discards envOverride values from Component.Spec.Parameters
	// and only uses values from ReleaseBinding.Spec.ComponentTypeEnvOverrides for envOverride fields.
	// Component parameters are still used for fields defined in schema.parameters.
	// Default: false
	DiscardComponentEnvOverrides bool
}

ComponentContextInput contains all inputs needed to build a component rendering context.

type ConfigurationItems added in v0.6.0

type ConfigurationItems struct {
	Envs  []EnvConfiguration  `json:"envs"`
	Files []FileConfiguration `json:"files"`
}

ConfigurationItems contains environment and file configurations.

type ContainerConfigurations added in v0.6.0

type ContainerConfigurations struct {
	Configs ConfigurationItems `json:"configs"`
	Secrets ConfigurationItems `json:"secrets"`
}

ContainerConfigurations contains configs and secrets for a container.

type ContainerData added in v0.6.0

type ContainerData struct {
	Image   string   `json:"image,omitempty"`
	Command []string `json:"command,omitempty"`
	Args    []string `json:"args,omitempty"`
}

ContainerData contains container information.

type DataPlaneData added in v0.6.0

type DataPlaneData struct {
	SecretStore       string `json:"secretStore,omitempty"`
	PublicVirtualHost string `json:"publicVirtualHost,omitempty"`
}

DataPlaneData provides data plane configuration in templates.

type EnvConfiguration added in v0.6.0

type EnvConfiguration struct {
	Name      string         `json:"name"`
	Value     string         `json:"value,omitempty"`
	RemoteRef *RemoteRefData `json:"remoteRef,omitempty"`
}

EnvConfiguration represents an environment variable configuration.

type FileConfiguration added in v0.6.0

type FileConfiguration struct {
	Name      string         `json:"name"`
	MountPath string         `json:"mountPath"`
	Value     string         `json:"value,omitempty"`
	RemoteRef *RemoteRefData `json:"remoteRef,omitempty"`
}

FileConfiguration represents a file configuration.

type MetadataContext

type MetadataContext struct {
	// ComponentName is the name of the component.
	// Example: "my-service"
	ComponentName string `json:"componentName" validate:"required"`

	// ComponentUID is the unique identifier of the component.
	// Example: "a1b2c3d4-5678-90ab-cdef-1234567890ab"
	ComponentUID string `json:"componentUID" validate:"required"`

	// ProjectName is the name of the project.
	// Example: "my-project"
	ProjectName string `json:"projectName" validate:"required"`

	// ProjectUID is the unique identifier of the project.
	// Example: "b2c3d4e5-6789-01bc-def0-234567890abc"
	ProjectUID string `json:"projectUID" validate:"required"`

	// DataPlaneName is the name of the data plane.
	// Example: "my-dataplane"
	DataPlaneName string `json:"dataPlaneName" validate:"required"`

	// DataPlaneUID is the unique identifier of the data plane.
	// Example: "c3d4e5f6-7890-12cd-ef01-34567890abcd"
	DataPlaneUID string `json:"dataPlaneUID" validate:"required"`

	// EnvironmentName is the name of the environment.
	// Example: "production"
	EnvironmentName string `json:"environmentName" validate:"required"`

	// EnvironmentUID is the unique identifier of the environment.
	// Example: "d4e5f6g7-8901-23de-f012-4567890abcde"
	EnvironmentUID string `json:"environmentUID" validate:"required"`

	// Name is the base name to use for generated resources.
	// Example: "my-service-dev-a1b2c3d4"
	Name string `json:"name" validate:"required"`

	// Namespace is the target namespace for the resources.
	// Example: "dp-acme-corp-payment-dev-x1y2z3w4"
	Namespace string `json:"namespace" validate:"required"`

	// Labels are common labels to add to all resources.
	// Example: {"openchoreo.dev/component": "my-service", ...}
	Labels map[string]string `json:"labels" validate:"required"`

	// Annotations are common annotations to add to all resources.
	Annotations map[string]string `json:"annotations" validate:"required"`

	// PodSelectors are platform-injected selectors for pod identity.
	// Used in Deployment selectors, Service selectors, etc.
	// Example: {
	//   "openchoreo.dev/component-uid": "abc123",
	//   "openchoreo.dev/environment-uid": "dev",
	//   "openchoreo.dev/project-uid": "xyz789",
	// }
	PodSelectors map[string]string `json:"podSelectors" validate:"required,min=1"`
}

MetadataContext provides structured metadata for resource generation. This is computed by the controller and passed to the renderer.

type RemoteRefData added in v0.6.0

type RemoteRefData struct {
	Key      string `json:"key"`
	Property string `json:"property,omitempty"`
	Version  string `json:"version,omitempty"`
}

RemoteRefData contains remote reference data for secrets.

type SchemaInput

type SchemaInput struct {
	// Types defines reusable type definitions.
	Types *runtime.RawExtension

	// ParametersSchema is the parameters schema definition.
	ParametersSchema *runtime.RawExtension

	// EnvOverridesSchema is the envOverrides schema definition.
	EnvOverridesSchema *runtime.RawExtension

	// Structural is the compiled structural schema (cached).
	Structural *apiextschema.Structural
}

SchemaInput contains schema information for applying defaults.

type TraitContext added in v0.7.0

type TraitContext struct {
	// Metadata provides structured naming and labeling information.
	// Accessed via ${metadata.name}, ${metadata.namespace}, ${metadata.componentName}, etc.
	Metadata MetadataContext `json:"metadata"`

	// Trait contains trait-specific metadata.
	// Accessed via ${trait.name}, ${trait.instanceName}
	Trait TraitMetadata `json:"trait"`

	// Parameters are merged trait instance parameters with defaults applied.
	// Dynamic - depends on Trait schema.
	Parameters map[string]any `json:"parameters"`
}

TraitContext represents the evaluated context for rendering trait resources. This is the output of BuildTraitContext and is used by the template engine.

func BuildTraitContext

func BuildTraitContext(input *TraitContextInput) (*TraitContext, error)

BuildTraitContext builds a CEL evaluation context for rendering trait resources.

The context includes:

  • parameters: Trait instance parameters with environment overrides and schema defaults applied
  • trait: Trait metadata (name, instanceName)
  • component: Component reference (name, etc.)
  • environment: Environment name
  • metadata: Additional metadata

Parameter precedence (highest to lowest):

  • ReleaseBinding.Spec.TraitOverrides[instanceName] (environment-specific)
  • TraitInstance.Parameters (instance parameters)
  • Schema defaults from Trait

Note: TraitOverrides is keyed by instanceName (not traitName), as instanceNames must be unique across all traits in a component.

func (*TraitContext) ToMap added in v0.7.0

func (t *TraitContext) ToMap() map[string]any

ToMap converts the TraitContext to map[string]any for CEL evaluation.

type TraitContextInput

type TraitContextInput struct {
	// Trait is the trait definition.
	Trait *v1alpha1.Trait `validate:"required"`

	// Instance contains the specific instance configuration.
	Instance v1alpha1.ComponentTrait `validate:"required"`

	// Component is the component this trait is being applied to.
	Component *v1alpha1.Component `validate:"required"`

	// ReleaseBinding contains release reference and environment-specific overrides.
	// Can be nil if no overrides are needed.
	ReleaseBinding *v1alpha1.ReleaseBinding

	// Metadata provides structured naming and labeling information.
	// Required - controller must provide this.
	Metadata MetadataContext `validate:"required"`

	// SchemaCache is an optional cache for structural schemas, keyed by trait name.
	// Used to avoid rebuilding schemas for the same trait used multiple times.
	// BuildTraitContext will check this cache before building and populate it after.
	SchemaCache map[string]*apiextschema.Structural

	// DiscardComponentEnvOverrides when true, discards envOverride values from trait instance parameters
	// and only uses values from ReleaseBinding.Spec.TraitOverrides for envOverride fields.
	// Trait instance parameters are still used for fields defined in trait's schema.parameters.
	// Default: false
	DiscardComponentEnvOverrides bool
}

TraitContextInput contains all inputs needed to build a trait rendering context.

type TraitMetadata added in v0.7.0

type TraitMetadata struct {
	// Name is the name of the trait.
	// Example: "storage"
	Name string `json:"name"`

	// InstanceName is the unique instance name within the component.
	// Example: "my-storage"
	InstanceName string `json:"instanceName"`
}

TraitMetadata contains trait-specific metadata.

type WorkloadData added in v0.6.0

type WorkloadData struct {
	Containers map[string]ContainerData `json:"containers"`
}

WorkloadData contains workload information for templates.

Jump to

Keyboard shortcuts

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