snjypl commented on code in PR #28161:
URL: https://github.com/apache/airflow/pull/28161#discussion_r1081083607
##########
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)
Review Comment:
@eladkal i think, #29025 is more about the error that we log around these
part.
https://github.com/apache/airflow/blob/1e385ac36cf84cca92cc18bb528e381904b44783/airflow/executors/kubernetes_executor.py#L690-L714
. these logs i believe are part of the scheduler logs.
--
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]