Skip to content

Commit

Permalink
[KYUUBI #5711][FOLLOWUP] Fix typo and audit pod and container states
Browse files Browse the repository at this point in the history
# 🔍 Description

Fix typo when checking container name, and audit the pod state and container states as we support to retrieve application state from pod and container states.
## Issue References 🔗

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 🔖

- [ ] 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 ⚰️

#### Behavior With This Pull Request 🎉

#### Related Unit Tests

---

# Checklists
## 📝 Author Self Checklist

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

- [x] Pull request title is okay.
- [x] No license issues.
- [x] Milestone correctly set?
- [ ] Test coverage is ok
- [x] Assignees are selected.
- [x] Minimum number of approvals
- [x] No changes are requested

**Be nice. Be informative.**

Closes #5763 from turboFei/fix_typo_k8s.

Closes #5711

59b6025 [fwang12] container and pod
4ef7fc9 [fwang12] more states
301d44e [fwang12] typo

Authored-by: fwang12 <[email protected]>
Signed-off-by: fwang12 <[email protected]>
  • Loading branch information
turboFei committed Nov 24, 2023
1 parent b70b510 commit ba5cb24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.kyuubi.engine

import scala.collection.JavaConverters._

import io.fabric8.kubernetes.api.model.Pod

import org.apache.kyuubi.Logging
Expand All @@ -39,6 +41,11 @@ object KubernetesApplicationAuditLogger extends Logging {
sb.append(s"context=${kubernetesInfo.context.orNull}").append("\t")
sb.append(s"namespace=${kubernetesInfo.namespace.orNull}").append("\t")
sb.append(s"pod=${pod.getMetadata.getName}").append("\t")
sb.append(s"podState=${pod.getStatus.getPhase}").append("\t")
val containerStatuses = pod.getStatus.getContainerStatuses.asScala.map { containerState =>
s"${containerState.getName}->${containerState.getState}"
}.mkString("[", ",", "]").foreach(sb.append(_).append("\t"))
sb.append(s"containers=$containerStatuses").append("\t")
sb.append(s"appId=${pod.getMetadata.getLabels.get(SPARK_APP_ID_LABEL)}").append("\t")
val (appState, appError) =
toApplicationStateAndError(pod, appStateSource, appStateContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,18 @@ object KubernetesApplicationOperation extends Logging {
pod: Pod,
appStateSource: KubernetesApplicationStateSource,
appStateContainer: String): (ApplicationState, Option[String]) = {
val podName = pod.getMetadata.getName
val containerStateToBuildAppState = appStateSource match {
case KubernetesApplicationStateSource.CONTAINER =>
pod.getStatus.getContainerStatuses.asScala
.find(_.getState == appStateContainer).map(_.getState)
.find(cs => appStateContainer.equalsIgnoreCase(cs.getName)).map(_.getState)
case KubernetesApplicationStateSource.POD => None
}
val applicationState = containerStateToBuildAppState.map(containerStateToApplicationState)
.getOrElse(podStateToApplicationState(pod.getStatus.getPhase))
val applicationError = containerStateToBuildAppState.map(containerStateToApplicationError)
.getOrElse(Option(pod.getStatus.getReason))
val applicationError = containerStateToBuildAppState
.map(cs => containerStateToApplicationError(cs).map(r => s"$podName/$appStateContainer[$r]"))
.getOrElse(Option(pod.getStatus.getReason).map(r => s"$podName[$r]"))
applicationState -> applicationError
}

Expand Down

0 comments on commit ba5cb24

Please sign in to comment.