From e11d9f6c6f5e14c428a7f67b3117f3b534adbe35 Mon Sep 17 00:00:00 2001 From: hehuiyuan Date: Tue, 26 Mar 2019 16:47:16 +0800 Subject: [PATCH 1/4] Fix the first character of Service's name is digit --- .../k8s/features/DriverServiceFeatureStep.scala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala index 925bcdf3e637f..7dc0bfe83d3a0 100644 --- a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala +++ b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala @@ -38,15 +38,21 @@ private[spark] class DriverServiceFeatureStep( s"$DRIVER_HOST_KEY is not supported in Kubernetes mode, as the driver's hostname will be " + "managed via a Kubernetes service.") + def isDigit(char: Char) : Boolean = { + char >= '0' && char <= '9' + } + private val preferredServiceName = s"${kubernetesConf.resourceNamePrefix}$DRIVER_SVC_POSTFIX" - private val resolvedServiceName = if (preferredServiceName.length <= MAX_SERVICE_NAME_LENGTH) { + private val resolvedServiceName = if (preferredServiceName.length <= MAX_SERVICE_NAME_LENGTH + && !isDigit(preferredServiceName.charAt(0))) { preferredServiceName } else { val randomServiceId = KubernetesUtils.uniqueID(clock = clock) val shorterServiceName = s"spark-$randomServiceId$DRIVER_SVC_POSTFIX" logWarning(s"Driver's hostname would preferably be $preferredServiceName, but this is " + - s"too long (must be <= $MAX_SERVICE_NAME_LENGTH characters). Falling back to use " + - s"$shorterServiceName as the driver service's name.") + s"too long (must be <= $MAX_SERVICE_NAME_LENGTH characters) " + + s"or the first character of $preferredServiceName is digit which is not support." + + s" Falling back to use $shorterServiceName as the driver service's name.") shorterServiceName } From b0c3df29fd87fc7c26db14348d6470c8b7924859 Mon Sep 17 00:00:00 2001 From: hehuiyuan Date: Tue, 26 Mar 2019 20:28:22 +0800 Subject: [PATCH 2/4] use JDK method 'Character.isDigit' --- .../deploy/k8s/features/DriverServiceFeatureStep.scala | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala index 7dc0bfe83d3a0..03a6cb588642e 100644 --- a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala +++ b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala @@ -38,13 +38,9 @@ private[spark] class DriverServiceFeatureStep( s"$DRIVER_HOST_KEY is not supported in Kubernetes mode, as the driver's hostname will be " + "managed via a Kubernetes service.") - def isDigit(char: Char) : Boolean = { - char >= '0' && char <= '9' - } - private val preferredServiceName = s"${kubernetesConf.resourceNamePrefix}$DRIVER_SVC_POSTFIX" private val resolvedServiceName = if (preferredServiceName.length <= MAX_SERVICE_NAME_LENGTH - && !isDigit(preferredServiceName.charAt(0))) { + && !Character.isDigit(preferredServiceName.charAt(0))) { preferredServiceName } else { val randomServiceId = KubernetesUtils.uniqueID(clock = clock) From 3a53d48fd711b7c313d0c0fd68d847e329497d4b Mon Sep 17 00:00:00 2001 From: hehuiyuan Date: Tue, 26 Mar 2019 23:18:39 +0800 Subject: [PATCH 3/4] add extra regex for getResourceNamePrefix method --- .../main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala | 1 + 1 file changed, 1 insertion(+) 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 5e741112fc7e7..67d3066e1da81 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 @@ -198,5 +198,6 @@ private[spark] object KubernetesConf { .replaceAll("\\.", "-") .replaceAll("[^a-z0-9\\-]", "") .replaceAll("-+", "-") + .replaceAll("^-", "") } } From 6af655706290c1416342a3ba191ae28639115119 Mon Sep 17 00:00:00 2001 From: hehuiyuan Date: Wed, 27 Mar 2019 18:36:07 +0800 Subject: [PATCH 4/4] replace isDigt with isLetter --- .../spark/deploy/k8s/features/DriverServiceFeatureStep.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala index 03a6cb588642e..aefb120d25a26 100644 --- a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala +++ b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/DriverServiceFeatureStep.scala @@ -40,14 +40,14 @@ private[spark] class DriverServiceFeatureStep( private val preferredServiceName = s"${kubernetesConf.resourceNamePrefix}$DRIVER_SVC_POSTFIX" private val resolvedServiceName = if (preferredServiceName.length <= MAX_SERVICE_NAME_LENGTH - && !Character.isDigit(preferredServiceName.charAt(0))) { + && Character.isLetter(preferredServiceName.charAt(0))) { preferredServiceName } else { val randomServiceId = KubernetesUtils.uniqueID(clock = clock) val shorterServiceName = s"spark-$randomServiceId$DRIVER_SVC_POSTFIX" logWarning(s"Driver's hostname would preferably be $preferredServiceName, but this is " + s"too long (must be <= $MAX_SERVICE_NAME_LENGTH characters) " + - s"or the first character of $preferredServiceName is digit which is not support." + + s"or the first character of $preferredServiceName is not letter which is not support." + s" Falling back to use $shorterServiceName as the driver service's name.") shorterServiceName }