Skip to content

Commit 7e199d6

Browse files
committed
[KYUUBI #7025] [KYUUBI #6686][FOLLOWUP] Prefer terminated container app state than terminated pod state
### Why are the changes needed? I found that, for a kyuubi batch on kubernetes. 1. It has been `FINISHED`. 2. then I delete the pod manually, then I check the k8s-audit.log, then the appState became `FAILED`. ``` 2025-04-15 11:16:30.453 INFO [-675216314-pool-44-thread-839] org.apache.kyuubi.engine.KubernetesApplicationAuditLogger: label=61e7d8c1-e5a9-46cd-83e7-c611003f0224 context=97 namespace=dls-prod pod=kyuubi-spark-61e7d8c1-e5a9-46cd-83e7-c611003f0224-driver podState=Running containers=[microvault->ContainerState(running=ContainerStateRunning(startedAt=2025-04-15T18:13:48Z, additionalProperties={}), terminated=null, waiting=null, additionalProperties={}),spark-kubernetes-driver->ContainerState(running=null, terminated=ContainerStateTerminated(containerID=containerd://72704f8e7ccb5e877c8f6b10bf6ad810d0c019e07e0cb5975be733e79762c1ec, exitCode=0, finishedAt=2025-04-15T18:14:22Z, message=null, reason=Completed, signal=null, startedAt=2025-04-15T18:13:49Z, additionalProperties={}), waiting=null, additionalProperties={})] appId=spark-228c62e0dc37402bacac189d01b871e4 appState=FINISHED appError='' :2025-04-15 11:16:30.854 INFO [-675216314-pool-44-thread-840] org.apache.kyuubi.engine.KubernetesApplicationAuditLogger: label=61e7d8c1-e5a9-46cd-83e7-c611003f0224 context=97 namespace=dls-prod pod=kyuubi-spark-61e7d8c1-e5a9-46cd-83e7-c611003f0224-driver podState=Failed containers=[microvault->ContainerState(running=null, terminated=ContainerStateTerminated(containerID=containerd://91654e3ee74e2c31218e14be201b50a4a604c2ad15d3afd84dc6f620e59894b7, exitCode=2, finishedAt=2025-04-15T18:16:30Z, message=null, reason=Error, signal=null, startedAt=2025-04-15T18:13:48Z, additionalProperties={}), waiting=null, additionalProperties={}),spark-kubernetes-driver->ContainerState(running=null, terminated=ContainerStateTerminated(containerID=containerd://72704f8e7ccb5e877c8f6b10bf6ad810d0c019e07e0cb5975be733e79762c1ec, exitCode=0, finishedAt=2025-04-15T18:14:22Z, message=null, reason=Completed, signal=null, startedAt=2025-04-15T18:13:49Z, additionalProperties={}), waiting=null, additionalProperties={})] appId=spark-228c62e0dc37402bacac189d01b871e4 appState=FAILED appError='{ ``` This PR is a followup for #6690 , which ignore the container state if POD is terminated. It is more reasonable to respect the terminated container state than terminated pod state. ### How was this patch tested? Integration testing. ``` :2025-04-15 13:53:24.551 INFO [-1077768163-pool-36-thread-3] org.apache.kyuubi.engine.KubernetesApplicationAuditLogger: eventType=DELETE label=e0eb4580-3cfa-43bf-bdcc-efeabcabc93c context=97 namespace=dls-prod pod=kyuubi-spark-e0eb4580-3cfa-43bf-bdcc-efeabcabc93c-driver podState=Failed containers=[microvault->ContainerState(running=null, terminated=ContainerStateTerminated(containerID=containerd://66c42206730950bd422774e3c1b0f426d7879731788cea609bbfe0daab24a763, exitCode=2, finishedAt=2025-04-15T20:53:22Z, message=null, reason=Error, signal=null, startedAt=2025-04-15T20:52:00Z, additionalProperties={}), waiting=null, additionalProperties={}),spark-kubernetes-driver->ContainerState(running=null, terminated=ContainerStateTerminated(containerID=containerd://9179a73d9d9e148dcd9c13ee6cc29dc3e257f95a33609065e061866bb611cb3b, exitCode=0, finishedAt=2025-04-15T20:52:28Z, message=null, reason=Completed, signal=null, startedAt=2025-04-15T20:52:01Z, additionalProperties={}), waiting=null, additionalProperties={})] appId=spark-578df0facbfd4958a07f8d1ae79107dc appState=FINISHED appError='' ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #7025 from turboFei/container_terminated. Closes #7025 Closes #6686 a3b2a5a [Wang, Fei] comments 4356d1b [Wang, Fei] fix the app state logical Authored-by: Wang, Fei <[email protected]> Signed-off-by: Wang, Fei <[email protected]>
1 parent 0ae158e commit 7e199d6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,15 +553,18 @@ object KubernetesApplicationOperation extends Logging {
553553
}
554554

555555
val podAppState = podStateToApplicationState(pod.getStatus.getPhase)
556-
val containerAppState = containerStatusToBuildAppState
556+
val containerAppStateOpt = containerStatusToBuildAppState
557557
.map(_.getState)
558558
.map(containerStateToApplicationState)
559559

560-
// When the pod app state is terminated, the container app state will be ignored
561-
val applicationState = if (ApplicationState.isTerminated(podAppState)) {
562-
podAppState
563-
} else {
564-
containerAppState.getOrElse(podAppState)
560+
val applicationState = containerAppStateOpt match {
561+
// for cases that spark container already terminated, but sidecar containers live
562+
case Some(containerAppState)
563+
if ApplicationState.isTerminated(containerAppState) => containerAppState
564+
// we don't need to care about container state if pod is already terminated
565+
case _ if ApplicationState.isTerminated(podAppState) => podAppState
566+
case Some(containerAppState) => containerAppState
567+
case None => podAppState
565568
}
566569
val applicationError =
567570
if (ApplicationState.isFailed(applicationState)) {

0 commit comments

Comments
 (0)