Skip to main content
Version: v1.0.0-rc.1 (pre-release)

ComponentType

A ComponentType is a platform-defined template that determines how components are deployed and what resources are generated for them. ComponentTypes enable platform engineers to create reusable deployment patterns with configurable parameters, replacing the fixed component classes from previous versions.

API Version​

openchoreo.dev/v1alpha1

Resource Definition​

Metadata​

ComponentTypes are namespace-scoped resources typically created in a namespace to be available for components in that namespace.

apiVersion: openchoreo.dev/v1alpha1
kind: ComponentType
metadata:
name: <componenttype-name>
namespace: <namespace> # Namespace for grouping component types

Short names: ct, cts

Spec Fields​

FieldTypeRequiredDefaultDescription
workloadTypestringYes-Primary workload type: deployment, statefulset, cronjob, job, proxy
allowedWorkflows[WorkflowRef]No[]Workflow references developers can use for building this component type; if empty, no workflows are allowed
parametersSchemaSectionNo-Developer-facing parameter schema for components of this type
environmentConfigsSchemaSectionNo-Per-environment configuration overrides schema
traits[ComponentTypeTrait]No[]Pre-configured trait instances automatically applied to all Components of this type
allowedTraits[TraitRef]No[]Traits that developers can attach to components of this type beyond those embedded in traits
validations[ValidationRule]No[]CEL-based rules evaluated during rendering; all must pass for rendering to proceed
resources[ResourceTemplate]Yes-Templates for generating Kubernetes resources
note

The workloadType field is immutable after creation and determines the primary resource type for components of this type. For non-proxy workload types, one resource template must have an id matching the workloadType.

WorkflowRef​

Specifies a Workflow that developers can use with components of this type. allowedWorkflows is an explicit allow list, so only referenced Workflows are permitted.

FieldTypeRequiredDefaultDescription
kindstringNoWorkflowKind of the referenced resource: Workflow (namespace-scoped) or ClusterWorkflow (cluster-scoped)
namestringYes-Name of the Workflow or ClusterWorkflow resource

Example:

allowedWorkflows:
- kind: Workflow
name: nodejs-build
- kind: ClusterWorkflow
name: dockerfile-builder
- name: container-image-scan

ComponentTypeTrait​

Represents a pre-configured trait instance embedded in a ComponentType. These traits are automatically applied to all Components of this type.

FieldTypeRequiredDefaultDescription
kindstringNoTraitKind of the referenced resource: Trait (namespace-scoped) or ClusterTrait (cluster-scoped)
namestringYes-Name of the Trait or ClusterTrait
instanceNamestringYes-Unique instance name within the component type
parametersobjectNo-Trait parameter values (can use CEL expressions referencing the ComponentType schema, e.g., ${parameters.storage.mountPath})
environmentConfigsobjectNo-Environment-specific override values for the trait

TraitRef​

Specifies a Trait or ClusterTrait that developers can attach to components of this type. Traits listed here must not overlap with traits already embedded in spec.traits.

FieldTypeRequiredDefaultDescription
kindstringNoTraitKind of the referenced resource: Trait (namespace-scoped) or ClusterTrait (cluster-scoped)
namestringYes-Name of the Trait or ClusterTrait

ValidationRule​

Defines a CEL-based validation rule evaluated during rendering. All rules must evaluate to true for rendering to proceed.

FieldTypeRequiredDescription
rulestringYesCEL expression wrapped in ${...} that must evaluate to true
messagestringYesError message shown when the rule evaluates to false

Example:

validations:
- rule: ${parameters.replicas >= 1}
message: "replicas must be at least 1"
- rule: ${parameters.port > 0 && parameters.port <= 65535}
message: "port must be between 1 and 65535"

SchemaSection​

Both parameters and environmentConfigs use the SchemaSection type, which holds a schema in openAPIV3Schema format:

FieldTypeRequiredDefaultDescription
openAPIV3SchemaobjectNo-Standard OpenAPI v3 JSON Schema format

openAPIV3Schema Format​

Uses standard OpenAPI v3 JSON Schema:

parameters:
openAPIV3Schema:
type: object
properties:
replicas:
type: integer
default: 1
port:
type: integer
default: 80

ResourceTemplate​

Defines a template for generating Kubernetes resources with CEL expressions for dynamic values.

FieldTypeRequiredDefaultDescription
idstringYes-Unique identifier (must match workloadType for primary)
targetPlanestringNodataplaneTarget plane: dataplane or observabilityplane
includeWhenstringNo-CEL expression determining if resource should be created
forEachstringNo-CEL expression for generating multiple resources from list
varstringNo-Variable name for forEach iterations (required if forEach is set)
templateobjectYes-Kubernetes resource template with CEL expressions

CEL Expression Syntax​

Templates use CEL expressions enclosed in ${...} that have access to the following context variables:

metadata​

Platform-computed metadata for resource generation:

FieldTypeDescription
metadata.namestringBase name for generated resources (e.g., my-service-dev-a1b2c3d4)
metadata.namespacestringTarget namespace for resources
metadata.componentNamespacestringTarget namespace of the component
metadata.componentNamestringName of the component
metadata.componentUIDstringUnique identifier of the component
metadata.projectNamestringName of the project
metadata.projectUIDstringUnique identifier of the project
metadata.environmentNamestringName of the environment (e.g., development, production)
metadata.environmentUIDstringUnique identifier of the environment
metadata.dataPlaneNamestringName of the data plane
metadata.dataPlaneUIDstringUnique identifier of the data plane
metadata.labelsmapCommon labels to add to all resources
metadata.annotationsmapCommon annotations to add to all resources
metadata.podSelectorsmapPlatform-injected selectors for pod identity (use in Deployment/Service selectors)
parameters​

Component parameters from Component.spec.parameters with schema defaults applied. Use for static configuration that doesn't change across environments.

environmentConfigs​

Environment-specific overrides from ReleaseBinding.spec.componentTypeEnvironmentConfigs with schema defaults applied. Use for values that vary per environment (resources, replicas, etc.).

workload​

Workload specification from the Workload resource:

FieldTypeDescription
workload.containerobjectContainer configuration
workload.container.imagestringContainer image
workload.container.command[]stringContainer command
workload.container.args[]stringContainer arguments
workload.endpointsmap[string]objectNetwork endpoints keyed by endpoint name
workload.endpoints[name].typestringEndpoint protocol (HTTP, REST, gRPC, GraphQL, Websocket, TCP, UDP)
workload.endpoints[name].portint32Port number
workload.endpoints[name].basePathstringBase path prefix (optional, default "/")
workload.endpoints[name].visibility[]stringVisibility scopes: "project", "external", "internal"
configurations​

Configuration and secret references extracted from the workload container:

FieldTypeDescription
configurations.configs.envs[]objectEnvironment variable configs (each has name, value)
configurations.configs.files[]objectFile configs (each has name, mountPath, value)
configurations.secrets.envs[]objectSecret env vars (each has name, value, remoteRef)
configurations.secrets.files[]objectSecret files (each has name, mountPath, remoteRef)

The remoteRef object contains: key, property (optional), version (optional).

Configuration Helper Functions:

The configurations object provides several helper methods to simplify working with container configurations. See Configuration Helpers for detailed documentation on these functions:

  • configurations.toContainerEnvFrom() - Generate envFrom array for the container
  • configurations.toConfigEnvsByContainer() - List config environment variables
  • configurations.toSecretEnvsByContainer() - List secret environment variables
  • configurations.toConfigFileList() - Flatten all config files into a single list
  • configurations.toSecretFileList() - Flatten all secret files into a single list
  • configurations.toContainerVolumeMounts() - Generate volumeMounts for the container
  • configurations.toVolumes() - Generate volumes array
dataplane​

Data plane configuration:

FieldTypeDescription
dataplane.secretStorestringName of the ClusterSecretStore for external secrets
dataplane.publicVirtualHoststringPublic virtual host for external access
gateway​

Ingress gateway configuration for HTTPRoute generation:

FieldTypeDescription
gateway.ingress.external.namestringName of the external ingress Gateway resource
gateway.ingress.external.namespacestringNamespace of the external ingress Gateway resource
gateway.ingress.external.httpobjectHTTP listener (optional; has .host)
gateway.ingress.external.httpsobjectHTTPS listener (optional; has .host)
gateway.ingress.internal.namestringName of the internal ingress Gateway resource
gateway.ingress.internal.namespacestringNamespace of the internal ingress Gateway resource
gateway.ingress.internal.httpobjectHTTP listener for internal gateway (optional; has .host)
gateway.ingress.internal.httpsobjectHTTPS listener for internal gateway (optional; has .host)
Helper Functions​
FunctionDescription
oc_generate_name(args...)Generate valid Kubernetes names with hash suffix for uniqueness
oc_hash(string)Generate 8-character FNV-32a hash from input string
oc_merge(map1, map2, ...)Shallow merge maps (later maps override earlier ones)
oc_omit()Remove field/key from output when used in conditional expressions
oc_dns_label(args...)Generate RFC 1123-compliant DNS label (≀63 chars) with hash suffix for HTTPRoute hostnames

