Skip to content

Commit 1f2fd80

Browse files
ash211foxish
authored andcommitted
Truncate k8s hostnames to be no longer than 63 characters (alteryx#102)
* Truncate k8s hostnames to be no longer than 63 characters * Use only executorId not executorKubernetesId
1 parent 3aba68a commit 1f2fd80

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/kubernetes/KubernetesClusterSchedulerBackend.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,14 @@ private[spark] class KubernetesClusterSchedulerBackend(
155155
}
156156

157157
private def allocateNewExecutorPod(): (String, Pod) = {
158-
val executorKubernetesId = UUID.randomUUID().toString.replaceAll("-", "")
159158
val executorId = EXECUTOR_ID_COUNTER.incrementAndGet().toString
160-
val name = s"${applicationId()}-exec-$executorKubernetesId"
159+
val name = s"${applicationId()}-exec-$executorId"
160+
161+
// hostname must be no longer than 63 characters, so take the last 63 characters of the pod
162+
// name as the hostname. This preserves uniqueness since the end of name contains
163+
// executorId and applicationId
164+
val hostname = name.substring(Math.max(0, name.length - 63))
165+
161166
val selectors = Map(SPARK_EXECUTOR_ID_LABEL -> executorId,
162167
SPARK_APP_ID_LABEL -> applicationId()).asJava
163168
val executorMemoryQuantity = new QuantityBuilder(false)
@@ -190,7 +195,7 @@ private[spark] class KubernetesClusterSchedulerBackend(
190195
.build()
191196
})
192197
try {
193-
(executorKubernetesId, kubernetesClient.pods().createNew()
198+
(executorId, kubernetesClient.pods().createNew()
194199
.withNewMetadata()
195200
.withName(name)
196201
.withLabels(selectors)
@@ -204,6 +209,7 @@ private[spark] class KubernetesClusterSchedulerBackend(
204209
.endOwnerReference()
205210
.endMetadata()
206211
.withNewSpec()
212+
.withHostname(hostname)
207213
.addNewContainer()
208214
.withName(s"executor")
209215
.withImage(executorDockerImage)

0 commit comments

Comments
 (0)