Workflow Fundamentals
- Argo Workflows is a container-native workflow engine, implemented as CRDs. Each step runs as a container (pod)
apiVersion: argoproj.io/v1alpha1,kindisWorkflow,WorkflowTemplateorClusterWorkflowTemplate
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
namespace: argo
spec:
entrypoint: main
templates:
- name: main
container:
image: docker/whalesay
command: [cowsay]
args: ["hello world"]
Spec fields
entrypoint- template to start with- override at submit time:
argo submit wf.yaml --entrypoint other
- override at submit time:
templates- the workarguments- workflow-level parameters/artifactsserviceAccountName- SA the pods run asttlStrategy- cleanup of finished workflows (secondsAfterCompletion,secondsAfterSuccess,secondsAfterFailure)activeDeadlineSeconds- max run time for the whole workflowpodGC- pod garbage collection strategyvolumeClaimTemplates- PVCs created for the workflowonExit- exit handler template
spec:
entrypoint: main
serviceAccountName: workflow-executor
activeDeadlineSeconds: 3600
ttlStrategy:
secondsAfterCompletion: 86400
arguments:
parameters:
- name: message
value: "Hello Argo"
templates:
- name: main
inputs:
parameters:
- name: message
container:
image: alpine:latest
command: [echo]
args: ["{{inputs.parameters.message}}"]
Phases
- Workflow phases:
Pending->Running->Succeeded/Failed/Error- Failed: a step failed (non-zero exit etc.)
- Error: system/controller level problem
SkippedandOmittedare node (step) phases, not workflow phasesOmitted:whenevaluated false / dependency omitted
- Checking:
argo get <wf>
argo watch <wf>
argo list
Basic patterns
Sequential / parallel
stepsis a list of lists- outer list = sequential
- inner list = parallel
steps:
- - name: step-1 # runs first
template: task
- - name: step-2a # 2a and 2b run in parallel
template: task
- name: step-2b
template: task
Conditional
whenuses an expression
- - name: prod
template: deploy-prod
when: "{{workflow.parameters.environment}} == production"
- name: dev
template: deploy-dev
when: "{{workflow.parameters.environment}} == development"
- Can also check earlier results:
when: "{{steps.step-1.status}} == Succeeded"
Loop
withItems(inline list),withParam(JSON list from a parameter),withSequence- Iterations run in parallel (limit with
parallelism)
- - name: process
template: process
arguments:
parameters:
- name: item
value: "{{item}}"
withItems: [apple, banana, cherry]
- For a list of objects use
{{item.field}}
Retry
retryStrategy:
limit: "3"
retryPolicy: Always # Always, OnFailure, OnError, OnTransientError
backoff:
duration: "10s"
factor: 2
maxDuration: "1m"
Variables
- Simple tag:
{{var}}; expression tag:{{=expr}}(v3.1+)
Global (workflow.*)
workflow.name,.namespace,.uid,.creationTimestamp,.serviceAccountName,.priorityworkflow.status- current phase (Succeeded/Failed/Error), mostly useful in exit handlersworkflow.failures- failure details, exit handlers onlyworkflow.labels.<k>,workflow.annotations.<k>,workflow.parameters.<name>- without the key they return everything as a JSON string
Inputs / outputs
inputs.parameters.<name>,inputs.artifacts.<name>.pathoutputs.parameters.<name>.path,outputs.artifacts.<name>.pathoutputs.result- stdout of acontainer/scripttemplate
Steps / DAG
- steps:
steps.<step>.outputs.result,.outputs.parameters.<n>,.outputs.artifacts.<n>,.status,.exitCode,.startedAt,.finishedAt,.ip,.id - dag: same, but
tasks.<task>.*
- name: deploy-app
dependencies: [generate-config]
template: deploy
arguments:
parameters:
- name: config
value: "{{tasks.generate-config.outputs.parameters.config}}"
Container/script only
pod.nameretries- current retry numberlastRetry.exitCode,.status,.duration,.message- these are strings, cast them:
when: "{{=asInt(lastRetry.exitCode) >= 2}}"
- these are strings, cast them:
Expression tags
{{=asInt(workflow.parameters.count) * 2}}- Type conversion:
asInt(),asFloat(),toString() - JSON:
toJson(),jsonpath() - expr-lang syntax for filter/map, plus Sprig functions
when: "{{=asInt(inputs.parameters.current) > asInt(inputs.parameters.threshold)}}"
Scoping
- Steps can only use outputs of steps that already finished
- DAG tasks can use outputs of tasks they depend on
- Exit handler can use workflow-level vars (
workflow.status,workflow.failures) but notsteps.X
Gotchas
- Hyphenated names: simple tags are fine (
{{inputs.parameters.my-param}}), expression tags need brackets:{{=inputs.parameters['my-param']}} - No whitespace inside the brackets
lastRetry.*are strings, soasInt()before comparing
Pipeline example
steps:
- - name: extract
template: extract-data
- - name: transform
template: transform-data
arguments:
parameters:
- name: raw-data
value: "{{steps.extract.outputs.parameters.data}}"
artifacts:
- name: data-file
from: "{{steps.extract.outputs.artifacts.dataset}}"
- - name: load
template: load-data
when: "{{=asInt(steps.transform.exitCode) == 0}}"
Remember
-
Workflow = CRD, both the definition and the live state record
-
entrypointpicks the starting template -
stepsfor sequential/parallel,whenfor conditions,retryStrategyfor transient failures -
serviceAccountNamecontrols permissions,ttlStrategyhandles cleanup