BatchSandbox: auto-replace pods stuck in intermediate failure states (e.g. ImagePullBackOff) during initial startup

Author: PangjipingCreated Sep 21, 2026Updated Sep 21, 2026

Motivation

BatchSandbox pods stuck in an intermediate failure state during initial startup (never Ready) are never recovered by the controller today. A production incident makes this concrete.

Incident (Kubernetes runtime)

  • A BatchSandbox pod was scheduled within 42 ms. The init container (execd) completed and the egress sidecar started, but the main container's image pull failed repeatedly with ImagePullBackOff because the node's disk was full:

    failed to prepare extraction snapshot ...: mkdir .../io.containerd.snapshotter.v1.overlayfs/snapshots/new-xxx:
    no space left on device
  • The pod never reached Ready. The BatchSandbox stayed Pending — which is correct per current semantics (see below) — but nothing ever recovered it: the pod lingered on the broken node for ~40 hours until it was garbage-collected.

  • The same root cause (nodes with full disks) left ~114 sandboxes stuck the same way within a few hours, clustered in bursts.

Current behavior (as of main, fbda73211)

The controller already distinguishes intermediate vs. terminal failures:

  • applySteadyRuntimePhase (kubernetes/internal/controller/batchsandbox_status.go:344-372) evaluates terminal-only failures (summarizeTerminalPodFailures) while the sandbox has never been Ready (Phase == "" || Pending), so ImagePullBackOff keeps Phase=Pending and does not trip the freeze gate. This tolerance is the right call.
  • hasTerminalPodFailureCondition (batchsandbox_status.go:374-385) freezes pod creation only for terminal reasons (PodFailed / ContainerFailed / InitContainerFailed). Consequently, if a stuck pod gets deleted for any reason, scaleBatchSandbox (batchsandbox_controller.go:698-762) recreates it by index — the "abandon + recreate" path already works today, but only when something else deletes the pod.
  • Nothing in the controller deletes a pod based on failure state: the only pod deletions are pause (batchsandbox_pause_resume.go:482), pool scale-down (pool_controller.go:1177), and pool eviction (eviction/eviction_default.go:46). There is no duration accounting and no retry budget for stuck pods.

Relying on kubelet's exponential image-pull backoff alone cannot escape a bad node: a full disk (or a broken image cache) is persistent, so the pull keeps failing on the same node forever.

Proposal

Add a bounded recovery step to the BatchSandbox reconcile loop:

  1. Trigger: the sandbox has never been Ready (Phase == "" || Pending), and a pod's (main) container has been in a recoverable waiting state — ImagePullBackOff / ErrImagePull — for longer than a threshold T.
  2. Action: delete the stuck pod and emit an Event; the existing scaleBatchSandbox path recreates it from the template, giving the scheduler a chance to pick a healthy node.
  3. Guardrails:
    • Per-sandbox replacement attempt limit + backoff (avoid hot-looping image pulls against a full disk).
    • First-observed timestamp accounting (waiting reasons carry no transition timestamp — needs controller-local state or a pod annotation).
    • CreateContainerConfigError and terminal failures are excluded; the existing freeze semantics stay untouched.
    • Observability: Events plus a status signal so upper layers can distinguish "recovering" from "stuck".

Notes

  • CrashLoopBackOff is intentionally out of scope for a first cut: moving a crashing pod to another node rarely helps and can mask application bugs.
  • Pool-mode sandboxes have a different lifecycle (allocation / eviction) and are out of scope here.

Happy to work on a PR if the maintainers think this fits the project's direction.

Source: opensandbox-group/OpenSandbox