KafkaOtto commented on code in PR #72511:
URL: https://github.com/apache/airflow/pull/72511#discussion_r4705718288


##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/pod_manager.py:
##########
@@ -1306,3 +1319,63 @@ def _emit_container_logs(self, logs: list[str], now: 
DateTime, container_name: s
                 else:
                     level = _parse_log_level(message_to_log)
                     self.log.log(level, "[%s] %s", container_name, 
message_to_log)
+
+    def get_init_container_names(self, pod: V1Pod) -> list[str]:
+        """
+        Return init container names from the pod spec.
+
+        :meta private:
+        """
+        return [container_spec.name for container_spec in 
pod.spec.init_containers or []]
+
+    async def fetch_requested_init_container_logs(
+        self,
+        pod: V1Pod,
+        init_containers: Iterable[str] | str | Literal[True] | None,
+        poll_interval: float = 1,
+    ) -> None:
+        """
+        Stream logs for the requested init containers, one at a time, until 
each completes.
+
+        Init containers run sequentially before the base container starts, so 
they are
+        processed in ``spec.initContainers`` order, mirroring the sync 
``PodManager``'s
+        ``fetch_requested_init_container_logs``.
+
+        :meta private:
+        """
+        all_containers = self.get_init_container_names(pod)
+        containers_to_log = reconcile_requested_log_containers(
+            self.log, init_containers, all_containers, pod.metadata.name
+        )
+        containers_to_log = sorted(containers_to_log, key=lambda cn: 
all_containers.index(cn))
+        for container_name in containers_to_log:
+            await self._await_init_container_start(pod, container_name)
+            await self._stream_init_container_logs_until_completion(pod, 
container_name, poll_interval)
+
+    async def _await_init_container_start(self, pod: V1Pod, container_name: 
str) -> None:
+        while True:
+            remote_pod = await self.read_pod(pod)
+            if (
+                remote_pod.status is not None
+                and remote_pod.status.phase != PodPhase.PENDING
+                and get_container_status(remote_pod, container_name) is not 
None
+                and not container_is_wait(remote_pod, container_name)
+            ):
+                return
+            await asyncio.sleep(1)

Review Comment:
   Thank! I added # use next version to the 
apache-airflow-providers-cncf-kubernetes line in the cncf.kubernetes extra of 
both providers/amazon/pyproject.toml and providers/google/pyproject.toml, and 
left the version numbers alone. Done in ea5f956.
   
    _await_init_container_start now returns False once the pod is Failed or 
Succeeded while the init container is still waiting. 
fetch_requested_init_container_logs then stops streaming, so the trigger falls 
through to define_pod_container_state and reports the failure as it does today. 
An init container that started before the pod finished still returns True, so 
its logs are still streamed. I added two tests: the await returns False for 
both terminal phases, and the fetch stops before streaming later init 
containers. Done in ea5f956.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to