-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(controller): auto-restart pods that failed before starting #15086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0aea37a
6185042
af89010
3391e67
f99244b
dc6861b
7b02165
3734918
c0feaa8
9c55d40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| Description: Restart pods that fail before starting | ||
| Authors: [Alan Clucas](https://github.com/Joibel) | ||
| Component: General | ||
| Issues: 12572 | ||
|
|
||
| Automatically restart pods that fail before starting for reasons like node eviction. | ||
| This is safe to do even for non-idempotent workloads. | ||
| You need to configure this in your workflow controller configmap for it to take effect. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # Automatic Pod Restarts | ||
|
|
||
| Argo Workflows can automatically restart pods that fail due to infrastructure issues before the main container starts. | ||
| This feature handles transient failures like node evictions, disk pressure, or unexpected admission errors without requiring a `retryStrategy` on your templates. | ||
|
|
||
| ## How It Works | ||
|
|
||
| When a pod fails before its main container enters the Running state, the workflow controller checks if the failure reason indicates an infrastructure issue. | ||
| If so, the pod is automatically deleted and recreated, allowing the workflow to continue. | ||
| For safety this mechanism only works on pods we know never started, for pods that might have started `retryStrategy` is the solution. | ||
|
|
||
| This is different from [retryStrategy](retries.md), which handles application-level failures after the container has run. | ||
| These are complementary mechanisms, in that both can occur. | ||
| Automatic pod restarts handle infrastructure-level failures that occur before your code even starts. | ||
|
|
||
| ### Restartable Failure Reasons | ||
|
|
||
| The following pod failure reasons trigger automatic restarts: | ||
|
|
||
| | Reason | Description | | ||
| |--------|-------------| | ||
| | `Evicted` | Node pressure eviction (`DiskPressure`, `MemoryPressure`, etc.) | | ||
| | `NodeShutdown` | Graceful node shutdown | | ||
| | `NodeAffinity` | Node affinity/selector no longer matches | | ||
| | `UnexpectedAdmissionError` | Unexpected error during pod admission | | ||
|
|
||
| ### Conditions for Restart | ||
|
|
||
| A pod qualifies for automatic restart when ALL of the following are true: | ||
|
|
||
| 1. The pod phase is `Failed` | ||
| 2. The main container never entered the `Running` state | ||
| 3. The failure reason is one of the restartable reasons listed above | ||
| 4. The restart count for this pod hasn't exceeded the configured maximum | ||
|
|
||
| ## Configuration | ||
|
|
||
| Enable automatic pod restarts in the workflow controller ConfigMap: | ||
|
|
||
| ```yaml | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: workflow-controller-configmap | ||
| data: | ||
| failedPodRestart: | | ||
| enabled: true | ||
| maxRestarts: 3 | ||
| ``` | ||
|
|
||
| ### Configuration Options | ||
|
|
||
| | Option | Type | Default | Description | | ||
| |--------|------|---------|-------------| | ||
| | `enabled` | `bool` | `false` | Enable automatic pod restarts | | ||
| | `maxRestarts` | `int` | `3` | Maximum restart attempts per node before giving up | | ||
|
|
||
| ## Monitoring | ||
|
|
||
| When a pod is automatically restarted, the node status is updated with: | ||
|
|
||
| - `FailedPodRestarts`: Counter tracking how many times the pod was restarted | ||
| - `Message`: Updated to indicate the restart, e.g., `Pod auto-restarting due to Evicted: The node had condition: [DiskPressure]` | ||
|
|
||
| You can view restart counts in the workflow status: | ||
|
|
||
| ```bash | ||
| kubectl get wf my-workflow -o jsonpath='{.status.nodes[*].failedPodRestarts}' | ||
| ``` | ||
|
|
||
| The [`pod_restarts_total`](metrics.md#pod_restarts_total) metric tracks restarts by reason, condition, and namespace. | ||
|
|
||
| ## Comparison with `retryStrategy` | ||
|
|
||
| | Feature | Automatic Pod Restarts | retryStrategy | | ||
| |---------|----------------------|---------------| | ||
| | **Trigger** | Infrastructure failures before container starts | Application failures after container runs | | ||
| | **Configuration** | Global (controller ConfigMap) | Per-template | | ||
| | **Use case** | Node evictions, disk pressure, admission errors | Application errors, transient failures | | ||
| | **Counter** | `failedPodRestarts` in node status | `retries` in node status | | ||
|
|
||
| Both features can work together. | ||
| If a pod is evicted before starting, automatic restart handles it. | ||
| If the container runs and fails, `retryStrategy` handles it. | ||
| Some pods may not be idempotent, and so a `retryStrategy` would not be suitable, but restarting the pod is safe. | ||
|
|
||
| ## Example | ||
|
|
||
| A workflow running on a node that experiences disk pressure: | ||
|
|
||
| 1. Pod is scheduled and init containers start | ||
| 2. Node experiences `DiskPressure`, evicting the pod before main container starts | ||
| 3. Controller detects the eviction and `FailedPodRestarts` condition | ||
| 4. Pod is deleted, and in workflow the node is marked as Pending to recreate the pod | ||
| 5. New pod is created on a healthy node | ||
| 6. Workflow continues normally | ||
|
|
||
| The workflow succeeds without any template-level retry configuration needed. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/bin/bash | ||
| #!/usr/bin/env bash | ||
| set -eu -o pipefail | ||
|
|
||
| cd "$(dirname "$0")/../.." # up to repo root | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.