Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KYUUBI #5237] ConfigMaps deletion on Kubernetes #6700

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
private var expireCleanUpTriggerCacheExecutor: ScheduledExecutorService = _

private var cleanupCanceledAppPodExecutor: ThreadPoolExecutor = _
private var cleanupConfigMapExecutor: ThreadPoolExecutor = _

private def getOrCreateKubernetesClient(kubernetesInfo: KubernetesInfo): KubernetesClient = {
checkKubernetesInfo(kubernetesInfo)
Expand Down Expand Up @@ -165,6 +166,8 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
TimeUnit.MILLISECONDS)
cleanupCanceledAppPodExecutor = ThreadUtils.newDaemonCachedThreadPool(
"cleanup-canceled-app-pod-thread")
cleanupConfigMapExecutor = ThreadUtils.newDaemonCachedThreadPool(
"cleanup-config-map-thread")
}

override def isSupported(appMgrInfo: ApplicationManagerInfo): Boolean = {
Expand Down Expand Up @@ -278,6 +281,48 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
private class SparkEnginePodEventHandler(kubernetesInfo: KubernetesInfo)
extends ResourceEventHandler[Pod] {

private def runConfigMapDeletion(pod: Pod, kubernetesInfo: KubernetesInfo): Unit = {
cleanupConfigMapExecutor.submit(new Runnable {
override def run(): Unit = Utils.tryLogNonFatalError {
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 " +
s"$configMapName associated with " +
s"pod ${pod.getMetadata.getName}.")
}
case None =>
warn(
s"[$kubernetesInfo] No ConfigMap volume found " +
s"for pod ${pod.getMetadata.getName}.")
}
} catch {
case NonFatal(e) => error(
s"[$kubernetesInfo] Failed to delete ConfigMap associated with " +
s"pod ${pod.getMetadata.getName}",
e)
}
}
})
}

override def onAdd(pod: Pod): Unit = {
if (isSparkEnginePod(pod)) {
updateApplicationState(kubernetesInfo, pod)
Expand Down Expand Up @@ -320,6 +365,8 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
appStateSource,
appStateContainer)
}

runConfigMapDeletion(pod, kubernetesInfo)
Copy link
Member

@turboFei turboFei Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

questions:

Do the executors belong to the same app share the configmap?

If that, on executor pod deleted, you will delete the shared the configmap.

}
}

Expand Down
Loading