When
Thewhen expression controls conditional step execution. Evaluate parameters, previous step outputs, or workflow status to skip steps dynamically. If the expression resolves to false, the step is skipped—making when the primary built-in branching mechanism for simple if/then/else logic in Argo Workflows.
Example: run tests only in non-production environments.
Use
when for lightweight branching. For more complex logic, combine when
with parameters and outputs from previous steps or use conditional templates.Daemon
A daemon template runs a container in the background (service mode). The workflow does not wait for a daemon step to exit. This is useful for temporary services (databases, mock APIs) that other steps need while they run. Example: start Redis in the background and run tests that connect to it.activeDeadlineSeconds (timeouts)
activeDeadlineSeconds sets a maximum runtime for a template or the entire workflow. When the limit is exceeded, Argo terminates the step or workflow and marks it failed—preventing hung workloads from consuming cluster resources.
Example: global workflow timeout with per-template overrides.
- Workflow-level
activeDeadlineSecondsapplies to the whole run. - Template-level settings override the workflow-level timeout for that template.
- Use conservative timeouts to avoid prematurely killing long-running valid work.
onExit (exit handler)
onExit sets an exit handler that always runs at the end of a workflow—whether it succeeded, failed, or was terminated. Use it for cleanup, alerts, or final audit logging. Inside the exit handler you can inspect variables like {{workflow.status}} to determine the final state.
Example: always run a cleanup template that reports the workflow status.
onExit runs even when the workflow is terminated externally, making it a reliable place to free resources or post a final summary.
retryStrategy
retryStrategy enables automatic retries for failing steps. Configure retry limit, retry policy, and backoff settings (initial duration, multiplier, and max backoff). This is essential for handling transient failures (network flakiness, intermittent external service errors).
Example: retry up to 3 times with exponential backoff.
Use
retryStrategy for transient failures. Tune retryPolicy and backoff to
match the expected failure profile of your tasks.Resource template: successCondition and failureCondition
Resource templates allow Argo to create Kubernetes resources and then poll their live status. UsesuccessCondition and failureCondition to evaluate the resource’s status object so the workflow reflects the actual readiness of the resource (not just the API apply success).
- successCondition: expression evaluated against the live resource that marks the step successful when true (e.g.,
status.succeeded == 1for a Job). - failureCondition: expression evaluated against the live resource that marks the step failed when true (e.g.,
status.failed > 3).
- Argo creates a Job with
backoffLimit: 4andfailureCondition: status.failed > 3. - Argo polls the Job status repeatedly and evaluates success/failure expressions.
- If
status.succeeded == 1becomes true first → step succeeds. - If
status.failed > 3becomes true first → step fails.
{ succeeded: 0, failed: 0 }
Attempt 1 - Pod Fails
K8s Job Controller:
Creates Pod #1 -> Pod exits with code 1 -> Pod fails
Updates Job: status.failed = 1
Job Status: (succeeded: 0, failed: 1)
Argo Polls Job:
Checks: 1 > 3 ❌ FALSE
Continue waiting…
Attempt 2 - Pod Fails
K8s Job Controller:
Creates Pod #2 -> Pod exits with code 1 -> Pod fails
Updates Job: status.failed = 2
Job Status: (succeeded: 0, failed: 2)
Argo Polls Job:
Checks: 2 > 3 ❌ FALSE
Continue waiting…
Attempt 3 - Pod Fails
K8s Job Controller:
Creates Pod #3 -> Pod exits with code 1 -> Pod fails
Updates Job: status.failed = 3
Job Status: (succeeded: 0, failed: 3)
Argo Polls Job:
Checks: 3 > 3 ❌ FALSE
Continue waiting…
Attempt 4 - Failure Condition Triggered!
K8s Job Controller:
Creates Pod #4 -> Pod exits with code 1 -> Pod fails
Updates Job: status.failed = 4
Job Status: (succeeded: 0, failed: 4)
Argo Polls Job:
Checks: 4 > 3 ✅ TRUE
Failure Condition Met!
Result: Argo marks the resource step as FAILED
Workflow stops or proceeds to onExit handler
Example resource template that waits for a Job to succeed:
Resource templates require the workflow’s ServiceAccount to have permissions
to create and read the resource types used in your manifest. Ensure RBAC is
configured (create, get, list, watch) for those resources.
- Tailor expressions to each resource kind (Job, Deployment, StatefulSet, etc.). Reference the resource’s
.statusschema when writing conditions. - Prefer conditions that reflect actual readiness (e.g.,
status.availableReplicas == spec.replicasfor Deployments). - Use
failureConditionto fail fast if the resource enters an unrecoverable state.
Quick reference table
| Field | Purpose | Typical use-case |
|---|---|---|
| when | Conditional execution of a step | Skip steps based on {{workflow.parameters}} or previous outputs |
| daemon | Run container as background service | Start DB or mock API for parallel consumers |
| activeDeadlineSeconds | Timeout for template or workflow | Prevent hung tasks from consuming resources |
| onExit | Exit handler that always runs | Cleanup, notifications, final logging |
| retryStrategy | Automatic retries with backoff | Handle transient failures (network, flaky services) |
| successCondition / failureCondition | Poll and evaluate live Kubernetes resource status | Wait for Jobs/Deployments to reach desired state before continuing |
Summary
- when: conditional step execution using parameters, outputs, or status.
- daemon: run background services that other steps can use; they are terminated when the workflow ends.
- activeDeadlineSeconds: enforce timeouts at workflow or template level to avoid resource leaks.
- onExit: reliable cleanup/notification handler executed at workflow completion.
- retryStrategy: configure retries and exponential backoff for transient errors.
- resource successCondition / failureCondition: poll and evaluate live Kubernetes resource status so workflow steps reflect the resource’s actual state.
- Argo Workflows docs: https://argoproj.github.io/argo-workflows/
- Kubernetes Jobs: https://kubernetes.io/docs/concepts/workloads/controllers/job/
- Kubernetes Deployments: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/