Repository navigation
feat: add zombie KPO pod cleanup to KubernetesExecutor - #67030
gingeekrishna wants to merge 5 commits into
Conversation
|
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
|
|
This PR lags any description. Can you please add any intention? |
|
Note: Before merging main hoping that simple static checks fix themself: Please check contribution docs how to run |
|
@gingeekrishna A few things need addressing before review — see our Pull Request quality criteria.
No rush. 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. Drafted-by: Claude Code (Opus 4.7); reviewed by @potiuk before posting |
|
@gingeekrishna Converting to draft — this PR does not yet meet our Pull Request quality criteria.
See the linked criteria for how to fix each item, then mark the PR "Ready for review". This is not a rejection — just an invitation to bring the PR up to standard. No rush. 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. |
8bd6398 to
42fc62c
Compare
Apologies for that, I just updated the right description |
jscheffl
left a comment
There was a problem hiding this comment.
I am not a K8sExecutor user so my experience is a bit limited. Would ask some other maintainer for opinion.
Thank you @jscheffl! |
|
Please fix the tests |
bd48312 to
357a17b
Compare
|
Hi @eladkal — fixed! The test failure had two root causes in
Also rebased onto |
Hi @eladkal is that my PR good to merge now? |
Signed-off-by: gingeekrishna <[email protected]>
… only Scoping the `task_instance` query by `dag_id.in_(pod_dag_ids)` bounds the result set to DAGs that actually have live KPO pods rather than scanning all non-terminal KPO TIs across the entire table. Signed-off-by: Radhakrishnan Pachyappan <[email protected]>
…d age guard Two bugs in _cleanup_zombie_kpo_pods caused spurious deletions: 1. No phase filter: the pod list included Pending/Completed pods and newly submitted pods, not just Running ones as the feature intends. Added field_selector="status.phase=Running" to _list_pods call. 2. No minimum-age guard: a pod created seconds ago with no matching TaskInstance yet (submit→schedule gap, or system-test pods) was immediately treated as a zombie. Now pods younger than zombie_kpo_pod_cleanup_interval seconds are skipped. Fixes the TestKubernetesPodOperatorSystem::test_full_pod_spec failure where the CI KubernetesExecutor was force-deleting the test pod because dag_id="dag" had no matching TaskInstance in the CI database. Also adds test_young_pod_skipped_by_age_guard and sets a realistic creation_timestamp in _make_pod so all zombie cleanup tests exercise the age guard correctly.
83e78e5 to
4a5e7b2
Compare
- Run ruff format on kubernetes_executor.py (dict arg expansion) - Remove datetime.timezone import that collided with airflow.sdk.timezone import later in the file, causing MyPy incompatible-import error; replace datetime.now(timezone.utc) with timezone.utcnow() to match existing test code style Signed-off-by: RadhaKrishnan Rajendran <[email protected]> Signed-off-by: gingeekrishna <[email protected]>
Resolve import conflict in kubernetes_executor.py: keep timezone (added by this branch) alongside dataclass (added by upstream).
|
@gingeekrishna This PR has been converted to draft because it does not yet meet our Pull Request quality criteria. Issues found:
What to do next:
Converting a PR to draft is not a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates. If you have questions, feel free to ask on the Airflow Slack. 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. |
Summary
Closes #58968
When a
KubernetesPodOperator(KPO) task reaches a terminal state, the scheduler signals its pod to terminate. However, sidecar containers that ignoreSIGTERM(such as the xcom sidecar or custom log-aggregation sidecars) can keep the pod inRunningstate indefinitely, leaking resources and confusing monitoring dashboards.This PR adds a periodic zombie-pod cleanup to
KubernetesExecutorthat:Runningin Kubernetes but whoseTaskInstancehas already reached a terminal state (zombie pods)try_number< active TItry_number)grace_period_seconds=0to bypass stuck sidecar containersTwo new
[kubernetes_executor]config options gate the feature:clean_zombie_kpo_pods(boolean, defaultTrue) — enable/disable the cleanup scanzombie_kpo_pod_cleanup_interval(integer seconds, default300) — how often to scanEksPodOperatorandGKEStartPodOperatorare intentionally excluded: their pods run in external clusters where thiskube_clienthas no authority.Changes
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py— add_cleanup_zombie_kpo_pods()method andsync()integrationproviders/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/kube_config.py— read the two new config optionsproviders/cncf/kubernetes/provider.yaml— register the two new config optionsTest plan
TestCleanupZombieKpoPods::test_no_pods_does_nothingTestCleanupZombieKpoPods::test_zombie_pod_no_matching_ti_is_force_deletedTestCleanupZombieKpoPods::test_healthy_pod_with_matching_active_ti_not_deletedTestCleanupZombieKpoPods::test_stale_retry_pod_is_force_deletedTestCleanupZombieKpoPods::test_current_try_pod_is_not_deletedTestCleanupZombieKpoPods::test_pod_missing_required_labels_is_skippedTestCleanupZombieKpoPods::test_404_on_delete_is_silently_ignoredTestCleanupZombieKpoPods::test_non_404_api_error_is_logged_not_raisedTestCleanupZombieKpoPods::test_only_zombie_pods_deleted_healthy_pods_untouchedTestCleanupZombieKpoPods::test_mapped_task_pod_matched_by_map_indexTestCleanupZombieKpoPods::test_force_delete_uses_grace_period_zeroTestCleanupZombieKpoPods::test_sync_calls_cleanup_when_config_enabledTestCleanupZombieKpoPods::test_sync_skips_cleanup_when_config_disabledGen-AI disclosure
Important
🛠️ Maintainer triage note for @gingeekrishna · by
@potiuk· 2026-07-28 17:13 UTCThis draft PR has been inactive since the last triage note, with no response from the author. Closing to keep the queue clean:
mainbranch first.The ball is in your court — you've been assigned to this PR. Reopen or open a fresh PR once addressed — no rush.
See the Pull Request quality criteria for how to fix each item. There is no rush.
Automated triage — may be imperfect; a maintainer takes the next look. We use this two-stage triage process so maintainers' limited time goes to the conversation with you.