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: Next

Context Reference

Every definition template can read context, the runtime data KubeVela fills in when it renders: which Application, where it is going, which component or step is being rendered. What context holds depends on the kind of definition. This page lists every field and where you can read it.

Fields​

A tick means the field is set when that kind of definition renders. The columns are:

  • Component: a ComponentDefinition template.
  • Trait: a TraitDefinition template. A trait renders against its component's context and adds to it.
  • Policy: a PolicyDefinition rendered into resources, as in Custom Policy.
  • App-scoped policy: an Application-scoped policy, which changes the Application before it renders.
  • Workflow step: a WorkflowStepDefinition template, as the step runs.
  • Source: a SourceDefinition template. A source reads only the fields its cache key can include, and only those its consumer has: a source read from a component can read componentName, one read from a workflow step can't.
FieldTypeMeaningComponentTraitPolicyApp-scoped policyWorkflow stepSource
context.namestringWhat is being rendered; see What context.name means✓✓✓✓✓✓
context.appNamestringThe Application's name✓✓✓✓✓✓
context.namespacestringThe namespace being rendered for: the Application's, or the one a topology policy places the component in✓✓✓✓✓✓
context.appNamespacestringThe Application's own namespace, wherever the component is placed✓✓✓✓✓✓
context.clusterstringThe cluster being rendered for; local is the hub. A policy always reads local✓✓✓✓
context.clusterVersionstructmajor, minor (int), gitVersion and platform of the target cluster, or of the hub where there is no target✓✓✓✓✓✓
context.appRevisionstringName of the current ApplicationRevision✓✓✓✓✓✓
context.appRevisionNumintNumber of the current ApplicationRevision✓✓✓✓✓✓
context.appLabelsmapThe Application's labels✓✓✓✓✓✓
context.appAnnotationsmapThe Application's annotations✓✓✓✓✓✓
context.publishVersionstringThe app.oam.dev/publishVersion annotation, when set✓✓✓✓✓
context.workflowNamestringThe app.oam.dev/workflowName annotation, when set✓✓✓✓✓
context.customanyData an Application-scoped policy published; absent unless one did✓✓✓✓✓✓
context.componentNamestringThe component being rendered✓✓✓
context.componentTypestringThe component's type✓✓✓
context.revisionstringName of the component's revision✓✓✓
context.replicaKeystringThe replica key, set by the replication policy✓✓✓
context.componentslistThe Application's spec.components✓✓✓
context.traitTypestringThe trait's type✓✓
context.outputobjectThe component's workload as rendered; the live object in a PostDispatch trait✓
context.outputs.<name>objectThe component's other resources, by their name in its outputs✓
context.artifactsobjectThe rendered resources of every component, as <component>.workload and <component>.traits.<type>.<name>✓
context.policyNamestringThe policy's name in spec.policies✓✓✓
context.policyTypestringThe policy's type✓✓✓
context.policyRevisionintThe PolicyDefinition's revision, when it is versioned✓
context.policyRevisionNamestringName of that DefinitionRevision✓
context.policyRevisionHashstringHash of the policy template✓
context.appComponentslistspec.components of the Application✓
context.appWorkflowobjectspec.workflow of the Application✓
context.appPolicieslistspec.policies of the Application✓
context.stepNamestringThe step being run✓✓
context.stepTypestringThe step's type, for a source read from a step's properties✓
context.stepSessionIDstringThe step's ID in the workflow status✓
context.spanIDstringThe trace ID of this reconcile, for logs✓
context.eachstructInside a forEach: item, index and key of the current pass✓

A component or trait's health policy and custom status read context.output and context.outputs too, as the live objects; see Definition Health & Status.

What context.name means​

context.name is the name of the thing being rendered, which differs by kind:

Kindcontext.name is
ComponentThe component
TraitThe component the trait is attached to (a trait has no name of its own; read context.traitType)
PolicyThe policy
App-scoped policyThe Application
Workflow stepThe Application (read context.stepName for the step)
SourceThe spec.sources[] entry being resolved

Where you mean a particular one, read the explicit field: context.appName, context.componentName, context.policyName or context.stepName.

Use the cluster version​

context.clusterVersion lets one definition work across Kubernetes versions. This picks the PodDisruptionBudget API by the target cluster's minor version:

outputs: pdb: {
if context.clusterVersion.minor < 21 {
apiVersion: "policy/v1beta1"
}
if context.clusterVersion.minor >= 21 {
apiVersion: "policy/v1"
}
kind: "PodDisruptionBudget"
}

Or match on the distribution through gitVersion:

import "strings"

if strings.Contains(context.clusterVersion.gitVersion, "k3s") {
provider: "k3s"
}