Skip to content

Commit 7f3b598

Browse files
[SPARK-40869][K8S] Resource name prefix should not start with a hyphen
### What changes were proposed in this pull request? Strip leading - from resource name prefix ### Why are the changes needed? leading - are not allowed for resource name prefix (especially spark.kubernetes.executor.podNamePrefix) ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Unit test Closes #38331 from tobiasstadler/fix-SPARK-40869. Lead-authored-by: Tobias Stadler <[email protected]> Co-authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 67d0dc8 commit 7f3b598

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ private[spark] object KubernetesConf {
256256
.toLowerCase(Locale.ROOT)
257257
.replaceAll("[^a-z0-9\\-]", "-")
258258
.replaceAll("-+", "-")
259+
.replaceAll("^-", "")
259260
}
260261

261262
def getAppNameLabel(appName: String): String = {

resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesConfSuite.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,8 @@ class KubernetesConfSuite extends SparkFunSuite {
250250
assert(KubernetesConf.getAppNameLabel("a" * 62 + "-aaa") === "a" * 62)
251251
assert(KubernetesConf.getAppNameLabel("-" + "a" * 63) === "a" * 62)
252252
}
253+
254+
test("SPARK-40869: Resource name prefix should not start with a hyphen") {
255+
assert(KubernetesConf.getResourceNamePrefix("_hello_").startsWith("hello"))
256+
}
253257
}

0 commit comments

Comments
 (0)