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: Workflow 0.6

Run a Workflow Template per Environment

A Workflow holds steps without running them. Each WorkflowRun that names it in workflowRef runs those steps, with its own context. Here one template configures an application for either environment, and if on context.env picks the steps that apply.

Needs: the vela-workflow controller (Install).

The template​

configure-env.yaml
apiVersion: core.oam.dev/v1alpha1
kind: Workflow
metadata:
name: configure-env
namespace: default
steps:
- name: dev-config
type: apply-object
if: context.env == "dev"
properties:
value:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config-dev
namespace: default
data:
logLevel: debug
- name: prod-config
type: apply-object
if: context.env == "prod"
properties:
value:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config-prod
namespace: default
data:
logLevel: warn
- name: done
type: print-message-in-status
properties:
message: configured

A Workflow has steps at the top level, not under spec, and an optional mode.

Two runs​

configure-runs.yaml
apiVersion: core.oam.dev/v1alpha1
kind: WorkflowRun
metadata:
name: configure-dev
namespace: default
spec:
context:
env: dev
workflowRef: configure-env
---
apiVersion: core.oam.dev/v1alpha1
kind: WorkflowRun
metadata:
name: configure-prod
namespace: default
spec:
context:
env: prod
workflowRef: configure-env

Run it​

kubectl apply -f configure-env.yaml
kubectl apply -f configure-runs.yaml
kubectl get workflowrun configure-dev configure-prod
NAME PHASE AGE
configure-dev succeeded 4s
configure-prod succeeded 4s

Each run took its own branch and skipped the other:

for r in configure-dev configure-prod; do
echo "== $r"
kubectl get workflowrun $r -o jsonpath='{range .status.steps[*]}{.name}{"\t"}{.phase}{"\t"}{.message}{"\n"}{end}'
done
== configure-dev
dev-config succeeded
prod-config skipped
done succeeded configured
== configure-prod
dev-config skipped
prod-config succeeded
done succeeded configured

A skipped step doesn't stop the ones after it: done ran in both. Each run wrote its own ConfigMap, app-config-dev and app-config-prod.

Changing the template​

Each reconcile reads the steps from the template, so an edit to configure-env reaches every WorkflowRun that hasn't finished, such as one waiting at a suspend step, as well as the next. A finished one keeps what it ran; vela workflow restart runs it again with the new steps.

Clean up​

kubectl delete workflowrun configure-dev configure-prod
kubectl delete workflow configure-env
kubectl delete configmap app-config-dev app-config-prod

Read more​