[Enhancement] Move `$( )` property expressions onto a shared CEL engine in kubevela/pkg, so workflow steps can evaluate them at run time
Is there an existing issue for this?
- I have searched the existing issues
Affected feature or component
Property expressions ($( ) in component, trait, policy and workflow step properties): pkg/definition/celexpr, pkg/definition/propexpr and pkg/sources in kubevela. The proposal also touches kubevela/pkg (new package) and kubevela/workflow (a later phase).
What is the current limitation or pain point?
The CEL engine behind $( ) lives inside kubevela and knows its roots by name: source, context and component are hard-coded throughout environment building, reference extraction and evaluation. That has two consequences.
Workflow steps cannot evaluate expressions when they run. kubevela/workflow cannot import kubevela, so step properties are substituted when kubevela generates the steps, before the WorkflowRun exists (resolveWorkflowStepSources). As a result:
- a source read in a step is frozen for the whole run, however long the run lasts or how long a step waits;
- a step cannot read anything that only exists while the workflow runs, such as an earlier step's outputs;
- a data-driven step
ifcannot be written as an expression.
Nothing else in the ecosystem can reuse the engine. kube-trigger filters and VelaUX validation would have to copy it, and copies drift.
Describe the improvement you'd like
Move the generic part of the engine into kubevela/pkg as a cel package that knows no roots by name. A host declares the roots its expressions may read and passes a resolver for each. Every read in a properties tree is collected first, each root's resolver is called once with all of its reads, and only then is anything evaluated.
engine, _ := cel.NewEngine(
cel.Root{Name: "component", QualifiedAt: 1, Qualifiers: []cel.Qualifier{{Name: "cluster"} /* ... */}},
cel.Root{Name: "context"},
cel.Root{Name: "source"},
)
out, err := engine.EvalTree(ctx, properties, map[string]cel.Resolver{
"component": componentScope, // delivered by the controller
"context": cel.Static(renderContext),
"source": cel.ResolverFunc(resolveSources), // gets every source.* read, with the property it feeds
}, cel.TreeOptions{})Why resolvers rather than functions that fetch data from inside CEL:
| Concern | Resolve first | I/O inside CEL functions |
|---|---|---|
| Admission typing and validation | every read is known statically | a call such as fetch("db") hides the read |
| Waiting on something not ready yet | the resolver says so before evaluation | CEL absorbs errors: true || notReady() is true, so a wait can vanish |
| Status, caching, deduplication | computed from the reads | lost or re-derived |
| Determinism and cost estimation | pure expressions | broken |
What the engine would provide:
| Roots and qualifiers | a host declares roots; a qualifier is a literal-argument member call on a root, such as component.db.cluster("east"), answered from values the resolver delivered |
| Resolvers | one call per root per tree, with every read and the property it feeds |
ErrNotReady |
a resolver's "wait, not fail" signal |
Unknown |
a root with no value in this evaluation, such as a dry run, whose reads the host renders |
| Typing | CUE schemas to CEL types, so admission can type-check an expression against the parameter it feeds |
Proposed phases:
| # | Repo | Change | User-facing |
|---|---|---|---|
| 1 | kubevela/pkg | add the cel package |
none |
| 2 | kubevela | declare source, context and component on the engine; the render becomes one call with three resolvers |
none intended; see below |
| 3 | kubevela/workflow | the executor accepts an engine and resolvers from its host, and evaluates step properties when a step runs | a source read in a step is resolved when that step runs |
| 4 | kubevela/workflow | roots native to the workflow, such as step outputs, and a CEL step if |
new capabilities, each to be designed separately |
Semantics to agree for phase 3. With evaluation at step run, a source is resolved when each step runs and is served from its cache within the TTL. If the TTL lapses mid-run, later steps can see a newer value than earlier ones. Per-step resolution status already records what each step read, so this would be visible. If a single value per run is ever needed, the cache entry could be pinned per WorkflowRun later, without changing the expression API. A standalone WorkflowRun, with no kubevela, would get only the roots workflow itself declares.
Behaviour worth reviewing in phase 2. While building a prototype, a few existing behaviours turned out to be inconsistent. The proposal would change them:
- A literal list index would be part of a read (
addresses[0]), rather than dropped, so a component read waits for the element itself. - A list or map embedded in text (
--tags=$(source.cfg.tags)) would be refused with an error suggesting.join(), instead of rendering Go syntax such as[a b]. - A placement call would be accepted only straight after
component.<name>, and only with a literal argument. - A guard would count only where it proves the path present for the branch the read is in (
has(x) ? d : xdoes not guardx).
Alternatives considered
- Keep substituting step properties when steps are generated (today). This is simple, but values are frozen for the run, and no workflow-native root is possible.
- Let CEL functions fetch data themselves. Rejected for the reasons in the table above.
- Move source resolution itself into
kubevela/workflow. That would drag SourceDefinitions, their cache and CRDs into the workflow engine. Resolvers keep that in kubevela and hand the workflow only the capability.
Additional context
Repos: kubevela/pkg (new cel), kubevela (pkg/definition/celexpr, pkg/definition/propexpr, pkg/sources, the application webhook and controller), kubevela/workflow (later phases).
Dependencies:
- The chain is pkg → workflow → kubevela, so phase 3 needs a
pkgrelease, then aworkflowbump, then akubevelabump. cel-go v0.20.1,k8s.io/apiserver v0.31.10(forapiserver/pkg/cel) andcuelang.org/go v0.14.1are already pinned across all three repos; onlypkgwould need to promote cel-go to a direct dependency.
Prototype, for discussion:
- kubevela/pkg#143: the engine.
- kubevela/kubevela#7398 (draft): kubevela's expressions on the engine. It is stacked on #7397 (component reads) and consumes #143 through a temporary fork
replace.
The prototype passes kubevela's source-expression and component-read e2e suites. The multicluster e2e has not been run yet.
Source: kubevela/kubevela