Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[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.
  • Loading branch information
Marcelo Vanzin committed Feb 14, 2019
commit 9fb83468737ddd26b1eaccc691020cbf0d7fbe11
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ private[spark] class BasicExecutorFeatureStep(
// name as the hostname. This preserves uniqueness since the end of name contains
// executorId
val hostname = name.substring(Math.max(0, name.length - 63))
// Remove non-word characters from the start of the hostname
.replaceAll("^[^\\w]+", "")
// Replace dangerous characters in the remaining string with a safe alternative.
.replaceAll("[^\\w-]+", "_")

val executorMemoryQuantity = new QuantityBuilder(false)
.withAmount(s"${executorMemoryTotal}Mi")
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.nio.file.Files

import scala.collection.JavaConverters._

import com.google.common.net.InternetDomainName
import io.fabric8.kubernetes.api.model._
import org.scalatest.BeforeAndAfter

Expand Down Expand Up @@ -124,6 +125,16 @@ class BasicExecutorFeatureStepSuite extends SparkFunSuite with BeforeAndAfter {
assert(step.configurePod(SparkPod.initialPod()).pod.getSpec.getHostname.length === 63)
}

test("hostname truncation generates valid host names") {
val invalidPrefix = "abcdef-*_/[]{}+==.,;'\"-----------------------------------------------"

baseConf.set(KUBERNETES_EXECUTOR_POD_NAME_PREFIX, invalidPrefix)
val step = new BasicExecutorFeatureStep(newExecutorConf(), new SecurityManager(baseConf))
val hostname = step.configurePod(SparkPod.initialPod()).pod.getSpec().getHostname()
assert(hostname.length <= 63)
assert(InternetDomainName.isValid(hostname))
}

test("classpath and extra java options get translated into environment variables") {
baseConf.set(config.EXECUTOR_JAVA_OPTIONS, "foo=bar")
baseConf.set(config.EXECUTOR_CLASS_PATH, "bar=baz")
Expand Down