You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "vincbeck (via GitHub)" <gi...@apache.org> on 2023/06/05 20:10:59 UTC

[GitHub] [airflow] vincbeck commented on a diff in pull request #31663: Logging from all containers in KubernetesOperatorPod

vincbeck commented on code in PR #31663:
URL: https://github.com/apache/airflow/pull/31663#discussion_r1218543980


##########
airflow/providers/cncf/kubernetes/utils/pod_manager.py:
##########
@@ -120,6 +127,20 @@ def container_is_running(pod: V1Pod, container_name: str) -> bool:
     return container_status.state.running is not None
 
 
+def container_is_completed(pod: V1Pod, container_name: str) -> bool:
+    """
+    Examines V1Pod ``pod`` to determine whether ``container_name`` is running.
+    If that container is present and completed, returns True.  Returns False otherwise.
+    """
+    container_statuses = pod.status.container_statuses if pod and pod.status else None
+    if not container_statuses:
+        return False
+    container_status = next((status for status in container_statuses if status.name == container_name), None)
+    if not container_status:
+        return False
+    return container_status.state.terminated is not None
+
+

Review Comment:
   You can reuse `get_container_status` to reduce duplicated code
   
   ```suggestion
   def container_is_completed(pod: V1Pod, container_name: str) -> bool:
       """
       Examines V1Pod ``pod`` to determine whether ``container_name`` is completed.
       If that container is present and completed, returns True.  Returns False otherwise.
       """
       container_status = get_container_status(pod, container_name)
       if not container_status:
           return False
       return container_status.state.terminated is not None
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org