Skip to content

Move KubernetesPodTrigger pod cleanup from cleanup() to on_kill()#65741

Merged
amoghrajesh merged 5 commits intoapache:mainfrom
raushanprabhakar1:k8s-on-kill
Apr 29, 2026
Merged

Move KubernetesPodTrigger pod cleanup from cleanup() to on_kill()#65741
amoghrajesh merged 5 commits intoapache:mainfrom
raushanprabhakar1:k8s-on-kill

Conversation

@raushanprabhakar1
Copy link
Copy Markdown
Contributor

KubernetesPodTrigger now cancels external work only through BaseTrigger.on_kill() instead of the previous cleanup() path that used safe_to_cancel() to distinguish user kills from triggerer restarts. Pod deletion on user-initiated kill is unchanged in intent: it still respects _fired_event, on_kill_action, and termination_grace_period; triggerer shutdown or redistribution no longer goes through pod-deletion logic in this trigger.

Unit tests were updated to assert on_kill behavior instead of cleanup / safe_to_cancel.

related: #65733


Was generative AI tooling used to co-author this PR?
  • Yes — Cursor (GPT-based agent)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented Apr 23, 2026

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

Copy link
Copy Markdown
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

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

Sorry, need to request changes on this. This PR deletes too much.

Unfortunaltely is it not (yet) time to remove all Airflow 2.x support. The K8s provider package is still and needs still to be suoported with Airflow 2.11.x. Please revert the removal.

And yes this adds a bot of complexity but: The new on_kill() will only be available for Airflow 3.3.0++
This means the existing logic also needs to stay for all Airflow <3.3.0.

@raushanprabhakar1
Copy link
Copy Markdown
Contributor Author

Hi @jscheffl , Thanks for the feedback, i have addressed your valuable feedback, please do review.

Comment thread providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/triggers/pod.py Outdated
Comment thread providers/cncf/kubernetes/tests/unit/cncf/kubernetes/triggers/test_pod.py Outdated
@jscheffl jscheffl dismissed their stale review April 24, 2026 20:25

Will do a proper review after comments, no blocker atm

@jscheffl jscheffl requested a review from Copilot April 24, 2026 20:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates KubernetesPodTrigger to perform pod deletion on user-initiated cancellation via BaseTrigger.on_kill() (Airflow 3.3+), and avoids deleting pods during triggerer restarts/redistribution by making cleanup() a no-op on 3.3+.

Changes:

  • Add KubernetesPodTrigger.on_kill() to delete pods on user kills (guarded by AIRFLOW_V_3_3_PLUS).
  • Update cleanup() to skip pod deletion on Airflow 3.3+ while keeping the legacy safe_to_cancel() behavior for older Airflow versions.
  • Update unit tests to assert on_kill() behavior (and legacy cleanup() behavior for Airflow < 3.3).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/triggers/pod.py Adds on_kill() and gates pod deletion away from cleanup() on Airflow 3.3+ to prevent restart-triggered deletion.
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/version_compat.py Introduces AIRFLOW_V_3_3_PLUS for provider-side feature gating.
providers/cncf/kubernetes/tests/unit/cncf/kubernetes/triggers/test_pod.py Migrates/extends tests to validate on_kill() on 3.3+ and legacy cleanup() behavior on < 3.3.

Comment thread providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/triggers/pod.py Outdated
@potiuk
Copy link
Copy Markdown
Member

potiuk commented Apr 27, 2026

@raushanprabhakar1 — There are 2 unresolved review threads on this PR from @jscheffl. Could you either push a fix or reply in each thread explaining why the feedback doesn't apply? Once you believe the feedback is addressed, mark the thread as resolved so the reviewer isn't re-pinged needlessly. Thanks!


Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you.

…essts to pytests pytest.mark.skipif with AIRFLOW_V_3_3_PLUS
@eladkal eladkal requested a review from amoghrajesh April 27, 2026 05:31
Copy link
Copy Markdown
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

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

Looks good for me. Second pair of eyes would be good.

@raushanprabhakar1 please run prek run -a ruff and commit changes to fix fails in static checks.

@raushanprabhakar1
Copy link
Copy Markdown
Contributor Author

Hi @jscheffl , fixed the lint issues. Thanks

@amoghrajesh
Copy link
Copy Markdown
Contributor

I will take a look too

Copy link
Copy Markdown
Contributor

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

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

Just one comment or LGTM

@amoghrajesh amoghrajesh merged commit 6dec3c8 into apache:main Apr 29, 2026
111 checks passed
@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented Apr 29, 2026

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

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

Labels

area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants