You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by do...@apache.org on 2023/03/27 22:32:00 UTC
[spark] branch branch-3.3 updated: [SPARK-42906][K8S] Replace a starting digit with `x` in resource name prefix
This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.3 by this push:
new fc126b46ee3 [SPARK-42906][K8S] Replace a starting digit with `x` in resource name prefix
fc126b46ee3 is described below
commit fc126b46ee3b8456e87d98dbbe6cce1b25e62177
Author: Cheng Pan <ch...@apache.org>
AuthorDate: Mon Mar 27 15:31:16 2023 -0700
[SPARK-42906][K8S] Replace a starting digit with `x` in resource name prefix
### What changes were proposed in this pull request?
Change the generated resource name prefix to meet K8s requirements
> DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')
### Why are the changes needed?
In current implementation, the following app name causes error
```
bin/spark-submit \
--master k8s://https://*.*.*.*:6443 \
--deploy-mode cluster \
--name 你好_187609 \
...
```
```
Exception in thread "main" io.fabric8.kubernetes.client.KubernetesClientException:
Failure executing:
POST at: https://*.*.*.*:6443/api/v1/namespaces/spark/services.
Message:
Service "187609-f19020870d12c349-driver-svc" is invalid: metadata.name: Invalid value: "187609-f19020870d12c349-driver-svc": a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?').
```
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
New UT.
Closes #40533 from pan3793/SPARK-42906.
Authored-by: Cheng Pan <ch...@apache.org>
Signed-off-by: Dongjoon Hyun <do...@apache.org>
(cherry picked from commit 0b9a3017005ccab025b93d7b545412b226d4e63c)
Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
.../main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala | 1 +
.../scala/org/apache/spark/deploy/k8s/KubernetesConfSuite.scala | 8 ++++++++
2 files changed, 9 insertions(+)
diff --git a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala
index 60ded7cbd0c..c271b783d49 100644
--- a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala
+++ b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala
@@ -257,6 +257,7 @@ private[spark] object KubernetesConf {
.replaceAll("[^a-z0-9\\-]", "-")
.replaceAll("-+", "-")
.replaceAll("^-", "")
+ .replaceAll("^[0-9]", "x")
}
def getAppNameLabel(appName: String): String = {
diff --git a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesConfSuite.scala b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesConfSuite.scala
index 95ef27c2a18..3d310a831ea 100644
--- a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesConfSuite.scala
+++ b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesConfSuite.scala
@@ -254,4 +254,12 @@ class KubernetesConfSuite extends SparkFunSuite {
test("SPARK-40869: Resource name prefix should not start with a hyphen") {
assert(KubernetesConf.getResourceNamePrefix("_hello_").startsWith("hello"))
}
+
+ test("SPARK-42906: Resource name prefix should start with an alphabetic character") {
+ // scalastyle:off nonascii
+ Seq("你好-123", "---123", "123---", "------", "123456").foreach { appName =>
+ // scalastyle:on nonascii
+ assert(KubernetesConf.getResourceNamePrefix(appName).matches("[a-z]([-a-z0-9]*[a-z0-9])?"))
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org