You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by "turboFei (via GitHub)" <gi...@apache.org> on 2023/11/16 06:24:47 UTC

[PR] [KUBERNETES] Support to build application state and error from pod container [kyuubi]

turboFei opened a new pull request, #5711:
URL: https://github.com/apache/kyuubi/pull/5711

   # :mag: Description
   ## Issue References đź”—
   <!-- Append the issue number after #. If there is no issue for you to link create one or -->
   <!-- If there are no issues to link, please provide details here. -->
   
   This pull request fixes #
   
   ## Describe Your Solution đź”§
   
   Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
   
   
   ## Types of changes :bookmark:
   <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
   - [ ] Bugfix (non-breaking change which fixes an issue)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Breaking change (fix or feature that would cause existing functionality to change)
   
   ## Test Plan đź§Ş
   
   #### Behavior Without This Pull Request :coffin:
   
   
   #### Behavior With This Pull Request :tada:
   
   
   #### Related Unit Tests
   
   
   ---
   
   # Checklists
   ## 📝 Author Self Checklist
   <!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
   <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
   - [ ] My code follows the [style guidelines](https://kyuubi.readthedocs.io/en/master/contributing/code/style.html) of this project
   - [ ] I have performed a self-review
   - [ ] I have commented my code, particularly in hard-to-understand areas
   - [ ] I have made corresponding changes to the documentation
   - [ ] My changes generate no new warnings
   - [ ] I have added tests that prove my fix is effective or that my feature works
   - [ ] New and existing unit tests pass locally with my changes
   - [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)
   
   ## 📝 Committer Pre-Merge Checklist
   
   - [ ] Pull request title is okay.
   - [ ] No license issues.
   - [ ] Milestone correctly set?
   - [ ] Test coverage is ok
   - [ ] Assignees are selected.
   - [ ] Minimum number of approvals
   - [ ] No changes are requested
   
   
   **Be nice. Be informative.**
   


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [K8S] Support to build application state and error from pod container [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#issuecomment-1814332922

   Or I can even ignore the user specified `spark.kubernetes.driver.podTemplateContainerName` in kyuubi server side.
   
   With kyuubi conf:
   `kyuubi.session.conf.ignore.list` and `kyuubi.batch.conf.ignore.list`.


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [KUBERNETES] Support to build application state and error from pod container [kyuubi]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395280666


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -1231,6 +1231,22 @@ object KyuubiConf {
       .checkValue(_ > 0, "must be positive number")
       .createWithDefault(Duration.ofMinutes(5).toMillis)
 
+  val KUBERNETES_APPLICATION_STATE_FROM_CONTAINER: ConfigEntry[Boolean] =
+    buildConf("kyuubi.kubernetes.application.state.fromContainer")
+      .doc("If set to true then the application state will be retrieved from the container " +
+        "instead of the pod.")
+      .version("1.8.1")
+      .booleanConf
+      .createWithDefault(false)
+
+  val KUBERNETES_APPLICATION_STATE_CONTAINERS: ConfigEntry[Set[String]] =
+    buildConf("kyuubi.kubernetes.application.state.containers")
+      .doc("A comma-separated list of container names to retrieve the application state from.")
+      .version("1.8.1")
+      .stringConf
+      .toSet()

Review Comment:
   why should we care about a set of containers' status? and how can we determine the final application status from each container's status? e.g. use OR or AND strategy?



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [K8S] Support to build application state and error from pod container [kyuubi]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395748708


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -1239,6 +1239,21 @@ object KyuubiConf {
       .booleanConf
       .createWithDefault(false)
 
+  val KUBERNETES_APPLICATION_STATE_FROM_CONTAINER: ConfigEntry[Boolean] =
+    buildConf("kyuubi.kubernetes.application.state.fromContainer")

Review Comment:
   actually, there are other potential ways for app state judgement, e.g. service, or CRD object, so I would suggest using an emum instead of bool for it.
   ```
   kyuubi.kubernetes.application.state.from=[pod|contianer]
   ```



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [K8S] Support to build application state and error from pod container [kyuubi]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#issuecomment-1814535815

   > If no container matched with the server level kyuubi.kubernetes.application.state.container, it will fallback to use the pod state to build application state.
   
   such behavior should be documented clearly.


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [KUBERNETES] Support to build application state and error from pod container [kyuubi]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395247098


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -1231,6 +1231,21 @@ object KyuubiConf {
       .checkValue(_ > 0, "must be positive number")
       .createWithDefault(Duration.ofMinutes(5).toMillis)
 
+  val KUBERNETES_APPLICATION_STATE_FROM_CONTAINER: ConfigEntry[Boolean] =
+    buildConf("kyuubi.kubernetes.application.state.fromContainer")
+      .doc("If set to true then the application state will be retrieved from the container " +
+        "instead of the pod.")
+      .version("1.8.1")
+      .booleanConf
+      .createWithDefault(false)
+
+  val KUBERNETES_APPLICATION_STATE_CONTAINER: OptionalConfigEntry[String] =
+    buildConf("kyuubi.kubernetes.application.state.container")

Review Comment:
   I couldn’t recall the details well. how can we configure the container name? through pod template? does it have a default 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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [K8S] Support to build application state and error from pod container [kyuubi]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#issuecomment-1814499535

   ## [Codecov](https://app.codecov.io/gh/apache/kyuubi/pull/5711?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: `52 lines` in your changes are missing coverage. Please review.
   > Comparison is base [(`88fae49`)](https://app.codecov.io/gh/apache/kyuubi/commit/88fae49d7f28884d7d022d329b789e7cb728132c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 61.40% compared to head [(`bca19be`)](https://app.codecov.io/gh/apache/kyuubi/pull/5711?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 61.34%.
   
   | [Files](https://app.codecov.io/gh/apache/kyuubi/pull/5711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...kyuubi/engine/KubernetesApplicationOperation.scala](https://app.codecov.io/gh/apache/kyuubi/pull/5711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-a3l1dWJpLXNlcnZlci9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9lbmdpbmUvS3ViZXJuZXRlc0FwcGxpY2F0aW9uT3BlcmF0aW9uLnNjYWxh) | 0.00% | [48 Missing :warning: ](https://app.codecov.io/gh/apache/kyuubi/pull/5711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...uubi/engine/KubernetesApplicationAuditLogger.scala](https://app.codecov.io/gh/apache/kyuubi/pull/5711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-a3l1dWJpLXNlcnZlci9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9lbmdpbmUvS3ViZXJuZXRlc0FwcGxpY2F0aW9uQXVkaXRMb2dnZXIuc2NhbGE=) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/kyuubi/pull/5711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #5711      +/-   ##
   ============================================
   - Coverage     61.40%   61.34%   -0.07%     
     Complexity       23       23              
   ============================================
     Files           607      607              
     Lines         35755    35807      +52     
     Branches       4900     4909       +9     
   ============================================
   + Hits          21957    21965       +8     
   - Misses        11413    11458      +45     
   + Partials       2385     2384       -1     
   ```
   
   
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/kyuubi/pull/5711?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [KUBERNETES] Support to build application state and error from pod container [kyuubi]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395247098


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -1231,6 +1231,21 @@ object KyuubiConf {
       .checkValue(_ > 0, "must be positive number")
       .createWithDefault(Duration.ofMinutes(5).toMillis)
 
+  val KUBERNETES_APPLICATION_STATE_FROM_CONTAINER: ConfigEntry[Boolean] =
+    buildConf("kyuubi.kubernetes.application.state.fromContainer")
+      .doc("If set to true then the application state will be retrieved from the container " +
+        "instead of the pod.")
+      .version("1.8.1")
+      .booleanConf
+      .createWithDefault(false)
+
+  val KUBERNETES_APPLICATION_STATE_CONTAINER: OptionalConfigEntry[String] =
+    buildConf("kyuubi.kubernetes.application.state.container")

Review Comment:
   I couldn’t recall the details well. how can we configure the container name? does it have a default name? throw pod template?



##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -1231,6 +1231,21 @@ object KyuubiConf {
       .checkValue(_ > 0, "must be positive number")
       .createWithDefault(Duration.ofMinutes(5).toMillis)
 
+  val KUBERNETES_APPLICATION_STATE_FROM_CONTAINER: ConfigEntry[Boolean] =
+    buildConf("kyuubi.kubernetes.application.state.fromContainer")
+      .doc("If set to true then the application state will be retrieved from the container " +
+        "instead of the pod.")
+      .version("1.8.1")
+      .booleanConf
+      .createWithDefault(false)
+
+  val KUBERNETES_APPLICATION_STATE_CONTAINER: OptionalConfigEntry[String] =
+    buildConf("kyuubi.kubernetes.application.state.container")

Review Comment:
   I couldn’t recall the details well. how can we configure the container name? does it have a default name? throw pod template?



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [K8S] Support to build application state and error from pod container [kyuubi]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395791217


##########
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
+      }
+    }

Review Comment:
   ```suggestion
       } else if (containerState.getTerminated == null) {
         UNKNOWN
       } else if (containerState.getTerminated.getExitCode == 0) {
         FINISHED
       } else {
         FAILED
       }
   ```



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [K8S] Support to build application state and error from pod container [kyuubi]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395807706


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

Review Comment:
   avoid breaking line after `func(\n lambda ...`
   
   ```suggestion
         pod.getStatus.getContainerStatuses.asScala
           .find(_.getState == appStateContainer).map(_.getState)
   ```



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [KUBERNETES] Support to build application state and error from pod container [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395296389


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -1231,6 +1231,22 @@ object KyuubiConf {
       .checkValue(_ > 0, "must be positive number")
       .createWithDefault(Duration.ofMinutes(5).toMillis)
 
+  val KUBERNETES_APPLICATION_STATE_FROM_CONTAINER: ConfigEntry[Boolean] =
+    buildConf("kyuubi.kubernetes.application.state.fromContainer")
+      .doc("If set to true then the application state will be retrieved from the container " +
+        "instead of the pod.")
+      .version("1.8.1")
+      .booleanConf
+      .createWithDefault(false)
+
+  val KUBERNETES_APPLICATION_STATE_CONTAINERS: ConfigEntry[Set[String]] =
+    buildConf("kyuubi.kubernetes.application.state.containers")
+      .doc("A comma-separated list of container names to retrieve the application state from.")
+      .version("1.8.1")
+      .stringConf
+      .toSet()
+      .createWithDefault(Set.empty)

Review Comment:
   SGTM



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [K8S] Support to build application state and error from pod container [kyuubi]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395771457


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -1239,6 +1239,21 @@ object KyuubiConf {
       .booleanConf
       .createWithDefault(false)
 
+  val KUBERNETES_APPLICATION_STATE_FROM_CONTAINER: ConfigEntry[Boolean] =
+    buildConf("kyuubi.kubernetes.application.state.fromContainer")
+      .doc("If set to true then the application state will be retrieved from the container " +
+        "instead of the pod.")
+      .version("1.8.1")
+      .booleanConf
+      .createWithDefault(false)
+
+  val KUBERNETES_APPLICATION_STATE_CONTAINER: ConfigEntry[String] =
+    buildConf("kyuubi.kubernetes.application.state.container")
+      .doc("The container names to retrieve the application state from.")

Review Comment:
   there are bunches of tricks under the hood, users may not get enough information from such a brief description.
   
   e.g. in which conditions, this configuration takes effect? how to set the value(e.g. it must be same as xxx)?



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [KUBERNETES] Support to build application state and error from pod container [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395311640


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -1231,6 +1231,22 @@ object KyuubiConf {
       .checkValue(_ > 0, "must be positive number")
       .createWithDefault(Duration.ofMinutes(5).toMillis)
 
+  val KUBERNETES_APPLICATION_STATE_FROM_CONTAINER: ConfigEntry[Boolean] =
+    buildConf("kyuubi.kubernetes.application.state.fromContainer")
+      .doc("If set to true then the application state will be retrieved from the container " +
+        "instead of the pod.")
+      .version("1.8.1")
+      .booleanConf
+      .createWithDefault(false)
+
+  val KUBERNETES_APPLICATION_STATE_CONTAINERS: ConfigEntry[Set[String]] =
+    buildConf("kyuubi.kubernetes.application.state.containers")
+      .doc("A comma-separated list of container names to retrieve the application state from.")
+      .version("1.8.1")
+      .stringConf
+      .toSet()

Review Comment:
   changed to use single 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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [KUBERNETES] Support to build application state and error from pod container [kyuubi]

Posted by "zwangsheng (via GitHub)" <gi...@apache.org>.
zwangsheng commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395277807


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -1231,6 +1231,22 @@ object KyuubiConf {
       .checkValue(_ > 0, "must be positive number")
       .createWithDefault(Duration.ofMinutes(5).toMillis)
 
+  val KUBERNETES_APPLICATION_STATE_FROM_CONTAINER: ConfigEntry[Boolean] =
+    buildConf("kyuubi.kubernetes.application.state.fromContainer")
+      .doc("If set to true then the application state will be retrieved from the container " +
+        "instead of the pod.")
+      .version("1.8.1")
+      .booleanConf
+      .createWithDefault(false)
+
+  val KUBERNETES_APPLICATION_STATE_CONTAINERS: ConfigEntry[Set[String]] =
+    buildConf("kyuubi.kubernetes.application.state.containers")
+      .doc("A comma-separated list of container names to retrieve the application state from.")
+      .version("1.8.1")
+      .stringConf
+      .toSet()
+      .createWithDefault(Set.empty)

Review Comment:
   how about set default to `spark-kubernetes-driver`(default spark 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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [K8S] Support to build application state and error from pod container [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei closed pull request #5711: [K8S] Support to build application state and error from pod container
URL: https://github.com/apache/kyuubi/pull/5711


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [K8S] Support to build application state and error from pod container [kyuubi]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [KUBERNETES] Support to build application state and error from pod container [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395297170


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala:
##########
@@ -1231,6 +1231,21 @@ object KyuubiConf {
       .checkValue(_ > 0, "must be positive number")
       .createWithDefault(Duration.ofMinutes(5).toMillis)
 
+  val KUBERNETES_APPLICATION_STATE_FROM_CONTAINER: ConfigEntry[Boolean] =
+    buildConf("kyuubi.kubernetes.application.state.fromContainer")
+      .doc("If set to true then the application state will be retrieved from the container " +
+        "instead of the pod.")
+      .version("1.8.1")
+      .booleanConf
+      .createWithDefault(false)
+
+  val KUBERNETES_APPLICATION_STATE_CONTAINER: OptionalConfigEntry[String] =
+    buildConf("kyuubi.kubernetes.application.state.container")

Review Comment:
   will give a default value `spark-kubernetes-driver`



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [K8S] Support to build application state and error from pod container [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#issuecomment-1814329921

   > But have one more question about: we set this kyuubi.kubernetes.application.state.fromContainer  as server level conf, what will happen when user submit spark app with custom container name(by setting pod template and spark.kubernetes.driver.podTemplateContainerName)?
   
   If not container matched with the server level `kyuubi.kubernetes.application.state.container`, it will fallback to use the pod state to build application state.
   
   So, I think it does not matter.


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [K8S] Support to build application state and error from pod container [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#issuecomment-1815679767

   cc @pan3793 @zwangsheng 


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] [KUBERNETES] Support to build application state and error from pod container [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #5711:
URL: https://github.com/apache/kyuubi/pull/5711#discussion_r1395206844


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala:
##########
@@ -274,16 +293,66 @@ 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

Review Comment:
   remove this one as it is out dated



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org