diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala index 41b4d448178..db1fb40fc2d 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala @@ -320,6 +320,39 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging { appStateSource, appStateContainer) } + + try { + val volumes = pod.getSpec.getVolumes.asScala + val configMapVolume = volumes.find(_.getConfigMap != null) + .map(_.getConfigMap.getName) + .find(_.contains("spark-exec")) + + configMapVolume match { + case Some(configMapName) => + val kubernetesClient = getOrCreateKubernetesClient(kubernetesInfo) + val statusDetailsList = kubernetesClient.configMaps().withName(configMapName).delete() + + val deletionSuccessful = + statusDetailsList != null && statusDetailsList.asScala.nonEmpty + if (deletionSuccessful) { + info( + s"[$kubernetesInfo] ConfigMap $configMapName associated with " + + s"pod ${pod.getMetadata.getName} deleted successfully.") + } else { + warn( + s"[$kubernetesInfo] Failed to delete ConfigMap $configMapName associated with " + + s"pod ${pod.getMetadata.getName}.") + } + case None => + warn( + s"[$kubernetesInfo] No ConfigMap volume found for pod ${pod.getMetadata.getName}.") + } + } catch { + case NonFatal(e) => error( + s"[$kubernetesInfo] Failed to delete ConfigMap associated with " + + s"pod ${pod.getMetadata.getName}", + e) + } } }