@@ -83,45 +83,9 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
8383
8484 private var cleanupCanceledAppPodExecutor : ThreadPoolExecutor = _
8585
86- private var kubernetesClientInitializeCleanupTerminatedPodExecutor : ThreadPoolExecutor = _
87-
8886 private def getOrCreateKubernetesClient (kubernetesInfo : KubernetesInfo ): KubernetesClient = {
8987 checkKubernetesInfo(kubernetesInfo)
90- kubernetesClients.computeIfAbsent(
91- kubernetesInfo,
92- kInfo => {
93- val kubernetesClient = buildKubernetesClient(kInfo)
94- cleanTerminatedAppPodsOnKubernetesClientInitialize(kInfo, kubernetesClient)
95- kubernetesClient
96- })
97- }
98-
99- private def cleanTerminatedAppPodsOnKubernetesClientInitialize (
100- kubernetesInfo : KubernetesInfo ,
101- kubernetesClient : KubernetesClient ): Unit = {
102- if (kubernetesClientInitializeCleanupTerminatedPodExecutor != null ) {
103- kubernetesClientInitializeCleanupTerminatedPodExecutor.submit(new Runnable {
104- override def run (): Unit = {
105- val existingPods =
106- kubernetesClient.pods().withLabel(LABEL_KYUUBI_UNIQUE_KEY ).list().getItems
107- info(s " [ $kubernetesInfo] Found ${existingPods.size()} existing pods with label " +
108- s " $LABEL_KYUUBI_UNIQUE_KEY" )
109- val eventType = KubernetesResourceEventTypes .UPDATE
110- existingPods.asScala.filter(isSparkEnginePod).foreach { pod =>
111- val appState = toApplicationState(pod, appStateSource, appStateContainer, eventType)
112- if (isTerminated(appState)) {
113- val kyuubiUniqueKey = pod.getMetadata.getLabels.get(LABEL_KYUUBI_UNIQUE_KEY )
114- info(s " [ $kubernetesInfo] Found existing pod ${pod.getMetadata.getName} with " +
115- s " ${toLabel(kyuubiUniqueKey)} in app state $appState, marking it as terminated " )
116- if (appInfoStore.get(kyuubiUniqueKey) == null ) {
117- updateApplicationState(kubernetesInfo, pod, eventType)
118- }
119- markApplicationTerminated(kubernetesInfo, pod, eventType)
120- }
121- }
122- }
123- })
124- }
88+ kubernetesClients.computeIfAbsent(kubernetesInfo, kInfo => buildKubernetesClient(kInfo))
12589 }
12690
12791 private var metadataManager : Option [MetadataManager ] = _
@@ -210,9 +174,6 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
210174 TimeUnit .MILLISECONDS )
211175 cleanupCanceledAppPodExecutor = ThreadUtils .newDaemonCachedThreadPool(
212176 " cleanup-canceled-app-pod-thread" )
213- kubernetesClientInitializeCleanupTerminatedPodExecutor =
214- ThreadUtils .newDaemonCachedThreadPool(
215- " kubernetes-client-initialize-cleanup-terminated-pod-thread" )
216177 initializeKubernetesClient(kyuubiConf)
217178 }
218179
@@ -373,11 +334,6 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
373334 ThreadUtils .shutdown(cleanupCanceledAppPodExecutor)
374335 cleanupCanceledAppPodExecutor = null
375336 }
376-
377- if (kubernetesClientInitializeCleanupTerminatedPodExecutor != null ) {
378- ThreadUtils .shutdown(kubernetesClientInitializeCleanupTerminatedPodExecutor)
379- kubernetesClientInitializeCleanupTerminatedPodExecutor = null
380- }
381337 }
382338
383339 private class SparkEnginePodEventHandler (kubernetesInfo : KubernetesInfo )
@@ -387,6 +343,10 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
387343 if (isSparkEnginePod(pod)) {
388344 val eventType = KubernetesResourceEventTypes .ADD
389345 updateApplicationState(kubernetesInfo, pod, eventType)
346+ val appState = toApplicationState(pod, appStateSource, appStateContainer, eventType)
347+ if (isTerminated(appState)) {
348+ markApplicationTerminated(kubernetesInfo, pod, eventType)
349+ }
390350 KubernetesApplicationAuditLogger .audit(
391351 eventType,
392352 kubernetesInfo,
0 commit comments