context

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOutputNotResolved indicates a binding references an output that is not present in
	// the provider ResourceReleaseBinding's status.outputs[]. Transient: may resolve once
	// the provider catches up.
	ErrOutputNotResolved = errors.New("output not resolved on resource release binding")

	// ErrInvalidFileBinding indicates a fileBindings entry targets a value-kind output, which
	// has no underlying DP-side object to mount. Permanent misconfiguration in the workload
	// spec; will not resolve by waiting.
	ErrInvalidFileBinding = errors.New("output kind cannot be mounted as file")
)

Sentinel errors returned by BuildResourceDependencyItem. Callers can use errors.Is to distinguish wait-for-resolve failures from permanent misconfigurations.

Functions

func BuildStructuralSchemas added in v0.7.0

func BuildStructuralSchemas(input *SchemaInput) (*SchemaBundle, *SchemaBundle, error)

BuildStructuralSchemas builds separate structural schemas for parameters and environmentConfigs.

Returns (parametersBundle, envConfigsBundle, error). Either bundle's schemas can be nil if not provided.

func CELExtensions added in v0.9.0

func CELExtensions() []cel.EnvOption

CELExtensions returns CEL environment options for configuration helpers used by the runtime template engine. Function overloads return list(dyn) and include runtime bindings.

func CELValidationExtensions added in v1.0.0

func CELValidationExtensions() []cel.EnvOption

CELValidationExtensions returns CEL environment options for the validation environment. Unlike CELExtensions(), function overloads declare typed return types instead of dyn, enabling the type checker to validate field access on forEach loop variables. No binding functions are registered since validation never evaluates expressions.

func ExtractTraitInstanceBindings added in v1.1.0

func ExtractTraitInstanceBindings(
	instance v1alpha1.ComponentTrait,
	rb *v1alpha1.ReleaseBinding,
) (parameters map[string]any, envConfigs map[string]any, err error)

ExtractTraitInstanceBindings produces concrete parameter and environmentConfigs maps for a component-level trait instance. Unlike ResolveEmbeddedTraitBindings, no CEL evaluation happens here — values are already concrete and we just JSON-deserialize them.

The instance parameters come from instance.Parameters (a runtime.RawExtension); the environmentConfigs come from rb.Spec.TraitEnvironmentConfigs[instance.InstanceName], if present. A nil ReleaseBinding or a missing instance entry produces an empty envConfigs map.

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

func FunctionReturnTypes added in v1.0.0

func FunctionReturnTypes() []reflect.Type

FunctionReturnTypes returns the unique Go types used as return types by CEL helper functions. Used by the validation environment to register DeclTypes for field-access validation.

func MergeWorkloadOverrides added in v0.6.0

MergeWorkloadOverrides merges workload overrides into the base workload. Supports merging container env and file configurations.

func ResolveEmbeddedTraitBindings added in v0.14.0

func ResolveEmbeddedTraitBindings(
	engine *template.Engine,
	embeddedTrait v1alpha1.ComponentTypeTrait,
	componentContextMap map[string]any,
) (resolvedParams map[string]any, resolvedEnvConfigs map[string]any, err error)

ResolveEmbeddedTraitBindings resolves CEL expressions in an embedded trait's parameter and environmentConfigs bindings against the component context, producing concrete maps suitable for passing into BuildTraitContext as ResolvedParameters / ResolvedEnvironmentConfigs.

Values in the embedded trait bindings can be:

  • Concrete values (locked by PE): passed through as-is
  • CEL expressions like "${parameters.storage.mountPath}": evaluated against the component context

