uranusjr commented on code in PR #68048:
URL: https://github.com/apache/airflow/pull/68048#discussion_r4639076956


##########
providers/apache/spark/src/airflow/providers/apache/spark/hooks/spark_submit.py:
##########
@@ -1301,7 +1308,56 @@ def _poll_k8s_driver_via_api(self) -> str | None:
                         ) from e
                     time.sleep(poll_interval)
                     continue
-
+                driver_container = None
+
+                for container in pod.spec.containers:
+                    if kubernetes_driver_container_name:
+                        if kubernetes_driver_container_name.lower() == 
container.name.lower():
+                            driver_container = container
+                            break
+                        continue
+                    if "driver" in container.name.lower():
+                        driver_container = container
+                        break
+                    if "spark" in container.name.lower():
+                        driver_container = container
+                    if len(pod.spec.containers) == 1:
+                        driver_container = container
+                if kubernetes_driver_container_name and not driver_container:
+                    with contextlib.suppress(Exception):
+                        self._delete_driver_pod()
+                    raise ValueError(
+                        f"The driver container name provided does not match 
any of the containers in pod "
+                        f"{kubernetes_driver_pod_name}. Deleted the driver 
pod; check "
+                        f"kubernetes_driver_container_name for a typo."
+                    )
+                container_completed = False
+                if driver_container:
+                    if not driver_container_logged:
+                        self.log.info("%s has been identified as the driver 
container", driver_container.name)
+                        driver_container_logged = True
+                    for status in pod.status.container_statuses or []:
+                        if status.name == driver_container.name:
+                            if status.state and status.state.terminated:
+                                driver_exit_code = 
status.state.terminated.exit_code
+                                if driver_exit_code == 0:
+                                    container_completed = True
+                                    break
+                                raise RuntimeError(
+                                    f"Spark application {app_id} failed.\nThe 
driver container exited with a non-zero status code.\nExit code: 
{driver_exit_code}\nReason: {status.state.terminated.reason}"

Review Comment:
   Have newlines in an error is a bit weird. It’s also unusually long. Probably 
use a log + short message pointing the user to look for the log?



-- 
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