Skip to content

Commit 54ae4fe

Browse files
Marcelo VanzinCatalin Toda
authored andcommitted
[SPARK-24894][K8S] Make sure valid host names are created for executors.
Since the host name is derived from the app name, which can contain arbitrary characters, it needs to be sanitized so that only valid characters are allowed. On top of that, take extra care that truncation doesn't leave characters that are valid except at the start of a host name. Closes apache#23781 from vanzin/SPARK-24894. Authored-by: Marcelo Vanzin <[email protected]> Signed-off-by: Marcelo Vanzin <[email protected]>
1 parent 146611c commit 54ae4fe

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ private[spark] class BasicExecutorFeatureStep(
100100
// name as the hostname. This preserves uniqueness since the end of name contains
101101
// executorId
102102
val hostname = name.substring(Math.max(0, name.length - 63))
103+
// Remove non-word characters from the start of the hostname
104+
.replaceAll("^[^\\w]+", "")
105+
// Replace dangerous characters in the remaining string with a safe alternative.
106+
.replaceAll("[^\\w-]+", "_")
107+
103108
val executorMemoryQuantity = new QuantityBuilder(false)
104109
.withAmount(s"${executorMemoryTotal}Mi")
105110
.build()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package org.apache.spark.deploy.k8s.features
1818

1919
import scala.collection.JavaConverters._
2020

21+
import com.google.common.net.InternetDomainName
2122
import io.fabric8.kubernetes.api.model._
2223
import org.mockito.MockitoAnnotations
2324
import org.scalatest.{BeforeAndAfter, BeforeAndAfterEach}

0 commit comments

Comments
 (0)