You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zwangsheng (via GitHub)" <gi...@apache.org> on 2023/03/29 06:29:39 UTC

[GitHub] [spark] zwangsheng commented on a diff in pull request #40118: [SPARK-26365][K8S] In kuberentes cluster mode, spark submit should pass driver exit code

zwangsheng commented on code in PR #40118:
URL: https://github.com/apache/spark/pull/40118#discussion_r1151449690


##########
resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/submit/LoggingPodStatusWatcher.scala:
##########
@@ -95,6 +100,27 @@ private[k8s] class LoggingPodStatusWatcherImpl(conf: KubernetesDriverConf)
     this.notifyAll()
   }
 
+  override def getDriverExitCode(): Option[Int] = synchronized {
+    if (hasCompleted()) {
+      val driverContainerName = conf.get(KUBERNETES_DRIVER_PODTEMPLATE_CONTAINER_NAME)
+        .getOrElse(DEFAULT_DRIVER_CONTAINER_NAME)
+      pod.foreach { p =>
+        try {
+          return Some(p.getStatus.getContainerStatuses.asScala
+            .filter(driverContainerName == _.getName)
+            .head.getState.getTerminated.getExitCode)
+        } catch {
+          case _: NullPointerException =>
+            logError("Fail to find completed driver container exit code")
+            return None
+        }
+      }
+      throw new SparkException("Fail to get driver exit code, when the application completed")
+    } else {
+      throw new SparkException("Call getDriverExitCode() when the application has not completed")

Review Comment:
   Thank you for looking at the code in detail.
   
   Four scenarios are considered here:
   * Case 1: which normal won't be triggered under normal case, placed here to prevent the function from being misused.
   * Case 2: Successful case
   * Case 3:  Only trigger if the app has completed but pod without exit code
   * Case 4: due to we didn't get the specified driver container(Neither `KUBERNETES_DRIVER_PODTEMPLATE_CONTAINER_NAME` nor `DEFAULT_DRIVER_CONTAINER_NAME `)
   > PS. In `KubernetesUtils.loadPodFromTemplate` function logic, we read the first container from user's template file, not hardwired to `KUBERNETES_DRIVER_PODTEMPLATE_CONTAINER_NAME` or `DEFAULT_DRIVER_CONTAINER_NAME`.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org