amoghrajesh commented on code in PR #67715:
URL: https://github.com/apache/airflow/pull/67715#discussion_r3327954473
##########
providers/apache/spark/src/airflow/providers/apache/spark/hooks/spark_submit.py:
##########
@@ -802,6 +857,54 @@ def _start_driver_status_tracking(self) -> None:
f"returncode = {returncode}"
)
+ def _poll_k8s_driver_via_api(self) -> None:
+ """Poll the K8s driver pod phase until it reaches a terminal state."""
+ pod_name = self._kubernetes_driver_pod
+ namespace = self._connection["namespace"]
+ app_id = self._kubernetes_application_id or pod_name
+
+ if not pod_name:
+ raise ValueError("K8s driver pod name not set; cannot poll
status.")
+
+ client = kube_client.get_kube_client(in_cluster=False)
+ poll_interval = max(self._status_poll_interval, 20)
+ # similar to `missed_job_status_reports` tolerance in
`_start_driver_status_tracking`:
+ # tolerate transient `Unknown` phases (node temporarily unreachable)
before giving up.
+ consecutive_unknown = 0
+ max_consecutive_unknown = 3
+
+ while True:
+ pod = client.read_namespaced_pod(pod_name, namespace)
+ phase = pod.status.phase or "Initializing"
+ self.log.info("Application status for %s (phase: %s)", app_id,
phase)
+ if phase == "Succeeded":
+ break
+ if phase == "Failed":
+ container_state = ""
+ if pod.status.container_statuses:
+ cs = pod.status.container_statuses[0]
+ if cs.state and cs.state.terminated:
+ container_state = (
+ f" exit_code={cs.state.terminated.exit_code}
reason={cs.state.terminated.reason}"
+ )
+ raise RuntimeError(f"Spark application {app_id} failed
(phase=Failed{container_state})")
Review Comment:
I moved `_run_post_submit_commands()` into a finally block wrapping the
entire poll loop, so it runs on all terminal exits: Succeeded, Failed, repeated
Unknown, repeated ApiException, and any unexpected raise.
Pod deletion still only happens on the success path (after the break),
matching the existing design of leaving failed pods alive for log inspection.
--
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]