This is an automated email from the ASF dual-hosted git repository.
jscheffl 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 4c4de51dc4d Handle missing container_statuses in
pod_manager.get_container_status (#47936)
4c4de51dc4d is described below
commit 4c4de51dc4d0e4de8035817f287e7614b77e9742
Author: Tom <[email protected]>
AuthorDate: Wed Mar 26 15:30:08 2025 -0600
Handle missing container_statuses in pod_manager.get_container_status
(#47936)
* Add failing example test
* Handle cases where container_statuses is None
---
.../src/airflow/providers/cncf/kubernetes/utils/pod_manager.py | 10 ++++++----
.../tests/unit/cncf/kubernetes/utils/test_pod_manager.py | 6 ++++++
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git
a/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/pod_manager.py
b/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/pod_manager.py
index 632f5faa57f..0d6f353310b 100644
---
a/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/pod_manager.py
+++
b/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/pod_manager.py
@@ -19,7 +19,6 @@
from __future__ import annotations
import enum
-import itertools
import json
import math
import time
@@ -119,9 +118,12 @@ class PodOperatorHookProtocol(Protocol):
def get_container_status(pod: V1Pod, container_name: str) -> V1ContainerStatus
| None:
"""Retrieve container status."""
if pod and pod.status:
- container_statuses = itertools.chain(
- pod.status.container_statuses, pod.status.init_container_statuses
- )
+ container_statuses = []
+ if pod.status.container_statuses:
+ container_statuses.extend(pod.status.container_statuses)
+ if pod.status.init_container_statuses:
+ container_statuses.extend(pod.status.init_container_statuses)
+
else:
container_statuses = None
diff --git
a/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/utils/test_pod_manager.py
b/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/utils/test_pod_manager.py
index 0ba6f0e1bcf..320470cf48a 100644
---
a/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/utils/test_pod_manager.py
+++
b/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/utils/test_pod_manager.py
@@ -888,6 +888,12 @@ def params_for_test_container_is_succeeded():
pod_mock_list.append(pytest.param(p, False, id="None remote_pod.status"))
p = RemotePodMock()
p.status = RemotePodMock()
+ p.status.container_statuses = None
+ p.status.init_container_statuses = []
+
+ pod_mock_list.append(pytest.param(p, False, id="None
remote_pod.status.container_statuses"))
+ p = RemotePodMock()
+ p.status = RemotePodMock()
p.status.container_statuses = []
p.status.init_container_statuses = []
pod_mock_list.append(pytest.param(p, False, id="empty
remote_pod.status.container_statuses"))