Skip to content

Commit

Permalink
pod status
Browse files Browse the repository at this point in the history
  • Loading branch information
turboFei committed Feb 8, 2024
1 parent f8152e7 commit 5135f5b
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,23 +365,24 @@ object KubernetesApplicationOperation extends Logging {
appStateSource: KubernetesApplicationStateSource,
appStateContainer: String): (ApplicationState, Option[String]) = {
val podName = pod.getMetadata.getName
val containerStateToBuildAppState = appStateSource match {
val containerStatusToBuildAppState = appStateSource match {
case KubernetesApplicationStateSource.CONTAINER =>
pod.getStatus.getContainerStatuses.asScala
.find(cs => appStateContainer.equalsIgnoreCase(cs.getName)).map(_.getState)
.find(cs => appStateContainer.equalsIgnoreCase(cs.getName))
case KubernetesApplicationStateSource.POD => None
}
val applicationState = containerStateToBuildAppState.map(containerStateToApplicationState)
val applicationState = containerStatusToBuildAppState
.map(_.getState)
.map(containerStateToApplicationState)
.getOrElse(podStateToApplicationState(pod.getStatus.getPhase))
val applicationError = if (ApplicationState.isFailed(applicationState)) {
containerStateToBuildAppState
.map(cs =>
s"""Pod: $podName
|Container: $appStateContainer
|ContainerStatus: ${JsonUtils.toPrettyJson(cs)}""".stripMargin)
.orElse(Some(
s"""Pod: $podName
|PodStatus: ${JsonUtils.toPrettyJson(pod.getStatus)}""".stripMargin))
var errorMap = Map("Pod" -> podName, "Container" -> appStateContainer)
containerStatusToBuildAppState.map { cs =>
errorMap ++= Map("ContainerStatus" -> cs)
}.getOrElse {
errorMap ++= Map("PodStatus" -> pod.getStatus)
}
Some(JsonUtils.toPrettyJson(errorMap.asJava))
} else {
None
}
Expand Down

0 comments on commit 5135f5b

Please sign in to comment.