o-nikolas commented on code in PR #28161:
URL: https://github.com/apache/airflow/pull/28161#discussion_r1095134144
##########
airflow/executors/kubernetes_executor.py:
##########
@@ -773,6 +775,57 @@ def _change_state(self, key: TaskInstanceKey, state: str |
None, pod_id: str, na
# do this once, so only do it when we remove the task from running
self.event_buffer[key] = state, None
+ @staticmethod
+ def _get_pod_namespace(ti: TaskInstance):
+ pod_override = ti.executor_config.get("pod_override")
+ namespace = None
+ with suppress(Exception):
+ namespace = pod_override.metadata.namespace
+ return namespace or conf.get("kubernetes_executor", "namespace",
fallback="default")
+
+ def get_task_log(self, ti: TaskInstance, log: str = "") -> str |
tuple[str, dict[str, bool]]:
+
+ try:
+ from airflow.kubernetes.pod_generator import PodGenerator
+
+ client = get_kube_client()
+
+ log += f"*** Trying to get logs (last 100 lines) from worker pod
{ti.hostname} ***\n\n"
+ selector = PodGenerator.build_selector_for_k8s_executor_pod(
+ dag_id=ti.dag_id,
+ task_id=ti.task_id,
+ try_number=ti.try_number,
+ map_index=ti.map_index,
+ run_id=ti.run_id,
+ airflow_worker=ti.queued_by_job_id,
+ )
+ namespace = self._get_pod_namespace(ti)
+ pod_list = client.list_namespaced_pod(
+ namespace=namespace,
+ label_selector=selector,
+ ).items
+ if not pod_list:
+ raise RuntimeError("Cannot find pod for ti %s", ti)
+ elif len(pod_list) > 1:
+ raise RuntimeError("Found multiple pods for ti %s: %s", ti,
pod_list)
+ res = client.read_namespaced_pod_log(
+ name=pod_list[0].metadata.name,
Review Comment:
This is not code that is new to this PR. It was just moved to a different
location. If you see the `airflow/utils/log/file_task_handler.py` module, this
code existed there before these changes.
--
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]