Retries¶
Argo Workflows offers a range of options for retrying failed steps.
restarts
For infrastructure-level failures that occur before your container starts (like node evictions or disk pressure), see Automatic Pod Restarts.
This page covers application-level retries using retryStrategy.
Configuring retryStrategy in WorkflowSpec¶
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: retry-container-
spec:
entrypoint: retry-container
templates:
- name: retry-container
retryStrategy:
limit: "10"
container:
image: python:alpine3.23
command: ["python", -c]
# fail with a 66% probability
args: ["import random; import sys; exit_code = random.choice([0, 1, 1]); sys.exit(exit_code)"]
The retryPolicy and expression are re-evaluated after each attempt. For example, if you set retryPolicy: OnFailure and your first attempt produces a failure then a retry will be attempted. If the second attempt produces an error, then another attempt will not be made.
Retry policies¶
Use retryPolicy to choose which failure types to retry:
Always: Retry all failed stepsOnFailure: Retry steps whose main container is marked as failed in KubernetesOnError: Retry steps that encounter Argo controller errors, or whose init or wait containers failOnTransientError: Retry steps that encounter errors defined as transient, or errors matching theTRANSIENT_ERROR_PATTERNenvironment variable.
The retryPolicy applies even if you also specify an expression, but the default policy means the expression makes the decision unless you explicitly specify a policy.
The default retryPolicy is OnFailure, except when an expression is also supplied, when it is Always.
This may be easier to understand in this diagram.
flowchart LR
start([Will a retry be attempted])
start --> policy
policy(Policy Specified?)
policy-->|No|expressionNoPolicy
policy-->|Yes|policyGiven
policyGiven(Expression Specified?)
policyGiven-->|No|policyGivenApplies
policyGiven-->|Yes|policyAndExpression
policyGivenApplies(Supplied Policy)
policyAndExpression(Supplied Policy AND Expression)
expressionNoPolicy(Expression specified?)
expressionNoPolicy-->|No|onfailureNoExpr
expressionNoPolicy-->|Yes|always
onfailureNoExpr[OnFailure]
always[Only Expression matters]
An example retry strategy:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: retry-on-error-
spec:
entrypoint: error-container
templates:
- name: error-container
retryStrategy:
limit: "2"
retryPolicy: "Always"
container:
image: python
command: ["python", "-c"]
# fail with a 80% probability
args: ["import random; import sys; exit_code = random.choice(range(0, 5)); sys.exit(exit_code)"]
Conditional retries¶
You can also use expression to control retries.
This is an expr expression with access to the following variables:
-
lastRetry.exitCode: The exit code of the last retry as a string, or "-1" if not availableexpression: asInt(lastRetry.exitCode) > 1 # Retry if code is greater than 1 -
lastRetry.status: The phase of the last retry: Error, Failedexpression: lastRetry.status != "Error" # Retry if not an error -
lastRetry.duration: The duration of the last retry, in secondsexpression: asInt(lastRetry.duration) < 60 # Retry unless duration >= 1 minute -
lastRetry.message: The message output from the last retry. For a failed DAG template, the message ischild '<node ID>' failed, where the node ID is the ID of the first failed task in thetaskslist, whatever order the tasks failed in.# Retry if message matches the regular expression expression: lastRetry.message matches 'imminent node shutdown|pod deleted'
If expression evaluates to false, the controller does not retry the step or task.
If the controller cannot evaluate expression, it does not retry the step or task.
The retried node ends Error, and its message is the error from the expression.
The last attempt keeps its own phase, for example Failed.
The expression result will be logical and with the retryPolicy. Both must be true to retry.
Boolean operators can be used to combine multiple conditions. See example for usage.
Back-Off¶
You can configure the delay between retries with backoff. See example for usage.