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

Sources

caution

SourceDefinition and $( ) property expressions are alpha features. Both are disabled by default and must be turned on with feature gates, see Enable the feature.

Applications often need data that lives somewhere else: a registry address in a ConfigMap, the owner label on a namespace, a file in a Git registry, the health of another Application. Today you fetch that data with workflow steps and pass it along by hand, so application authors have to know where the data comes from and how to move it.

A SourceDefinition removes that work. A platform engineer declares how to fetch a piece of data, what shape it has, and how long it can be cached. An application author names the source, and writes an expression wherever the value should go. The platform controls how and when the data is fetched. The application author controls what they need and where it goes.

How it works​

Four pieces take part:

LayerObjectWritten byResponsibility
DefinitionSourceDefinitionPlatform engineerDeclares the output schema, the cache policy and the fetch logic
Bindingspec.sources[] in an ApplicationApplication authorNames a SourceDefinition, gives it a local name and supplies its properties
ResolutionConfigControllerServes a cached value, or runs the fetch logic and stores the result
Consumption$( ) expressionApplication authorPuts a resolved value into a property of a component, trait, workflow step or policy
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: checkout
annotations:
app.oam.dev/cel-expressions: "true"
spec:
sources:
- name: registry # local name, used in expressions
type: platform-registry # the SourceDefinition
components:
- name: api
type: webservice
properties:
image: '$(source.registry.host + "/api:1.4.0")'

When the controller renders the api component it does the following:

  1. It finds the expression and works out that registry is needed.
  2. It computes the cache key for platform-registry and looks for a fresh cached value.
  3. Only on a cache miss, or when the cached value has expired, it runs the definition's fetch logic and stores the result.
  4. It substitutes the resolved value into image, then renders the component with concrete values.

The component's own template never fetches anything. It receives a plain string.

Admission checks the binding before anything is fetched. Every expression must name a field the source declares, and the type of the expression must fit the parameter it feeds. See Using sources.

Enable the feature​

Expressions are off by default. $(VAR_NAME) is also Kubernetes' own syntax for a dependent environment variable in env, command and args. If expressions were read everywhere, an existing Application using that form would be refused. Two feature gates therefore give three states:

StateEnableCelExpressionsRequireCelExpressionOptInExpressions are read in
Off (default)falsen/ano Application
Opt-intruetrue (default)Applications annotated app.oam.dev/cel-expressions: "true"
Ontruefalseevery Application

Set them through the chart:

helm upgrade kubevela kubevela/vela-core \
-n vela-system \
--reset-then-reuse-values \
--set featureGates.enableCelExpressions=true

--reset-then-reuse-values needs Helm 3.14 or later. It keeps the user-supplied values from the current release and takes the rest from the chart.

Or pass --feature-gates=EnableCelExpressions=true to the controller, see Feature Gates.

Opt-in mode is meant for a gradual rollout. Enable the feature, let each team annotate the Applications it has checked for $(VAR) strings, and set featureGates.requireCelExpressionOptIn=false only after every Application has been reviewed.

Two more gates affect sources and policies:

GateDefaultEffect
EnableSourceAutoUpdatefalseDefault for spec.sources[].autoUpdate
EnableApplicationScopedPoliciesfalseRequired for all Application-scoped policy functionality

Sources that ship with KubeVela​

Eight SourceDefinitions are installed with vela-core, so most Applications do not need to author one. See Built-in sources.

Next​