pan3793 commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395810798
##########
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala:
##########
@@ -295,16 +314,64 @@ object KubernetesApplicationOperation extends Logging {
def toLabel(tag: String): String = s"label: $LABEL_KYUUBI_UNIQUE_KEY=$tag"
- def toApplicationState(state: String): ApplicationState = state match {
- //
https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/core/types.go#L2396
- // https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/
+ def toApplicationState(
+ pod: Pod,
+ appStateFromContainer: Boolean,
+ appStateContainer: String): ApplicationState = {
+ toApplicationStateAndError(pod, appStateFromContainer,
appStateContainer)._1
+ }
+
+ def toApplicationStateAndError(
+ pod: Pod,
+ appStateFromContainer: Boolean,
+ appStateContainer: String): (ApplicationState, Option[String]) = {
+ val containerStateToBuildAppState = if (appStateFromContainer) {
+ pod.getStatus.getContainerStatuses.asScala.find(_.getState ==
appStateContainer).map(
+ _.getState)
+ } else {
+ None
+ }
+ val applicationState =
containerStateToBuildAppState.map(containerStateToApplicationState)
+ .getOrElse(podStateToApplicationState(pod.getStatus.getPhase))
+ val applicationError =
containerStateToBuildAppState.map(containerStateToApplicationError)
+ .getOrElse(Option(pod.getStatus.getReason))
+ applicationState -> applicationError
+ }
+
+ def containerStateToApplicationState(containerState: ContainerState):
ApplicationState = {
+ //
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-states
+ if (containerState.getWaiting != null) {
+ PENDING
+ } else if (containerState.getRunning != null) {
+ RUNNING
+ } else {
+ Option(containerState.getTerminated) match {
+ case Some(terminated) =>
+ if (terminated.getExitCode == 0) {
+ FINISHED
+ } else {
+ FAILED
+ }
+ case None => UNKNOWN
+ }
+ }
+ }
+
+ def containerStateToApplicationError(containerState: ContainerState):
Option[String] = {
+ //
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-states
+ Option(containerState.getWaiting).map(_.getReason)
+ .orElse(Option(containerState.getTerminated).map(_.getReason))
+ }
+
+ def podStateToApplicationState(podState: String): ApplicationState =
podState match {
+ //
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase
case "Pending" => PENDING
case "Running" => RUNNING
case "Succeeded" => FINISHED
case "Failed" | "Error" => FAILED
case "Unknown" => UNKNOWN
case _ =>
- warn(s"The kubernetes driver pod state: $state is not supported, " +
+ warn(s"The kubernetes driver pod state: $podState is not supported, " +
Review Comment:
```suggestion
warn(s"The Spark driver pod state: $podState is not supported, " +
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]