Fix KubernetesPodTrigger pod terminal state handling#66650
Merged
jscheffl merged 3 commits intoMay 10, 2026
Conversation
jscheffl
reviewed
May 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Kubernetes deferrable pod trigger/operator flow to stop polling based on pod-level terminal phases (Succeeded/Failed) instead of relying solely on the base container state, addressing cases like init-container failure where the pod is already terminal but the base container never transitions.
Changes:
- Add
define_pod_state()inKubernetesPodTriggerto treat podSucceeded/Failedas terminal outcomes, falling back to base-container state otherwise. - Switch trigger polling and operator pre-deferral terminal-state checks to use
define_pod_state(). - Update/extend unit tests to patch the new method and add coverage for the init-container failure scenario.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/triggers/pod.py |
Introduces pod-phase terminal detection and uses it in trigger polling. |
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py |
Uses pod-level terminal detection to skip deferral when already terminal. |
providers/cncf/kubernetes/tests/unit/cncf/kubernetes/triggers/test_pod.py |
Updates mocks to define_pod_state() and adds a regression test for pod failed while base container waits. |
providers/cncf/kubernetes/tests/unit/cncf/kubernetes/operators/test_pod.py |
Updates operator async test to patch define_pod_state() instead of define_container_state(). |
Comments suppressed due to low confidence (1)
providers/cncf/kubernetes/tests/unit/cncf/kubernetes/triggers/test_pod.py:336
test_running_log_intervalpatchesdefine_pod_state, but the injected mock argument is still nameddefine_container_state. Renaming the parameter (and any related variable names) to match the patched symbol would avoid confusion and make the test intent clearer.
@mock.patch("airflow.providers.cncf.kubernetes.triggers.pod.datetime")
@mock.patch(f"{TRIGGER_PATH}.define_pod_state")
@mock.patch(f"{TRIGGER_PATH}._wait_for_pod_start")
@mock.patch(
"airflow.providers.cncf.kubernetes.triggers.pod.AsyncPodManager.fetch_container_logs_before_current_sec"
)
@mock.patch("airflow.providers.cncf.kubernetes.triggers.pod.AsyncKubernetesHook.get_pod")
async def test_running_log_interval(
self,
mock_get_pod,
mock_fetch_container_logs_before_current_sec,
mock_wait_pod,
define_container_state,
mock_datetime,
jscheffl
approved these changes
May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
KubernetesPodTriggerFailedorSucceededTests
uv run --project providers/cncf/kubernetes pytest providers/cncf/kubernetes/tests/unit/cncf/kubernetes/triggers/test_pod.py -quv run --project providers/cncf/kubernetes pytest --with-db-init providers/cncf/kubernetes/tests/unit/cncf/kubernetes/operators/test_pod.py::TestKubernetesPodOperatorAsync::test_async_create_pod_should_execute_successfully -qCloses #66624