Counterpart to ExtractTraitInstanceBindings, which performs the equivalent step for component-level traits (where no CEL evaluation is needed).

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.gateway.ingress.external.https.host}, etc.
	DataPlane DataPlaneData `json:"dataplane"`

	// Environment provides environment-specific gateway configuration.
	// Accessed via ${environment.gateway.ingress.external.https.host}, etc.
	// Falls back to DataPlane gateway values if Environment.Gateway is not configured.
	Environment EnvironmentData `json:"environment"`

	// Gateway provides the effective gateway configuration for this deployment.
	// Uses environment gateway if configured, falls back to DataPlane gateway.
	// Accessed via ${gateway.ingress.external.https.host}, etc.
	Gateway *GatewayData `json:"gateway,omitempty"`

	// Parameters from Component.Spec.Parameters, pruned to ComponentType.Spec.Parameters schema.
	// Accessed via ${parameters.*}
	Parameters map[string]any `json:"parameters"`

	// EnvironmentConfigs from ReleaseBinding.Spec.ComponentTypeEnvironmentConfigs, pruned to ComponentType.Spec.EnvironmentConfigs schema.
	// Accessed via ${environmentConfigs.*}
	EnvironmentConfigs map[string]any `json:"environmentConfigs"`

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

	// Configurations are extracted configuration items from workload.
	// Contains configs and secrets for the single container.
	// Accessed via ${configurations.configs.envs}, ${configurations.secrets.files}, etc.
	Configurations ContainerConfigurations `json:"configurations"`

	// Dependencies contains dependency metadata and merged env vars for templates.
	// Accessed via ${dependencies.items} and ${dependencies.envVars}.
	Dependencies ConnectionsContextData `json:"dependencies"`
}

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: From Component.Spec.Parameters (pruned to schema.parameters) - access via ${parameters.*}
  • environmentConfigs: From ReleaseBinding.Spec.ComponentTypeEnvironmentConfigs (pruned to schema.environmentConfigs) - access via ${environmentConfigs.*}
  • workload: Workload specification (image, resources, etc.) - access via ${workload.*}
  • metadata: Structured naming and labeling information - access via ${metadata.*}
  • dataplane: Data plane configuration - access via ${dataplane.*}
  • configurations: Extracted configuration items from workload - access via ${configurations.*}

Schema defaults are applied to both parameters and environmentConfigs sections.

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. All fields including configurations are converted to nested maps via JSON marshaling. This allows consistent CEL access without requiring ext.NativeTypes() registration.

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

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

	// Environment contains the environment configuration.
	// Required - controller must provide this.
	Environment *v1alpha1.Environment `validate:"required"`

	// WorkloadData is the pre-computed workload data (containers, endpoints).
	// Should be computed once by the caller using ExtractWorkloadData and shared.
	WorkloadData WorkloadData

	// Configurations is the pre-computed configurations from workload.
	// Should be computed once by the caller using ExtractConfigurationsFromWorkload
	// and shared across ComponentContext and all TraitContexts.
	Configurations ContainerConfigurations

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

	// Dependencies contains pre-computed dependency environment variables.
	// Optional - if not provided, dependencies context will be empty.
	Dependencies ConnectionsData

	// DefaultNotificationChannel is the default notification channel name for the environment.
	// Optional - if not provided, the defaultNotificationChannel field in EnvironmentData will be empty.
	DefaultNotificationChannel string
}

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

type ConfigFileListEntry added in v1.0.0

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

ConfigFileListEntry represents an element returned by configurations.toConfigFileList().

type ConfigMapVolume added in v1.0.0

type ConfigMapVolume struct {
	Name string `json:"name"`
}

ConfigMapVolume represents a configMap volume source.

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 ConnectionItem added in v0.17.0

type ConnectionItem struct {
	Namespace  string        `json:"namespace"`
	Project    string        `json:"project"`
	Component  string        `json:"component"`
	Endpoint   string        `json:"endpoint"`
	Visibility string        `json:"visibility"`
	EnvVars    []EnvVarEntry `json:"envVars"`
}

ConnectionItem represents a single connection with its target metadata and resolved env vars.

type ConnectionsContextData added in v0.17.0

type ConnectionsContextData struct {
	Items        []ConnectionItem         `json:"items"`
	Resources    []ResourceDependencyItem `json:"resources"`
	EnvVars      []EnvVarEntry            `json:"envVars"`
	VolumeMounts []VolumeMountEntry       `json:"volumeMounts"`
	Volumes      []VolumeEntry            `json:"volumes"`
}

ConnectionsContextData is the template context representation of dependencies. It exposes per-item views (Items, Resources) plus merged flat lists (EnvVars, VolumeMounts, Volumes) for templates that want a single combined surface.

${dependencies.items}        — endpoint per-item view
${dependencies.resources}    — resource per-item view
${dependencies.envVars}      — merged across endpoints + resources
${dependencies.volumeMounts} — merged across resources
${dependencies.volumes}      — merged across resources

