Documentation
¶
Overview ¶
Package expressions answers the roots a $( ) expression in a workflow step may read: context, steps and each. A host such as KubeVela adds roots of its own, with their resolvers, through NewEngine.
Index ¶
- Constants
- func ConditionsWithoutExpressions(stepsPath *field.Path, steps []v1alpha1.WorkflowStep, why string) field.ErrorList
- func ContextResolver(pCtx process.Context) cel.Resolver
- func EachResolver(pCtx process.Context) cel.Resolver
- func EnabledFor(annotations map[string]string) bool
- func IsCondition(cond string) bool
- func MayHoldExpression(raw []byte) bool
- func MisplacedCondition(cond string) bool
- func MisplacedConditions(stepsPath *field.Path, steps []v1alpha1.WorkflowStep) field.ErrorList
- func NewEngine(host ...cel.Root) (*cel.Engine, error)
- func StepsResolver(steps []v1alpha1.WorkflowStep, status map[string]wfv1alpha1.StepStatus, ...) cel.Resolver
- func StepsWithReadDependencies(steps []v1alpha1.WorkflowStep, mode *v1alpha1.WorkflowExecuteMode, ...) []v1alpha1.WorkflowStep
- func Validate(base *field.Path, steps []v1alpha1.WorkflowStep, ...) field.ErrorList
- type Evaluator
- func (e *Evaluator) Condition(ctx context.Context, step types.ExpressionStep, cond string, ...) (bool, error)
- func (e *Evaluator) Properties(ctx context.Context, step types.ExpressionStep, ...) (*runtime.RawExtension, error)
- func (e *Evaluator) WithReadDependencies(steps []v1alpha1.WorkflowStep, mode *v1alpha1.WorkflowExecuteMode) ([]v1alpha1.WorkflowStep, map[string][]string)
- type RunScope
- type RunStore
- type Vars
Constants ¶
const ( // RootContext is the step's context: the run's name and namespace, the step's // name, and whatever the run adds. It is the context a CUE template reads. RootContext = "context" // RootSteps is the outputs earlier steps declare, as steps.<name>.outputs.<output>. RootSteps = "steps" // RootEach is the current forEach iteration, as each.item, each.index and each.key: the // names inputs[].from reads it by. RootEach = model.ContextEach )
Variables ¶
This section is empty.
Functions ¶
func ConditionsWithoutExpressions ¶
func ConditionsWithoutExpressions(stepsPath *field.Path, steps []v1alpha1.WorkflowStep, why string) field.ErrorList
ConditionsWithoutExpressions refuses every $( ) if, on a step or a sub-step, of a run that does not read expressions, with why as the reason. Without an evaluator the engine reads such an if as CUE, which it is not, and skips the step.
func ContextResolver ¶
ContextResolver answers context from the step's process context.
func EachResolver ¶
EachResolver answers each from the step's process context, where a forEach iteration sets it.
func EnabledFor ¶
EnabledFor reports whether a WorkflowRun with these annotations resolves $( ) expressions: the feature gate is on and the run opts in.
func IsCondition ¶
IsCondition reports whether a step's if is a $( ) condition: exactly one expression, the whole of the value. Any other if is CUE, as it always was; a "$(" inside a CUE string does not make one.
func MayHoldExpression ¶
MayHoldExpression reports whether a JSON document may hold a $( ) expression: it holds the marker, as written or with either character as a JSON escape.
func MisplacedCondition ¶
MisplacedCondition reports an if with a $( ) outside its CUE strings and comments that is not one $( ) expression. A $$( is an escape, not an expression.
func MisplacedConditions ¶
MisplacedConditions refuses every if, on a step or a sub-step, that holds a $( ) outside a CUE string without being one $( ) expression. Such an if is not a condition, and as CUE it never compiles, so the step would be skipped.
func NewEngine ¶
NewEngine builds an engine over the workflow's roots and the host's. A host root named like a workflow one replaces it.
func StepsResolver ¶
func StepsResolver(steps []v1alpha1.WorkflowStep, status map[string]wfv1alpha1.StepStatus, vars Vars) cel.Resolver
StepsResolver answers steps.<name>.outputs.<output> for an output the named step declares. A read waits while that step has still to finish, and fails once it has failed or been skipped, since then it never will.
A step in a forEach body reads by the names inputs[].from does: inside the loop, a body step's outputs are this iteration's; outside it, they are the lists the loop collected, ready once the loop is.
func StepsWithReadDependencies ¶
func StepsWithReadDependencies(steps []v1alpha1.WorkflowStep, mode *v1alpha1.WorkflowExecuteMode, host ...cel.Root) []v1alpha1.WorkflowStep
StepsWithReadDependencies is steps with the dependsOn their expressions' reads imply, as a run orders them, for code that works on a workflow's steps outside a run, such as restarting one from a step. host is the roots the host offers.
func Validate ¶
func Validate(base *field.Path, steps []v1alpha1.WorkflowStep, mode *v1alpha1.WorkflowExecuteMode, host ...cel.Root) field.ErrorList
Validate checks every expression in a workflow's steps without evaluating any: that it compiles, reads only roots offered where it sits, and reads only step outputs that exist and that the step can wait for. host is the roots the host answers, as given to ExpressionOptions.
Types ¶
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator resolves the expressions in one workflow's step properties.
func NewEvaluator ¶
func NewEvaluator(opts types.ExpressionOptions, steps []v1alpha1.WorkflowStep, run string) (*Evaluator, error)
NewEvaluator builds the evaluator for a workflow's steps, with the host's roots and resolvers beside the workflow's own. run identifies this run of the workflow to the host's resolvers (RunFrom).
func (*Evaluator) Condition ¶
func (e *Evaluator) Condition(ctx context.Context, step types.ExpressionStep, cond string, wfCtx wfContext.Context, pCtx process.Context, status map[string]wfv1alpha1.StepStatus) (bool, error)
Condition evaluates a step's $( ) if, reading what the step's properties may. It must be a bool. A read still to be answered is cel.ErrNotReady, so the step waits rather than being skipped.
func (*Evaluator) Properties ¶
func (e *Evaluator) Properties(ctx context.Context, step types.ExpressionStep, properties *runtime.RawExtension, wfCtx wfContext.Context, pCtx process.Context, status map[string]wfv1alpha1.StepStatus) (*runtime.RawExtension, error)
Properties returns properties with every expression replaced by its value. A read that cannot be answered yet returns an error that is cel.ErrNotReady.
func (*Evaluator) WithReadDependencies ¶
func (e *Evaluator) WithReadDependencies(steps []v1alpha1.WorkflowStep, mode *v1alpha1.WorkflowExecuteMode) ([]v1alpha1.WorkflowStep, map[string][]string)
WithReadDependencies returns a copy of steps in which each step dependsOn the steps its expressions read, and, by step name, the steps each one reads: the edges it added, and the earlier steps a workflow run in order puts first without one. A read of a forEach body step from outside the loop is a read of the loop.
No edge is added for a step the order already puts first, the reader itself or its own loop, a later step in a workflow run in order, or a read that would close a cycle.
type RunScope ¶
type RunScope struct {
// Run identifies this run of the workflow. A workflow context can outlive a
// run, as an Application's does across revisions, so a value kept in Store
// is the run's only if it was kept under this.
Run string
// Step and StepType are the step whose expressions are resolved, Step as
// it runs: a forEach iteration's step has its own name.
Step string
StepType string
Store RunStore
}
RunScope is the run and step a host's resolver answers for, so that it can hold a value for the whole run and say which step read it.