Skip to content

Kubernetes: allow opt-out of rescheduling on SIGTERM by setting PREFECT_FLOW_RUN_EXECUTE_SIGTERM_BEHAVIOR#19223

Merged
desertaxle merged 1 commit into
PrefectHQ:mainfrom
svatopluk-sperka:prefect-kubernetes-eviction-handling-reschedule-optout
Oct 20, 2025
Merged

Kubernetes: allow opt-out of rescheduling on SIGTERM by setting PREFECT_FLOW_RUN_EXECUTE_SIGTERM_BEHAVIOR#19223
desertaxle merged 1 commit into
PrefectHQ:mainfrom
svatopluk-sperka:prefect-kubernetes-eviction-handling-reschedule-optout

Conversation

@svatopluk-sperka
Copy link
Copy Markdown
Contributor

closes #18867.

Gist of the problem is that currently there is no way to opt-out of rescheduling a flow run on SIGTERM. Either:

  • backoffLimit > 0 in which case the K8s retries the job
  • backoffLimit = 0 in which case Prefect forces reschedule behaviour on SIGTERM via setting PREFECT_FLOW_RUN_EXECUTE_SIGTERM_BEHAVIOR=reschedule

In our case, we have workflows that we want to reschedule with human in the loop when killed due to eviction. That is because processes triggered downstream currently cannot be cancelled and multiple runs of those processes cause all sorts of problems.

The way I've tried to address the problem is by not forcing PREFECT_FLOW_RUN_EXECUTE_SIGTERM_BEHAVIOR=reschedule when that var is already set in env.

My perspective of Prefect codebase is very limited at this point so I'd appreciate any guidance on this one.

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

@github-actions github-actions Bot added the enhancement An improvement of an existing feature label Oct 20, 2025
@svatopluk-sperka svatopluk-sperka marked this pull request as ready for review October 20, 2025 12:25
@svatopluk-sperka svatopluk-sperka force-pushed the prefect-kubernetes-eviction-handling-reschedule-optout branch from 354232d to 404e097 Compare October 20, 2025 12:52
Copy link
Copy Markdown
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @svatopluk-sperka! This looks great! Thanks for taking the time to submit a fix!

@desertaxle desertaxle merged commit 22df319 into PrefectHQ:main Oct 20, 2025
15 checks passed
@svatopluk-sperka
Copy link
Copy Markdown
Contributor Author

That was smooth. Thanks @desertaxle!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow users to opt-out of SIGTERM rescheduling on Kubernetes worker

2 participants