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 fed4a65  [SPARK-38630][K8S] K8s app name label should start and end 
with alphanumeric char
fed4a65 is described below

commit fed4a65fe1b809051a111b50f4fa550bb9b2b204
Author: Dongjoon Hyun <dh...@apple.com>
AuthorDate: Tue Mar 22 21:12:26 2022 -0700

    [SPARK-38630][K8S] K8s app name label should start and end with 
alphanumeric char
    
    ### What changes were proposed in this pull request?
    
    This PR aims to fix `getAppNameLabel` by removing the prefix and suffix `-` 
character from app name label.
    
    ### Why are the changes needed?
    
    Currently, `master/branch-3.3` has this regression.
    ```
    io.fabric8.kubernetes.client.KubernetesClientException:
    Failure executing: POST at: 
https://kubernetes.default.svc/api/v1/namespaces/default/pods.
    Message: Pod "..." is invalid:
    metadata.labels: Invalid value: "...-tpcds-1000g-parquet-":
    a valid label must be an empty string or consist of alphanumeric 
characters, '-', '_' or '.', and
    must start and end with an alphanumeric character
    ```
    
    ### Does this PR introduce _any_ user-facing change?
    
    This is a regression at Apache Spark 3.3.0.
    
    ### How was this patch tested?
    
    Pass the CI with the newly added test case.
    
    Closes #35943 from dongjoon-hyun/SPARK-38630.
    
    Authored-by: Dongjoon Hyun <dh...@apple.com>
    Signed-off-by: Dongjoon Hyun <dongj...@apache.org>
    (cherry picked from commit 43487cb2b0f01cbb2c235cc52fcb515c5448d4a8)
    Signed-off-by: Dongjoon Hyun <dongj...@apache.org>
---
 .../src/main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala | 5 +++--
 .../scala/org/apache/spark/deploy/k8s/KubernetesConfSuite.scala     | 6 ++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

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 118f4e5..8a985c3 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
@@ -261,7 +261,8 @@ private[spark] object KubernetesConf {
   def getAppNameLabel(appName: String): String = {
     // According to 
https://kubernetes.io/docs/concepts/overview/working-with-objects/labels,
     // must be 63 characters or less to follow the DNS label standard, so take 
the 63 characters
-    // of the appName name as the label.
+    // of the appName name as the label. In addition, label value must start 
and end with
+    // an alphanumeric character.
     StringUtils.abbreviate(
       s"$appName"
         .trim
@@ -270,7 +271,7 @@ private[spark] object KubernetesConf {
         .replaceAll("-+", "-"),
       "",
       KUBERNETES_DNSNAME_MAX_LENGTH
-    )
+    ).stripPrefix("-").stripSuffix("-")
   }
 
   /**
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 eecaff2..d33d792 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
@@ -244,4 +244,10 @@ class KubernetesConfSuite extends SparkFunSuite {
     assert(KubernetesConf.getAppNameLabel("a" * 64) === "a" * 63)
     assert(KubernetesConf.getAppNameLabel("a" * 253) === "a" * 63)
   }
+
+  test("SPARK-38630: K8s label value should start and end with alphanumeric") {
+    assert(KubernetesConf.getAppNameLabel("-hello-") === "hello")
+    assert(KubernetesConf.getAppNameLabel("a" * 62 + "-aaa") === "a" * 62)
+    assert(KubernetesConf.getAppNameLabel("-" + "a" * 63) === "a" * 62)
+  }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to