type ConnectionsData added in v0.17.0

type ConnectionsData struct {
	Items     []ConnectionItem         `json:"items"`
	Resources []ResourceDependencyItem `json:"resources"`
}

ConnectionsData contains the per-item dependency views (endpoint connections and resource dependencies) that the controller resolves before invoking the pipeline. This is the input type used in RenderInput and context inputs.

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.

func ExtractConfigurationsFromWorkload added in v0.11.0

func ExtractConfigurationsFromWorkload(secretReferences map[string]*v1alpha1.SecretReference, workload *v1alpha1.Workload) ContainerConfigurations

ExtractConfigurationsFromWorkload extracts env and file configurations from the workload container and organizes them with configs vs secrets separation. Returns the container's configs and secrets. Always initializes empty slices for envs and files to ensure they're never nil. Example structure: {"configs": {"envs": [...], "files": [...]}, "secrets": {"envs": [...], "files": [...]}}

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"`
	Gateway               *GatewayData               `json:"gateway,omitempty"`
	ObservabilityPlaneRef *ObservabilityPlaneRefData `json:"observabilityPlaneRef,omitempty"`
}

DataPlaneData provides data plane configuration in templates.

type EndpointData added in v0.11.0

type EndpointData struct {
	DisplayName string   `json:"displayName,omitempty"`
	Port        int32    `json:"port"`
	TargetPort  int32    `json:"targetPort"`
	Type        string   `json:"type"`
	BasePath    string   `json:"basePath,omitempty"`
	Visibility  []string `json:"visibility"`
}

EndpointData contains endpoint information.

type EnvConfiguration added in v0.6.0

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

EnvConfiguration represents an environment variable configuration. Value is always emitted (no omitempty) so that empty-string literals survive the JSON round-trip into the CEL evaluation context.

type EnvFromEntry added in v1.0.0

type EnvFromEntry struct {
	ConfigMapRef *NameRef `json:"configMapRef,omitempty"`
	SecretRef    *NameRef `json:"secretRef,omitempty"`
}

EnvFromEntry represents an element returned by configurations.toContainerEnvFrom().

type EnvVarEntry added in v1.1.0

type EnvVarEntry struct {
	Name      string             `json:"name"`
	Value     string             `json:"value,omitempty"`
	ValueFrom *EnvVarSourceEntry `json:"valueFrom,omitempty"`
}

EnvVarEntry mirrors corev1.EnvVar for the subset of shapes the platform emits when merging endpoint connection env vars and resource dependency env vars into ${dependencies.envVars}. JSON-compatible with corev1.EnvVar so the rendered Pod spec is unchanged. Kept local (instead of importing corev1) so the validation env's CEL element type matches across configurations.* and dependencies.* helpers, enabling concat with the `+` operator without a type-check error.

type EnvVarSourceEntry added in v1.1.0

type EnvVarSourceEntry struct {
	SecretKeyRef    *KeyRef `json:"secretKeyRef,omitempty"`
	ConfigMapKeyRef *KeyRef `json:"configMapKeyRef,omitempty"`
}

EnvVarSourceEntry mirrors corev1.EnvVarSource for the two ref kinds the platform emits. FieldRef / ResourceFieldRef / FileKeyRef are deliberately not modeled — resource outputs produce literal value, secretKeyRef, or configMapKeyRef only.

type EnvironmentData added in v0.15.0

type EnvironmentData struct {
	Gateway                    *GatewayData `json:"gateway,omitempty"`
	DefaultNotificationChannel string       `json:"defaultNotificationChannel,omitempty"`
}

EnvironmentData provides environment-specific gateway configuration in templates. If the environment does not have gateway configuration, values fallback to DataPlane gateway.

type EnvsByContainerEntry added in v1.0.0

type EnvsByContainerEntry struct {
	ResourceName string             `json:"resourceName"`
	Envs         []EnvConfiguration `json:"envs"`
}

EnvsByContainerEntry represents an element returned by configurations.toConfigEnvsByContainer() or configurations.toSecretEnvsByContainer().

type FileConfiguration added in v0.6.0

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

FileConfiguration represents a file configuration.

