Skip to content

Commit fac497c

Browse files
committed
[SPARK-59914][K8S] Make ExecutorResizePlugin skip executor pods with the placeholder EXECID label
### What changes were proposed in this pull request? This PR aims to make `ExecutorResizePlugin` skip executor pods whose `spark-exec-id` label is the placeholder `EXECID`, like `ExecutorPodsSnapshot` does. ### Why are the changes needed? `deployment` and `statefulset` pods allocators create executor pods with the `EXECID` label and patch the real executor ID later on a best-effort basis. Currently, `ExecutorResizePlugin` runs only with the `direct` pods allocator, so this is a defensive improvement. It keeps the placeholder out of the `cappedExecutors` keys and the logs. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass the CIs with the newly added test case. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 5.5 Closes #59175 from dongjoon-hyun/SPARK-59914. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]> (cherry picked from commit 6ed637f) Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent a20c062 commit fac497c

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,20 @@ class ExecutorResizeDriverPlugin extends DriverPlugin with Logging {
111111
.list()
112112
.getItems.asScala
113113

114+
val executorPods = pods.flatMap { pod =>
115+
pod.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL) match {
116+
case "EXECID" | null =>
117+
// The exec label has not yet been assigned
118+
None
119+
case id =>
120+
Some((id, pod))
121+
}
122+
}
123+
114124
// Drop executors that no longer exist so that cappedExecutors does not grow unbounded.
115-
cappedExecutors.retainAll(pods.flatMap { p =>
116-
Option(p.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL))
117-
}.toSet.asJava)
125+
cappedExecutors.retainAll(executorPods.map(_._1).toSet.asJava)
118126

119-
pods.filter(_.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL) != null).foreach { pod =>
120-
val execId = pod.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL)
127+
executorPods.foreach { case (execId, pod) =>
121128
try {
122129
val metrics = kubernetesClient.top().pods().metrics(namespace, pod.getMetadata.getName)
123130

‎resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorResizePluginSuite.scala‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,24 @@ class ExecutorResizePluginSuite
161161
verify(podMetricOperations, never()).metrics(anyString(), anyString())
162162
}
163163

164+
test("Pod with placeholder executor ID label should be skipped") {
165+
val plugin = createPlugin()
166+
val pod = new PodBuilder()
167+
.withNewMetadata()
168+
.withName("spark-executor-1")
169+
.addToLabels(SPARK_APP_ID_LABEL, appId)
170+
.addToLabels(SPARK_ROLE_LABEL, SPARK_POD_EXECUTOR_ROLE)
171+
.addToLabels(SPARK_EXECUTOR_ID_LABEL, "EXECID")
172+
.endMetadata()
173+
.build()
174+
175+
when(podList.getItems).thenReturn(Collections.singletonList(pod))
176+
177+
plugin.invokePrivate(_checkAndIncreaseMemory(namespace, 0.9, 0.1, kubernetesClient))
178+
179+
verify(podMetricOperations, never()).metrics(anyString(), anyString())
180+
}
181+
164182
test("SPARK-59840: Inactive executor pods are excluded from the listing") {
165183
val plugin = createPlugin()
166184
when(podList.getItems).thenReturn(Collections.emptyList())

0 commit comments

Comments
 (0)