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
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private[spark] class KubernetesDriverConf(

override def annotations: Map[String, String] = {
KubernetesUtils.parsePrefixedKeyValuePairs(sparkConf, KUBERNETES_DRIVER_ANNOTATION_PREFIX)
.map { case (k, v) => (k, Utils.substituteAppNExecIds(v, appId, "")) }
}

def serviceLabels: Map[String, String] = {
Expand Down Expand Up @@ -188,6 +189,7 @@ private[spark] class KubernetesExecutorConf(

override def annotations: Map[String, String] = {
KubernetesUtils.parsePrefixedKeyValuePairs(sparkConf, KUBERNETES_EXECUTOR_ANNOTATION_PREFIX)
.map { case(k, v) => (k, Utils.substituteAppNExecIds(v, appId, executorId)) }
}

override def secretNamesToMountPaths: Map[String, String] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ private[spark] class BasicDriverFeatureStep(conf: KubernetesDriverConf)
.editOrNewMetadata()
.withName(driverPodName)
.addToLabels(conf.labels.asJava)
.addToAnnotations(conf.annotations.map { case (k, v) =>
(k, Utils.substituteAppNExecIds(v, conf.appId, "")) }.asJava)
.addToAnnotations(conf.annotations.asJava)
.endMetadata()
.editOrNewSpec()
.withRestartPolicy("Never")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,12 @@ private[spark] class BasicExecutorFeatureStep(
case "statefulset" => "Always"
case _ => "Never"
}
val annotations = kubernetesConf.annotations.map { case (k, v) =>
(k, Utils.substituteAppNExecIds(v, kubernetesConf.appId, kubernetesConf.executorId))
}

val executorPodBuilder = new PodBuilder(pod.pod)
.editOrNewMetadata()
.withName(name)
.addToLabels(kubernetesConf.labels.asJava)
.addToAnnotations(annotations.asJava)
.addToAnnotations(kubernetesConf.annotations.asJava)
.addToOwnerReferences(ownerReference.toSeq: _*)
.endMetadata()
.editOrNewSpec()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.apache.spark.deploy.k8s.Config._
import org.apache.spark.deploy.k8s.Constants._
import org.apache.spark.deploy.k8s.submit._
import org.apache.spark.resource.ResourceProfile.DEFAULT_RESOURCE_PROFILE_ID
import org.apache.spark.util.Utils

class KubernetesConfSuite extends SparkFunSuite {

Expand All @@ -42,7 +43,9 @@ class KubernetesConfSuite extends SparkFunSuite {
"customLabel2Key" -> "customLabel2Value")
private val CUSTOM_ANNOTATIONS = Map(
"customAnnotation1Key" -> "customAnnotation1Value",
"customAnnotation2Key" -> "customAnnotation2Value")
"customAnnotation2Key" -> "customAnnotation2Value",
"customAnnotation3Key" -> "{{APP_ID}}",
"customAnnotation4Key" -> "{{EXECUTOR_ID}}")
private val SECRET_NAMES_TO_MOUNT_PATHS = Map(
"secret1" -> "/mnt/secrets/secret1",
"secret2" -> "/mnt/secrets/secret2")
Expand Down Expand Up @@ -93,7 +96,9 @@ class KubernetesConfSuite extends SparkFunSuite {
SPARK_APP_NAME_LABEL -> KubernetesConf.getAppNameLabel(conf.appName),
SPARK_ROLE_LABEL -> SPARK_POD_DRIVER_ROLE) ++
CUSTOM_LABELS)
assert(conf.annotations === CUSTOM_ANNOTATIONS)
assert(conf.annotations === CUSTOM_ANNOTATIONS.map {
case (k, v) => (k, Utils.substituteAppNExecIds(v, conf.appId, ""))
})
assert(conf.secretNamesToMountPaths === SECRET_NAMES_TO_MOUNT_PATHS)
assert(conf.secretEnvNamesToKeyRefs === SECRET_ENV_VARS)
assert(conf.environment === CUSTOM_ENVS)
Expand Down Expand Up @@ -161,7 +166,9 @@ class KubernetesConfSuite extends SparkFunSuite {
SPARK_APP_NAME_LABEL -> KubernetesConf.getAppNameLabel(conf.appName),
SPARK_ROLE_LABEL -> SPARK_POD_EXECUTOR_ROLE,
SPARK_RESOURCE_PROFILE_ID_LABEL -> DEFAULT_RESOURCE_PROFILE_ID.toString) ++ CUSTOM_LABELS)
assert(conf.annotations === CUSTOM_ANNOTATIONS)
assert(conf.annotations === CUSTOM_ANNOTATIONS.map {
case (k, v) => (k, Utils.substituteAppNExecIds(v, conf.appId, EXECUTOR_ID))
})
assert(conf.secretNamesToMountPaths === SECRET_NAMES_TO_MOUNT_PATHS)
assert(conf.secretEnvNamesToKeyRefs === SECRET_ENV_VARS)
}
Expand Down