Skip to content

Commit 52c4e57

Browse files
committed
[SPARK-41419][K8S] Decrement PVC_COUNTER when the pod deletion happens
1 parent d9c7908 commit 52c4e57

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ class ExecutorPodsAllocator(
433433
podWithAttachedContainer, resolvedExecutorSpec.executorKubernetesResources, reusablePVCs)
434434
val createdExecutorPod =
435435
kubernetesClient.pods().inNamespace(namespace).resource(podWithAttachedContainer).create()
436+
var success = 0
436437
try {
437438
addOwnerReference(createdExecutorPod, resources)
438439
resources
@@ -445,6 +446,7 @@ class ExecutorPodsAllocator(
445446
logInfo(s"Trying to create PersistentVolumeClaim ${pvc.getMetadata.getName} with " +
446447
s"StorageClass ${pvc.getSpec.getStorageClassName}")
447448
kubernetesClient.persistentVolumeClaims().inNamespace(namespace).resource(pvc).create()
449+
success += 1
448450
PVC_COUNTER.incrementAndGet()
449451
}
450452
newlyCreatedExecutors(newExecutorId) = (resourceProfileId, clock.getTimeMillis())
@@ -455,7 +457,15 @@ class ExecutorPodsAllocator(
455457
.inNamespace(namespace)
456458
.resource(createdExecutorPod)
457459
.delete()
460+
if (success == 1) {
461+
success += 1
462+
}
458463
throw e
464+
} finally {
465+
if ((!conf.get(KUBERNETES_DRIVER_OWN_PVC) || !conf.get(KUBERNETES_DRIVER_REUSE_PVC))
466+
&& success == 2) {
467+
PVC_COUNTER.decrementAndGet()
468+
}
459469
}
460470
}
461471
}

0 commit comments

Comments
 (0)