@@ -26,7 +26,7 @@ import io.fabric8.kubernetes.client.informers.SharedIndexInformer
2626
2727import org .apache .kyuubi .Logging
2828import org .apache .kyuubi .config .KyuubiConf
29- import org .apache .kyuubi .engine .ApplicationState .{ApplicationState , FAILED , FINISHED , NOT_FOUND , PENDING , RUNNING , UNKNOWN }
29+ import org .apache .kyuubi .engine .ApplicationState .{isTerminated , ApplicationState , FAILED , FINISHED , NOT_FOUND , PENDING , RUNNING , UNKNOWN }
3030import org .apache .kyuubi .engine .KubernetesApplicationOperation .{toApplicationState , LABEL_KYUUBI_UNIQUE_KEY , SPARK_APP_ID_LABEL }
3131import org .apache .kyuubi .util .KubernetesUtils
3232
@@ -36,7 +36,7 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
3636
3737 @ volatile
3838 private var kubernetesClient : KubernetesClient = _
39- private var driverInformer : SharedIndexInformer [Pod ] = _
39+ private var enginePodInformer : SharedIndexInformer [Pod ] = _
4040 private var submitTimeout : Long = _
4141
4242 private val appInfoStore : ConcurrentHashMap [String , ApplicationInfo ] =
@@ -51,10 +51,9 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
5151 submitTimeout = conf.get(KyuubiConf .ENGINE_SUBMIT_TIMEOUT )
5252 // Using Kubernetes Informer to update application state
5353 val informerPeriod = conf.get(KyuubiConf .KUBERNETES_INFORMER_PERIOD )
54- driverInformer = client.informers().sharedIndexInformerFor(
55- classOf [Pod ],
56- informerPeriod)
57- driverInformer.addEventHandler(new SparkEnginePodEventHandler ()).start()
54+ enginePodInformer =
55+ client.pods().withLabel(LABEL_KYUUBI_UNIQUE_KEY ).runnableInformer(informerPeriod)
56+ enginePodInformer.addEventHandler(new SparkEnginePodEventHandler ()).start()
5857 info(" Start Kubernetes Client Informer." )
5958 // Using Cache help clean delete app info
6059 val cachePeriod = conf.get(KyuubiConf .KUBERNETES_INFORMER_CACHE_PERIOD )
@@ -139,8 +138,8 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
139138
140139 override def stop (): Unit = {
141140 try {
142- if (driverInformer != null ) {
143- driverInformer .stop()
141+ if (enginePodInformer != null ) {
142+ enginePodInformer .stop()
144143 }
145144 if (kubernetesClient != null ) {
146145 kubernetesClient.close()
@@ -158,7 +157,7 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
158157 pod.getMetadata.getLabels.containsKey(LABEL_KYUUBI_UNIQUE_KEY )
159158 }
160159
161- private def updateState (pod : Pod ): Unit = {
160+ private def updateApplicationState (pod : Pod ): Unit = {
162161 val metaData = pod.getMetadata
163162 val state = toApplicationState(pod.getStatus.getPhase)
164163 debug(s " Driver Informer change pod: ${metaData.getName} state: $state" )
@@ -171,24 +170,24 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
171170 error = Option (pod.getStatus.getReason)))
172171 }
173172
174- private def markDeleted (pod : Pod ): Unit = {
173+ private def markTerminated (pod : Pod ): Unit = {
175174 deletedAppInfoCache.put(
176175 pod.getMetadata.getLabels.get(LABEL_KYUUBI_UNIQUE_KEY ),
177176 toApplicationState(pod.getStatus.getPhase))
178177 }
179178
180179 override def onAdd (pod : Pod ): Unit = {
181180 if (isSparkEnginePod(pod)) {
182- updateState (pod)
181+ updateApplicationState (pod)
183182 }
184183 }
185184
186185 override def onUpdate (oldPod : Pod , newPod : Pod ): Unit = {
187186 if (isSparkEnginePod(newPod)) {
188- updateState (newPod)
187+ updateApplicationState (newPod)
189188 toApplicationState(newPod.getStatus.getPhase) match {
190- case FINISHED | FAILED | UNKNOWN =>
191- markDeleted (newPod)
189+ case state if isTerminated(state) =>
190+ markTerminated (newPod)
192191 case _ =>
193192 // do nothing
194193 }
@@ -197,8 +196,8 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
197196
198197 override def onDelete (pod : Pod , deletedFinalStateUnknown : Boolean ): Unit = {
199198 if (isSparkEnginePod(pod)) {
200- updateState (pod)
201- markDeleted (pod)
199+ updateApplicationState (pod)
200+ markTerminated (pod)
202201 }
203202 }
204203 }
0 commit comments