type GatewayData added in v0.17.0

type GatewayData struct {
	Ingress *GatewayNetworkData `json:"ingress,omitempty"`
	Egress  *GatewayNetworkData `json:"egress,omitempty"`
}

GatewayData provides gateway configuration in templates.

type GatewayEndpointData added in v0.17.0

type GatewayEndpointData struct {
	Name      string               `json:"name,omitempty"`
	Namespace string               `json:"namespace,omitempty"`
	HTTP      *GatewayListenerData `json:"http,omitempty"`
	HTTPS     *GatewayListenerData `json:"https,omitempty"`
	TLS       *GatewayListenerData `json:"tls,omitempty"`
}

GatewayEndpointData provides endpoint data for a gateway in templates.

type GatewayListenerData added in v0.17.0

type GatewayListenerData struct {
	ListenerName string `json:"listenerName,omitempty"`
	Port         int32  `json:"port,omitempty"`
	Host         string `json:"host,omitempty"`
}

GatewayListenerData provides listener data for a gateway in templates.

type GatewayNetworkData added in v0.17.0

type GatewayNetworkData struct {
	External *GatewayEndpointData `json:"external,omitempty"`
	Internal *GatewayEndpointData `json:"internal,omitempty"`
}

GatewayNetworkData provides traffic gateway data for ingress/egress in templates.

type KeyRef added in v1.1.0

type KeyRef struct {
	Name string `json:"name"`
	Key  string `json:"key"`
}

