This is an automated email from the ASF dual-hosted git repository.
taragolis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 9a529a8d43 Fix hanging KPO on deferrable task with do_xcom_push
(#37300)
9a529a8d43 is described below
commit 9a529a8d432c2ec568a361199c643557004291bb
Author: Victor Chiapaikeo <[email protected]>
AuthorDate: Sat Feb 10 03:52:46 2024 -0500
Fix hanging KPO on deferrable task with do_xcom_push (#37300)
---
airflow/providers/cncf/kubernetes/operators/pod.py | 4 ++++
tests/providers/cncf/kubernetes/operators/test_pod.py | 9 +++++++--
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/airflow/providers/cncf/kubernetes/operators/pod.py
b/airflow/providers/cncf/kubernetes/operators/pod.py
index 1ab32a5cd7..0564afdcc7 100644
--- a/airflow/providers/cncf/kubernetes/operators/pod.py
+++ b/airflow/providers/cncf/kubernetes/operators/pod.py
@@ -683,6 +683,10 @@ class KubernetesPodOperator(BaseOperator):
message = f"{event['message']}\n{event['stack_trace']}"
else:
message = event["message"]
+ if self.do_xcom_push:
+ # In the event of base container failure, we need to kill
the xcom sidecar.
+ # We disregard xcom output and do that here
+ _ = self.extract_xcom(pod=pod)
raise AirflowException(message)
elif event["status"] == "success":
# fetch some logs when pod is executed successfully
diff --git a/tests/providers/cncf/kubernetes/operators/test_pod.py
b/tests/providers/cncf/kubernetes/operators/test_pod.py
index b896f57ee5..fa617a39fd 100644
--- a/tests/providers/cncf/kubernetes/operators/test_pod.py
+++ b/tests/providers/cncf/kubernetes/operators/test_pod.py
@@ -2049,8 +2049,13 @@ def
test_async_kpo_wait_termination_before_cleanup_on_failure(
# assert that it does not push the xcom
ti_mock.xcom_push.assert_not_called()
- # assert that the xcom are not extracted
- mock_extract_xcom.assert_not_called()
+ if do_xcom_push:
+ # assert that the xcom are not extracted if do_xcom_push is Fale
+ mock_extract_xcom.assert_called_once()
+ else:
+ # but that it is extracted when do_xcom_push is true because the
sidecare
+ # needs to be terminated
+ mock_extract_xcom.assert_not_called()
# check if it waits for the pod to complete
assert read_pod_mock.call_count == 3