A machine-readable index of this documentation for AI agents is available at https://kubevela.io/llms.txt. Markdown versions of documentation pages are available by appending .md to their URLs.
Skip to main content
Version: v1.10

OAM Definition Protocol

Definitions are Kubernetes objects. You can write them as YAML, or as CUE files that vela def converts. The definition file shows one definition in both formats and how the fields map.

You can manage the definition in CUE and the vela def command renders it into the Kubernetes API described on this page.

Definition API​

Essentially, a definition object in KubeVela is a programmable building block. A definition object normally includes several information to model a certain platform capability that would used in further application deployment:

  • Capability Indicator
    • ComponentDefinition uses spec.workload to indicate the workload type of this component.
    • TraitDefinition uses spec.definitionRef to name the CRD that provides this trait.
    • These indicators can be auto detected, so they're not necessary.
  • Interoperability Fields
    • they are for the platform to ensure a trait can work with given workload type. Hence only TraitDefinition has these fields.
  • Capability Encapsulation and Abstraction defined by spec.schematic
    • this defines the templating and parametering (i.e. encapsulation) of this capability.

Hence, the basic structure of definition object is as below:

apiVersion: core.oam.dev/v1beta1
kind: XxxDefinition
metadata:
name: <definition name>
annotations:
<map of annotations>
labels:
<map of labels>
spec:
...
schematic:
cue:
# cue template ...
# ... interoperability fields

The CUE format​

The CUE files vela def works with put the metadata and attributes (the spec) in one block, and the CUE template in template. The definition file has the full mapping between the two formats.

The rest of this page shows each definition kind as a Kubernetes object.

ComponentDefinition​

The design goal of ComponentDefinition is to allow platform administrators to encapsulate any type of deployable products into "components" to be delivered. Once defined, this type of component can be referenced, instantiated and delivered by users in the Application.

Common component types include Helm Chart, Kustomize directory, a set of Kubernetes YAML files, container images, cloud resource IaC files, or CUE configuration file modules, etc. The component supplier corresponds to the real-world role, which is generally a third-party software distributor (ISV), a DevOps team engineer, or a code package and image generated by the CI system you built.

ComponentDefinition can be shared and reused. For example, a Helm chart, a CUE module, or a Terraform module. Another example is, for an Alibaba Cloud RDS component type, end users can select the same Alibaba Cloud RDS component type in different applications and instantiate them into cloud database instances with different specifications and different parameter configurations.

Let's take a look at the frame format of ComponentDefinition:

apiVersion: core.oam.dev/v1beta1
kind: ComponentDefinition
metadata:
name: <ComponentDefinition name>
annotations:
definition.oam.dev/description: <Function description>
spec:
workload: # Workload Capability Indicator
definition:
apiVersion: <Kubernetes Workload resource group>
kind: <Kubernetes Workload types>
schematic: # Component description
cue: # Details of components defined by CUE language
template: <CUE format template>

The indicator of workload type is declared as spec.workload.

Below is a definition for Web Service in KubeVela:

apiVersion: core.oam.dev/v1beta1
kind: ComponentDefinition
metadata:
name: webservice
namespace: default
annotations:
definition.oam.dev/description: "Describes long-running, scalable, containerized services that have a stable network endpoint to receive external network traffic from customers."
spec:
workload:
definition:
apiVersion: apps/v1
kind: Deployment
...

In above example, it claims to leverage Kubernetes Deployment (apiVersion: apps/v1, kind: Deployment) as the workload type for component.

The programmable template of a capability is defined in the spec.schematic field. For a full example, look at the helm component type from the fluxcd addon. Enable the addon, then print the definition with:

vela addon enable fluxcd
vela def get helm

The specification of schematic is explained in the CUE with KubeVela documentations.

TraitDefinition​

TraitDefinition provides a series of DevOps actions for the component that can be bound on demand. These operation and maintenance actions are usually provided by the platform administrator, such as adding a load balancing strategy, routing strategy, or performing scaler, gray release strategy, etc.

The format and field functions of the TraitDefinition are as follows:

apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
name: <TraitDefinition name>
annotations:
definition.oam.dev/description: <function description>
spec:
definitionRef: # the CRD that provides this trait, if any
name: <CRD name, e.g. ingresses.networking.k8s.io>
appliesToWorkloads:
- <workload types this trait can be attached to>
conflictsWith:
- <traits that can't sit on the same component as this one>
podDisruptive: <true if adding or changing the trait restarts pods>
workloadRefPath: <field of the trait object that gets a reference to the workload>
revisionEnabled: <true if the trait is aware of component revisions>
manageWorkload: <true if the trait is responsible for creating the workload>
controlPlaneOnly: <true to dispatch the trait's resources to the hub cluster only>
stage: <PreDispatch, DefaultDispatch (the default) or PostDispatch>
version: <semantic version of this definition>
status:
customStatus: <CUE for the status message>
healthPolicy: <CUE for the health check>
details: <CUE for status details>
extension: <free-form data for platform builders>
schematic:
cue:
template: <CUE format template>

The interoperability fields are trait only. Let's explain them in detail.

.spec.appliesToWorkloads​

This field defines the constraints that what kinds of workloads this trait is allowed to apply to.

  • It accepts an array of string as value.
  • Each item in the array refers to one or a group of workload types to which this trait is allowed to apply.

There are three approaches to denote one or a group of workload types.

  • ComponentDefinition definition reference (CRD name), e.g., deployments.apps
  • Resource group of ComponentDefinition definition reference prefixed with *., e.g., *.apps, *.oam.dev. This means the trait is allowed to apply to any workloads in this group.
  • * means this trait is allowed to apply to any workloads

If this field is omitted, it means this trait is allowed to apply to any workload types.

For now, this field is not checked when applying application. Strict checking is planed to be implemented in the KubeVela 1.6.

.spec.conflictsWith​

This field defines that constraints that what kinds of traits are conflicting with this trait, if they are applied to the same workload.

  • It accepts an array of string as value.
  • Each item in the array refers to one or a group of traits.

There are three ways to name one or a group of traits.

  • TraitDefinition name, e.g., ingress
  • Resource group of TraitDefinition definition reference prefixed with *., e.g., *.networking.k8s.io. This means the trait is conflicting with any traits in this group.
  • * means this trait is conflicting with any other trait.

If this field is omitted, it means this trait is NOT conflicting with any traits.

.spec.workloadRefPath​

This field defines the field path of the trait which is used to store the reference of the workload to which the trait is applied.

  • It accepts a string as value, e.g., spec.workloadRef.

If this field is set, KubeVela core will automatically fill the workload reference into target field of the trait. Then the trait controller can get the workload reference from the trait latter. So this field usually accompanies with the traits whose controllers relying on the workload reference at runtime.

For example, when this field set in the following custom trait:

apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
name: myscaler
spec:
workloadRefPath: spec.workloadRef
schematic:
cue:
template: |
outputs: scaler: {
apiVersion: "core.oam.dev/v1alpha2"
kind: "ManualScalerTrait"
spec: {
replicaCount: parameter.replicas
}
}
parameter: {
//+short=r
//+usage=Replicas of the workload
replicas: *1 | int
}

The controller will automatically inject the apiVersion/Kind/Name of the workload defined in the component into the field specified in workloadRefPath, the result of the trait object in the app can be something like below, assume the workload is a Kubernetes Deployment:

apiVersion: "core.oam.dev/v1alpha2"
kind: "ManualScalerTrait"
spec:
workloadRef:
apiVersion: apps/v1
kind: Deployment
name: mywork
replicaCount: 1

.spec.podDisruptive​

This field says whether adding or changing the trait restarts the component's pods. It defaults to false.

Set it to true when the trait changes the pod template, so users know adding or changing it restarts pods.

The hpa trait below doesn't touch the pods, so it leaves the field at false:

apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: "configure k8s Horizontal Pod Autoscaler for Component which using Deployment as worklaod"
name: hpa
spec:
appliesToWorkloads:
- deployments.apps
workloadRefPath: spec.scaleTargetRef
schematic:
cue:
template: |
outputs: hpa: {
apiVersion: "autoscaling/v2beta2"
kind: "HorizontalPodAutoscaler"
spec: {
minReplicas: parameter.min
maxReplicas: parameter.max
metrics: [{
type: "Resource"
resource: {
name: "cpu"
target: {
type: "Utilization"
averageUtilization: parameter.cpuUtil
}
}
}]
}
}
parameter: {
min: *1 | int
max: *10 | int
cpuUtil: *50 | int
}

PolicyDefinition​

PolicyDefinition is similar to TraitDefinition, but where a trait acts on a single component, a policy acts on the whole application.

It can provide global policy for applications, commonly including global security policies (such as RBAC permissions, auditing, and key management), application insights (such as application SLO management, etc.).

The format is as follows:

apiVersion: core.oam.dev/v1beta1
kind: PolicyDefinition
metadata:
name: <PolicyDefinition name>
annotations:
definition.oam.dev/description: <function description>
spec:
schematic: # strategy description
cue:
template: <CUE format template>

The topology policy that ships with KubeVela looks like this:

apiVersion: core.oam.dev/v1beta1
kind: PolicyDefinition
metadata:
name: topology
annotations:
definition.oam.dev/description: Describe the destination where components should be deployed to.
spec:
schematic:
cue:
template: |
parameter: {
// +usage=Specify the names of the clusters to select.
clusters?: [...string]
// +usage=Specify the label selector for clusters
clusterLabelSelector?: [string]: string
// +usage=Ignore empty cluster error
allowEmpty?: bool
// +usage=Deprecated: Use clusterLabelSelector instead.
clusterSelector?: [string]: string
// +usage=Specify the target namespace to deploy in the selected clusters, default inherit the original namespace.
namespace?: string
}

The template only declares parameters: the controller knows topology (and override, and the other built-in policies) by name and acts on them itself. A policy you write takes effect through its output; see Custom Policy.

WorkflowStepDefinition​

WorkflowStepDefinition is used to describe a series of steps that can be declared in the workflow, such as the deployment of execution resources, status check, data output, dependent input, external script call, etc.

apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
name: <WorkflowStepDefinition name>
annotations:
definition.oam.dev/description: <function description>
spec:
schematic: # node description
cue:
template: <CUE format template>

The apply-component step that ships with KubeVela looks like this:

apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
name: apply-component
annotations:
custom.definition.oam.dev/category: Application Delivery
definition.oam.dev/description: Apply a specific component and its corresponding traits in application
labels:
custom.definition.oam.dev/scope: Application
spec:
schematic:
cue:
template: |
parameter: {
// +usage=Specify the component name to apply
component: string
// +usage=Specify the cluster
cluster: *"" | string
// +usage=Specify the namespace
namespace: *"" | string
}

Like the built-in policies, apply-component is run by the workflow engine by name, so its template only declares parameters. A step you write does its work in the template, with the vela/kube, vela/http and other providers; see Workflow Step Definition.

The Standard Protocol Behind Abstraction​

Once the application is created, KubeVela tags the created resources with a series of tags, which include the version, name, type, etc. of the application. Through these standard protocols, application components, traits and policies can be coordinated. The specific metadata list is as follows:

LabelDescription
workload.oam.dev/typeCorresponds to the name of ComponentDefinition
trait.oam.dev/typeCorresponds to the name of TraitDefinition
app.oam.dev/nameApplication name
app.oam.dev/componentComponent name
trait.oam.dev/resourceoutputs.\<resource type\>in Trait
app.oam.dev/appRevisionApplication Revision Name

Runtime Context Data in Definitions​

In the Definitions, some runtime context information can be obtained through the context variable, please check out:

Please note that all the Definition concepts introduced in this section only need to be understood by the platform administrator when they want to expand the functions of KubeVela. The end users will learn the schema of above definitions with visualized forms (or the JSON schema of parameters if they prefer) and reference them in application deployment plan. Please check the Generate Forms from Definitions section about how this is achieved.