For a comprehensive guide to configuration helper functions, see the Configuration Helpers.

Examples​

Basic HTTP Service ComponentType​

apiVersion: openchoreo.dev/v1alpha1
kind: ComponentType
metadata:
name: service
namespace: default
spec:
workloadType: deployment

parameters:
openAPIV3Schema:
type: object
properties:
replicas:
type: integer
default: 1
port:
type: integer
default: 80

resources:
- id: deployment
template:
apiVersion: apps/v1
kind: Deployment
metadata:
name: ${metadata.name}
namespace: ${metadata.namespace}
spec:
replicas: ${parameters.replicas}
selector:
matchLabels: ${metadata.podSelectors}
template:
metadata:
labels: ${metadata.podSelectors}
spec:
containers:
- name: main
image: ${workload.container.image}
ports:
- containerPort: ${parameters.port}

- id: service
template:
apiVersion: v1
kind: Service
metadata:
name: ${metadata.componentName}
namespace: ${metadata.namespace}
spec:
selector: ${metadata.podSelectors}
ports:
- port: 80
targetPort: ${parameters.port}

- id: httproute-external
forEach: '${workload.endpoints.transformList(name, ep, ("external" in ep.visibility && ep.type in ["HTTP", "REST", "GraphQL", "Websocket"]) ? [name] : []).flatten()}'
var: endpoint
template:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: ${oc_generate_name(metadata.componentName, endpoint)}
namespace: ${metadata.namespace}
labels: '${oc_merge(metadata.labels, {"openchoreo.dev/endpoint-name": endpoint, "openchoreo.dev/endpoint-visibility": "external"})}'
spec:
parentRefs:
- name: ${gateway.ingress.external.name}
namespace: ${gateway.ingress.external.namespace}
hostnames: |
${[gateway.ingress.external.?http, gateway.ingress.external.?https]
.filter(g, g.hasValue()).map(g, g.value().host).distinct()
.map(h, oc_dns_label(endpoint, metadata.componentName, metadata.environmentName, metadata.componentNamespace) + "." + h)}
rules:
- matches:
- path:
type: PathPrefix
value: /${metadata.componentName}-${endpoint}
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: '${workload.endpoints[endpoint].?basePath.orValue("") != "" ? workload.endpoints[endpoint].?basePath.orValue("") : "/"}'
backendRefs:
- name: ${metadata.componentName}
port: ${workload.endpoints[endpoint].port}

Scheduled Task ComponentType​

apiVersion: openchoreo.dev/v1alpha1
kind: ComponentType
metadata:
name: scheduled-task
namespace: default
spec:
workloadType: cronjob

parameters:
openAPIV3Schema:
type: object
properties:
schedule:
type: string
concurrencyPolicy:
type: string
default: Forbid
enum:
- Allow
- Forbid
- Replace

resources:
- id: cronjob
template:
apiVersion: batch/v1
kind: CronJob
metadata:
name: ${metadata.name}
namespace: ${metadata.namespace}
spec:
schedule: ${parameters.schedule}
concurrencyPolicy: ${parameters.concurrencyPolicy}
jobTemplate:
spec:
template:
spec:
containers:
- name: main
image: ${workload.container.image}
restartPolicy: OnFailure

ComponentType with Resource Iteration​

apiVersion: openchoreo.dev/v1alpha1
kind: ComponentType
metadata:
name: multi-config-service
namespace: default
spec:
workloadType: deployment

resources:
- id: deployment
template:
# ... deployment spec ...

- id: file-config
includeWhen: ${has(configurations.configs.files) && configurations.configs.files.size() > 0}
forEach: ${configurations.configs.files}
var: config
template:
apiVersion: v1
kind: ConfigMap
metadata:
name: ${metadata.name}-${config.name}
namespace: ${metadata.namespace}
data:
${config.name}: ${config.value}

Usage​

Components reference a ComponentType using the spec.componentType field:

apiVersion: openchoreo.dev/v1alpha1
kind: Component
metadata:
name: my-service
spec:
componentType:
kind: ComponentType
name: deployment/service # References the ComponentType
parameters:
replicas: 3
port: 8080

Best Practices​

  1. Naming Convention: Use descriptive names like service, web-application, scheduled-task
  2. Parameter Design: Keep parameters focused and provide sensible defaults
  3. Resource IDs: Use clear, descriptive IDs for each resource template
  4. Conditional Resources: Use includeWhen for optional resources based on parameters
  5. Type Definitions: Define reusable types for complex parameter structures
  6. Testing: Validate ComponentTypes with sample components before platform-wide deployment