Skip to content

Commit bbd8fd6

Browse files
committed
[SPARK-55399][K8S] Improve KubernetesDriverEndpoint to use patch instead of edit API
### What changes were proposed in this pull request? This PR aims to improve `KubernetesDriverEndpoint` to use `patch` instead of `edit` API ### Why are the changes needed? **Network Efficiency** - `edit` requires fetching the entire resource and sending the full updated resource back. - `patch` only transmits the specific changes, making it much more network-efficient. **Concurrency & Conflict Resolution** - `edit` typically follows a Get -> Modify -> Update (PUT) pattern. Using this pattern creates a race condition where, if another client modifies the resource in between, a 409 Conflict error occurs due to a mismatched resourceVersion. - `patch` sends only the changes (delta) to the server, where the merge is handled server-side. This significantly reduces the risk of conflicts, especially for simple operations like adding an annotation. ### Does this PR introduce _any_ user-facing change? This will reduce the overhead of K8s control plane and the chance of 409 error. ### How was this patch tested? Pass the CIs with newly updated test case. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: `Sonnet 4.5` on `Claude Code` Closes #54179 from dongjoon-hyun/SPARK-55399. Authored-by: Dongjoon Hyun <dongjoon@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent cbcc7f8 commit bbd8fd6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,11 @@ private[spark] class KubernetesClusterSchedulerBackend(
353353
kubernetesClient.pods()
354354
.inNamespace(namespace)
355355
.withName(x.podName)
356-
.edit({p: Pod => new PodBuilder(p).editMetadata()
356+
.patch(PATCH_CONTEXT, new PodBuilder()
357+
.withNewMetadata()
357358
.addToLabels(SPARK_EXECUTOR_ID_LABEL, newId)
358359
.endMetadata()
359-
.build()})
360+
.build())
360361
}
361362
}
362363
executorService.execute(labelTask)

0 commit comments

Comments
 (0)