Skip to content

nf-k8s: Handle node disruption as an infrastructure failure in Pod and Job mode - #7464

Open
KasperWolsink99 wants to merge 4 commits into
nextflow-io:masterfrom
KasperWolsink99:k8s-disruption-target-preemption-retry
Open

nf-k8s: Handle node disruption as an infrastructure failure in Pod and Job mode#7464
KasperWolsink99 wants to merge 4 commits into
nextflow-io:masterfrom
KasperWolsink99:k8s-disruption-target-preemption-retry

Conversation

@KasperWolsink99

Copy link
Copy Markdown

Detect involuntary K8s node disruptions (e.g spot-vm pre-emption) and treat them as infrastructure failures so the affected task is resubmitted without consuming the retry budget, rather than surfacing them through the user-facing errorStrategy retry path.

Changes

  • Detect the DisruptionTarget pod condition in K8sClient.podState() and surface it as a NodeTerminationException. Complements the existing Shutdown and pod-not-found (404) detections, which don't fire reliably for graceful preemptions.
  • In Job mode, jobStateFallback0() now re-throws the original NodeTerminationException instead of throwing a ProcessFailedException if the issue was caused by a node termination/disruption. This ensures that these disruptions are resubmitted without consuming retry limit, which now functions the same as how it behaves in pod mode.
  • Added tests to cover this new functionality.

The second bullet point is interesting since it also affects already existing NodeTerminationException. In master these surface as a ProcessFailedException in job mode, which differs from how it behaves in pod mode. This PR also fixes this discrepancy.

Closes: #7378

Detect the `DisruptionTarget` pod condition (set by K8s on involuntary
disruptions such as Spot/preemptible node preemption or graceful node
shutdown) and surface it as a NodeTerminationException so the task is
retried, unless the container already exited successfully. This
complements the existing `Shutdown` and pod-not-found (404) detections,
which do not fire reliably for graceful preemptions.

Assisted-by: Claude Opus 4.8 (1M context)
Signed-off-by: Kasper Wolsink <k.wolsink@hartwigmedicalfoundation.nl>
In Job mode, `K8sClient.jobState()` caught any `NodeTerminationException`
thrown by `podState()` -- including the `DisruptionTarget`/`Shutdown`
detections -- and fell back to the Job status. With `backoffLimit: 0`
the Job reports a generic "backoff limit" failure, so the node-termination
signal was lost and the task retried via the normal errorStrategy path,
counting against `maxRetries`.

Pass the caught exception into `jobStateFallback0()` and re-throw it when
the Job has failed, so a genuine node disruption is surfaced as an
infrastructure failure and retried without counting against `maxRetries`
-- matching Pod mode. The succeeded-but-reaped fallback is unchanged and
still runs first, so a completed task is never re-run. Also drop the
misleading "Pod not found" warning, which was inaccurate for a present
pod carrying a disruption condition.

Assisted-by: Claude Opus 4.8 (1M context)
Signed-off-by: Kasper Wolsink <k.wolsink@hartwigmedicalfoundation.nl>
(cherry picked from commit 9040a5de0d17cd0ab383ad37cbad22b31421cf35)
Cover the three previously-untested branches of
K8sClient.jobStateFallback0():
- a failed Job with a node-termination exception -- re-thrown so the
  task is retried as an infrastructure failure
- a failed Job without one -- ProcessFailedException carrying the
  message from the Job's Failed condition
- a Job with no pods scheduled yet -- empty-map fall-through

Assisted-by: Claude Opus 4.8 (1M context)
Signed-off-by: Kasper Wolsink <k.wolsink@hartwigmedicalfoundation.nl>
Collapse the duplicated re-surfacing rationale that appeared at both
the catch site and the throw site into a single concise explanation.

Assisted-by: Claude Opus 4.8 (1M context)
Signed-off-by: Kasper Wolsink <k.wolsink@hartwigmedicalfoundation.nl>
@netlify

netlify Bot commented Aug 10, 2026

Copy link
Copy Markdown

Deploy Preview for nextflow-docs canceled.

Name Link
🔨 Latest commit 60f9958
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs/deploys/6a79cf2e19fe4500083806d3

@KasperWolsink99 KasperWolsink99 changed the title K8s: Handle node disruption as an infrastructure failure in Pod and Job mode nf-k8s: Handle node disruption as an infrastructure failure in Pod and Job mode Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

K8s: disrupted pods with condition DisruptionTarget consume the retry budget

1 participant