KeyRef references a single key within a Secret or ConfigMap. JSON-compatible with the {name, key} projection of corev1.SecretKeySelector / corev1.ConfigMapKeySelector that the platform emits.

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"`

	// ComponentNamespace is the namespace on which the component is created.
	// Example: "cp-acme-corp"
	ComponentNamespace string `json:"componentNamespace" 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/namespace": "dp-acme-corp-payment-dev-x1y2z3w4",
	//   "openchoreo.dev/project": "acme-corp",
	//   "openchoreo.dev/component": "payment",
	//   "openchoreo.dev/environment": "dev",
	//   "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 NameRef added in v1.0.0

type NameRef struct {
	Name string `json:"name"`
}

NameRef is a reference containing a name field.

type ObservabilityPlaneRefData added in v0.15.0

type ObservabilityPlaneRefData struct {
	Kind string `json:"kind,omitempty"`
	Name string `json:"name,omitempty"`
}

ObservabilityPlaneRefData provides observability plane reference in templates.

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 ResourceDependencyItem added in v1.1.0

type ResourceDependencyItem struct {
	Ref          string             `json:"ref"`
	EnvVars      []EnvVarEntry      `json:"envVars"`
	VolumeMounts []VolumeMountEntry `json:"volumeMounts"`
	Volumes      []VolumeEntry      `json:"volumes"`
}

ResourceDependencyItem represents a single resource dependency with its target metadata and pre-computed env vars, volume mounts, and volumes for the consuming container. Mirrors ConnectionItem's role on the endpoint side.

func BuildResourceDependencyItem added in v1.1.0

func BuildResourceDependencyItem(
	dep v1alpha1.WorkloadResourceDependency,
	outputs []v1alpha1.ResolvedResourceOutput,
) (ResourceDependencyItem, error)

BuildResourceDependencyItem produces the env vars, volume mounts, and volumes that wire the outputs of a resolved ResourceReleaseBinding into a consuming container per the workload's dependency declaration. Pure function — no client, no logger, no controller-runtime imports.

Dispatch per-binding:

  • envBindings[outputName] → EnvVarEntry with {Value} (value-kind output) or {ValueFrom.SecretKeyRef} / {ValueFrom.ConfigMapKeyRef} (ref-kind outputs)
  • fileBindings[outputName] → VolumeMountEntry + VolumeEntry; output's source kind must be SecretKeyRef or ConfigMapKeyRef (value-kind is rejected with ErrInvalidFileBinding)

Volumes are deduped per (dep.Ref, secretName) and (dep.Ref, configMapName), so multiple file bindings that resolve to keys in the same Secret/ConfigMap share one volume with multiple mounts. Volume names are deterministic (FNV-1a 32-bit hash).

Returns an error wrapping a sentinel (ErrOutputNotResolved / ErrInvalidFileBinding) on the first binding failure; the partial item is discarded. All-or-nothing per-dep semantics: callers should surface the error as a single PendingResourceDependency entry.

type SchemaBundle added in v0.9.0

type SchemaBundle struct {
	Structural *apiextschema.Structural
	JSONSchema *extv1.JSONSchemaProps
}

SchemaBundle holds both structural and JSON schemas for validation workflows. The structural schema is used for pruning and defaulting, while the JSON schema is used for validation.

type SchemaInput

type SchemaInput struct {
	// ParametersSchema is the parameters schema section.
	ParametersSchema *v1alpha1.SchemaSection

	// EnvironmentConfigsSchema is the environmentConfigs schema section.
	EnvironmentConfigsSchema *v1alpha1.SchemaSection
}

SchemaInput contains schema information for building structural and JSON schemas.

type SecretFileListEntry added in v1.0.0

type SecretFileListEntry struct {
	Name         string         `json:"name"`
	MountPath    string         `json:"mountPath"`
	ResourceName string         `json:"resourceName"`
	RemoteRef    *RemoteRefData `json:"remoteRef,omitempty"`
}

SecretFileListEntry represents an element returned by configurations.toSecretFileList().

type SecretVolume added in v1.0.0

type SecretVolume struct {
	SecretName string `json:"secretName"`
}

SecretVolume represents a secret volume source.

type ServicePortEntry added in v1.0.0

type ServicePortEntry struct {
	Name       string `json:"name"`
	Port       int64  `json:"port"`
	TargetPort int64  `json:"targetPort"`
	Protocol   string `json:"protocol"`
}

ServicePortEntry represents an element returned by workload.toServicePorts().

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 from TraitInstance.Parameters, pruned to Trait.Spec.Parameters schema.
	// Accessed via ${parameters.*}
	Parameters map[string]any `json:"parameters"`

	// EnvironmentConfigs from ReleaseBinding.Spec.TraitEnvironmentConfigs[instanceName], pruned to Trait.Spec.EnvironmentConfigs schema.
	// Accessed via ${environmentConfigs.*}
	EnvironmentConfigs map[string]any `json:"environmentConfigs"`

	// DataPlane provides data plane configuration.
	// Accessed via ${dataplane.secretStore}, ${dataplane.gateway.ingress.external.https.host}, etc.
	DataPlane DataPlaneData `json:"dataplane"`

	// Environment provides environment-specific gateway configuration.
	// Accessed via ${environment.gateway.ingress.external.https.host}, etc.
	// Falls back to DataPlane gateway values if Environment.Gateway is not configured.
	Environment EnvironmentData `json:"environment"`

	// Gateway provides the effective gateway configuration for this deployment.
	// Uses environment gateway if configured, falls back to DataPlane gateway.
	// Accessed via ${gateway.ingress.external.https.host}, etc.
	Gateway *GatewayData `json:"gateway,omitempty"`

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

	// Configurations are extracted configuration items from workload.
	// Contains configs and secrets for the single container.
	// Accessed via ${configurations.configs.envs}, ${configurations.secrets.files}, etc.
	Configurations ContainerConfigurations `json:"configurations"`

	// Dependencies contains dependency metadata and merged env vars for templates.
	// Accessed via ${dependencies.items} and ${dependencies.envVars}.
	Dependencies ConnectionsContextData `json:"dependencies"`
}

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: ResolvedParameters pruned to Trait.Spec.Parameters schema — access via ${parameters.*}
  • environmentConfigs: ResolvedEnvironmentConfigs pruned to Trait.Spec.EnvironmentConfigs schema — access via ${environmentConfigs.*}
  • trait: Trait metadata (name, instanceName) — access via ${trait.*}
  • metadata: Structured naming and labeling information — access via ${metadata.*}

Schema defaults are applied to both parameters and environmentConfigs sections.

Both component-level and embedded traits use this builder. Callers obtain the resolved parameter/environmentConfigs maps separately:

  • Component-level traits call ExtractTraitInstanceBindings.
  • Embedded traits call ResolveEmbeddedTraitBindings.

By the time the input reaches BuildTraitContext both flows look identical.

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 TraitContextBase added in v1.1.0

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

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

	// Environment contains the environment configuration.
	// Required - controller must provide this.
	Environment *v1alpha1.Environment `validate:"required"`

	// WorkloadData is the pre-computed workload data (containers, endpoints).
	// Should be computed once by the caller using ExtractWorkloadData and shared.
	WorkloadData WorkloadData

	// Configurations is the pre-computed configurations from workload.
	// Should be computed once by the caller using ExtractConfigurationsFromWorkload
	// and shared across ComponentContext and all TraitContexts.
	Configurations ContainerConfigurations

	// Dependencies contains pre-computed dependency environment variables.
	// Optional - if not provided, dependencies context will be empty.
	Dependencies ConnectionsData

	// DefaultNotificationChannel is the default notification channel name for the environment.
	// Optional - if not provided, the defaultNotificationChannel field in EnvironmentData will be empty.
	DefaultNotificationChannel string
}

TraitContextBase contains the inputs common to building both regular and embedded trait contexts (metadata, dataplane, environment, workload data, configurations, dependencies, notification channel). Pipeline callers typically build this once at the start of a render and embed it in each TraitContextInput / EmbeddedTraitContextInput inside the trait loops.

type TraitContextInput

type TraitContextInput struct {
	// TraitContextBase contains the fields shared across every trait built in a render
	// (metadata, dataplane, environment, workload data, configurations, dependencies,
	// notification channel). Pipeline callers typically build it once and embed it here.
	TraitContextBase

	// Trait is the trait definition.
	Trait *v1alpha1.Trait `validate:"required"`

	// InstanceName is the unique instance name for this trait within the component.
	InstanceName string `validate:"required"`

	// ResolvedParameters contains the parameter map after resolution. For component-level
	// traits this is JSON-deserialized from the ComponentTrait instance. For embedded
	// traits this is the result of CEL evaluation against the component context.
	ResolvedParameters map[string]any

	// ResolvedEnvironmentConfigs contains the environmentConfigs map after resolution.
	// For component-level traits it comes from ReleaseBinding.Spec.TraitEnvironmentConfigs;
	// for embedded traits it comes from CEL-evaluated bindings.
	ResolvedEnvironmentConfigs map[string]any

	// SchemaCache is an optional cache for schema bundles, keyed by trait kind+name with suffix.
	// Used to avoid rebuilding schemas for the same trait used multiple times.
	// BuildTraitContext will check this cache before building and populate it after.
	// Cache keys use format "{kind}:{traitName}:parameters" and "{kind}:{traitName}:environmentConfigs".
	SchemaCache map[string]*SchemaBundle
}

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

Both component-level and embedded traits use this input. The only difference is how callers obtain the resolved parameter and environmentConfigs maps:

  • Component-level traits: use ExtractTraitInstanceBindings to deserialize the ComponentTrait instance and ReleaseBinding override.
  • Embedded traits: use ResolveEmbeddedTraitBindings to evaluate CEL expressions against the component context.

By the time the input reaches BuildTraitContext both flows look identical.

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 VolumeEntry added in v1.0.0

type VolumeEntry struct {
	Name      string           `json:"name"`
	ConfigMap *ConfigMapVolume `json:"configMap,omitempty"`
	Secret    *SecretVolume    `json:"secret,omitempty"`
}

VolumeEntry represents an element returned by configurations.toVolumes().

type VolumeMountEntry added in v1.0.0

type VolumeMountEntry struct {
	Name      string `json:"name"`
	MountPath string `json:"mountPath"`
	SubPath   string `json:"subPath,omitempty"`
}

VolumeMountEntry represents an element returned by configurations.toContainerVolumeMounts().

type WorkloadData added in v0.6.0

type WorkloadData struct {
	Container ContainerData           `json:"container"`
	Endpoints map[string]EndpointData `json:"endpoints"`
}

WorkloadData contains workload information for templates.

func ExtractWorkloadData added in v0.11.0

func ExtractWorkloadData(workload *v1alpha1.Workload) WorkloadData

ExtractWorkloadData extracts relevant workload information for the rendering context. This function is exported so callers can pre-compute workload data once and share it across multiple context builds (ComponentContext and TraitContexts).

Jump to

Keyboard shortcuts

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