Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.
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 @@ -183,7 +183,8 @@ private[spark] class DriverConfigurationStepsOrchestrator(
allDriverLabels,
initContainerConfigMapName,
INIT_CONTAINER_CONFIG_MAP_KEY,
submissionSparkConf)
submissionSparkConf,
hadoopConfDir.isDefined)
val initContainerConfigurationSteps =
initContainerConfigurationStepsOrchestrator.getAllConfigurationSteps()
Some(new InitContainerBootstrapStep(initContainerConfigurationSteps,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.spark.deploy.k8s.submit

import io.fabric8.kubernetes.api.model.{Container, ContainerBuilder}

import org.apache.spark.deploy.k8s.constants._

/**
* Bootstraps a container with hadoop conf mounted.
*/
private[spark] trait MountHadoopConfStep {
/**
* Mount hadoop conf into the given container.
*
* @param container the container into which volumes are being mounted.
* @return the updated container with hadoop conf volumes mounted.
*/
def mountHadoopConf(container: Container): Container
}

private[spark] class MountHadoopConfStepImpl extends MountHadoopConfStep {
def mountHadoopConf(container: Container): Container = {
new ContainerBuilder(container)
.addNewVolumeMount()
.withName(HADOOP_FILE_VOLUME)
.withMountPath(HADOOP_CONF_DIR_PATH)
.endVolumeMount()
.addNewEnv()
.withName(ENV_HADOOP_CONF_DIR)
.withValue(HADOOP_CONF_DIR_PATH)
.endEnv()
.build()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.apache.spark.SparkConf
import org.apache.spark.deploy.k8s.{ConfigurationUtils, InitContainerResourceStagingServerSecretPluginImpl, OptionRequirements, SparkPodInitContainerBootstrapImpl}
import org.apache.spark.deploy.k8s.config._
import org.apache.spark.deploy.k8s.constants._
import org.apache.spark.deploy.k8s.submit.{KubernetesFileUtils, MountSecretsBootstrapImpl, SubmittedDependencyUploaderImpl}
import org.apache.spark.deploy.k8s.submit.{KubernetesFileUtils, MountHadoopConfStepImpl, MountSecretsBootstrapImpl, SubmittedDependencyUploaderImpl}
import org.apache.spark.deploy.rest.k8s.{ResourceStagingServerSslOptionsProviderImpl, RetrofitClientFactoryImpl}
import org.apache.spark.util.Utils

Expand All @@ -38,7 +38,8 @@ private[spark] class InitContainerConfigurationStepsOrchestrator(
driverLabels: Map[String, String],
initContainerConfigMapName: String,
initContainerConfigMapKey: String,
submissionSparkConf: SparkConf) {
submissionSparkConf: SparkConf,
hadoopConfEnabled: Boolean = false) {

private val submittedResourcesSecretName = s"$kubernetesResourceNamePrefix-init-secret"
private val resourceStagingServerUri = submissionSparkConf.get(RESOURCE_STAGING_SERVER_URI)
Expand Down Expand Up @@ -146,8 +147,16 @@ private[spark] class InitContainerConfigurationStepsOrchestrator(
None
}

val mountHadoopConfStep = if (hadoopConfEnabled) {
val mountHadoopConfStep = new MountHadoopConfStepImpl
Some(new InitContainerMountHadoopConfStep(mountHadoopConfStep))
} else {
None
}

Seq(baseInitContainerStep) ++
submittedResourcesInitContainerStep.toSeq ++
mountSecretsStep.toSeq
mountSecretsStep.toSeq ++
mountHadoopConfStep.toSeq
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.spark.deploy.k8s.submit.submitsteps.initcontainer

import org.apache.spark.deploy.k8s.submit.MountHadoopConfStep

/**
* An init-container configuration step for mounting hadoop conf files onto HADOOP_CONF_DIR_PATH.
*/
private[spark] class InitContainerMountHadoopConfStep(
mountHadoopConfStep: MountHadoopConfStep) extends InitContainerConfigurationStep {
override def configureInitContainer(initContainerSpec: InitContainerSpec) : InitContainerSpec = {
val initContainerWithHadoopConfMounted = mountHadoopConfStep.mountHadoopConf(
initContainerSpec.initContainer)
initContainerSpec.copy(
initContainer = initContainerWithHadoopConfMounted
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.apache.spark.{SparkConf, SparkException}
import org.apache.spark.deploy.k8s.{ConfigurationUtils, HadoopConfBootstrap, HadoopConfSparkUserBootstrap, InitContainerResourceStagingServerSecretPlugin, KerberosTokenConfBootstrap, PodWithDetachedInitContainer, PodWithMainContainer, SparkPodInitContainerBootstrap}
import org.apache.spark.deploy.k8s.config._
import org.apache.spark.deploy.k8s.constants._
import org.apache.spark.deploy.k8s.submit.{InitContainerUtil, MountSecretsBootstrap, MountSmallFilesBootstrap}
import org.apache.spark.deploy.k8s.submit.{InitContainerUtil, MountHadoopConfStep, MountSecretsBootstrap, MountSmallFilesBootstrap}
import org.apache.spark.util.Utils

// Configures executor pods. Construct one of these with a SparkConf to set up properties that are
Expand All @@ -47,6 +47,7 @@ private[spark] class ExecutorPodFactoryImpl(
executorInitContainerBootstrap: Option[SparkPodInitContainerBootstrap],
executorInitContainerMountSecretsBootstrap: Option[MountSecretsBootstrap],
executorMountInitContainerSecretPlugin: Option[InitContainerResourceStagingServerSecretPlugin],
executorInitContainerMountHadoopConfBootstrap: Option[MountHadoopConfStep],
executorLocalDirVolumeProvider: ExecutorLocalDirVolumeProvider,
hadoopBootStrap: Option[HadoopConfBootstrap],
kerberosBootstrap: Option[KerberosTokenConfBootstrap],
Expand Down Expand Up @@ -256,10 +257,16 @@ private[spark] class ExecutorPodFactoryImpl(
podWithDetachedInitContainer.initContainer)
}.getOrElse(podWithDetachedInitContainer.initContainer)

val maybeInitContainerWithHadoopConfMounted =
executorInitContainerMountHadoopConfBootstrap.map { bootstrap =>
bootstrap.mountHadoopConf(resolvedInitContainer)
}.getOrElse(resolvedInitContainer)

val (mayBePodWithSecretsMountedToInitContainer, mayBeInitContainerWithSecretsMounted) =
executorInitContainerMountSecretsBootstrap.map { bootstrap =>
bootstrap.mountSecrets(podWithDetachedInitContainer.pod, resolvedInitContainer)
}.getOrElse(podWithDetachedInitContainer.pod, resolvedInitContainer)
bootstrap.mountSecrets(podWithDetachedInitContainer.pod,
maybeInitContainerWithHadoopConfMounted)
}.getOrElse(podWithDetachedInitContainer.pod, maybeInitContainerWithHadoopConfMounted)

val podWithAttachedInitContainer = InitContainerUtil.appendInitContainer(
mayBePodWithSecretsMountedToInitContainer, mayBeInitContainerWithSecretsMounted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.apache.spark.SparkContext
import org.apache.spark.deploy.k8s.{ConfigurationUtils, HadoopConfBootstrapImpl, HadoopConfSparkUserBootstrapImpl, HadoopUGIUtilImpl, InitContainerResourceStagingServerSecretPluginImpl, KerberosTokenConfBootstrapImpl, SparkKubernetesClientFactory, SparkPodInitContainerBootstrapImpl}
import org.apache.spark.deploy.k8s.config._
import org.apache.spark.deploy.k8s.constants._
import org.apache.spark.deploy.k8s.submit.{MountSecretsBootstrapImpl, MountSmallFilesBootstrapImpl}
import org.apache.spark.deploy.k8s.submit.{MountHadoopConfStepImpl, MountSecretsBootstrapImpl, MountSmallFilesBootstrapImpl}
import org.apache.spark.internal.Logging
import org.apache.spark.network.netty.SparkTransportConf
import org.apache.spark.network.shuffle.kubernetes.KubernetesExternalShuffleClientImpl
Expand Down Expand Up @@ -135,6 +135,11 @@ private[spark] class KubernetesClusterManager extends ExternalClusterManager wit
} else {
None
}
val executorInitContainerMountHadoopConfBootstrap = if (hadoopBootStrap.isDefined) {
Some(new MountHadoopConfStepImpl)
} else {
None
}

if (maybeInitContainerConfigMap.isEmpty) {
logWarning("The executor's init-container config map was not specified. Executors will" +
Expand Down Expand Up @@ -181,6 +186,7 @@ private[spark] class KubernetesClusterManager extends ExternalClusterManager wit
executorInitContainerBootstrap,
executorInitContainerMountSecretsBootstrap,
executorInitContainerSecretVolumePlugin,
executorInitContainerMountHadoopConfBootstrap,
executorLocalDirVolumeProvider,
hadoopBootStrap,
kerberosBootstrap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef
None,
None,
None,
None,
executorLocalDirVolumeProvider,
None,
None,
Expand Down Expand Up @@ -133,6 +134,7 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef
None,
None,
None,
None,
executorLocalDirVolumeProvider,
None,
None,
Expand All @@ -158,6 +160,7 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef
None,
None,
None,
None,
executorLocalDirVolumeProvider,
None,
None,
Expand Down Expand Up @@ -196,6 +199,7 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef
Some(initContainerBootstrap),
None,
None,
None,
executorLocalDirVolumeProvider,
None,
None,
Expand Down Expand Up @@ -226,6 +230,7 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef
Some(initContainerBootstrap),
Some(secretsBootstrap),
None,
None,
executorLocalDirVolumeProvider,
None,
None,
Expand Down Expand Up @@ -265,6 +270,7 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef
None,
None,
None,
None,
executorLocalDirVolumeProvider,
None,
None,
Expand All @@ -289,6 +295,7 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef
None,
None,
None,
None,
executorLocalDirVolumeProvider,
None,
None,
Expand Down Expand Up @@ -326,6 +333,7 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef
None,
None,
None,
None,
executorLocalDirVolumeProvider,
None,
None,
Expand Down Expand Up @@ -362,6 +370,7 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef
None,
None,
None,
None,
executorLocalDirVolumeProvider,
Some(hadoopBootsrap),
None,
Expand Down Expand Up @@ -400,6 +409,7 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef
None,
None,
None,
None,
executorLocalDirVolumeProvider,
Some(hadoopBootstrap),
None,
Expand Down Expand Up @@ -444,6 +454,7 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef
None,
None,
None,
None,
executorLocalDirVolumeProvider,
Some(hadoopBootstrap),
Some(kerberosBootstrap),
Expand Down