-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-36039][K8S] Fix executor pod hadoop conf mount #33257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ab865a7
Add hadoop conf executor feature step to kubernetes executor builder
cutiechi 61c9372
Add hadoop conf executor feature step to kubernetes executor builder …
cutiechi 2a91196
Fix executor pod hadoop conf config map create
cutiechi daee42b
Fix executor pod create or replace NPE
cutiechi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
...e/src/main/scala/org/apache/spark/deploy/k8s/features/HadoopConfExecutorFeatureStep.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /* | ||
| * 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.features | ||
|
|
||
| import java.io.File | ||
| import java.nio.charset.StandardCharsets | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import com.google.common.io.Files | ||
| import io.fabric8.kubernetes.api.model._ | ||
|
|
||
| import org.apache.spark.deploy.k8s.{KubernetesConf, KubernetesUtils, SparkPod} | ||
| import org.apache.spark.deploy.k8s.Config._ | ||
| import org.apache.spark.deploy.k8s.Constants._ | ||
|
|
||
| /** | ||
| * Mounts the Hadoop configuration - either a pre-defined config map, or a local configuration | ||
| * directory - on the executor pod. | ||
| */ | ||
| private[spark] class HadoopConfExecutorFeatureStep(conf: KubernetesConf) | ||
| extends KubernetesFeatureConfigStep { | ||
|
|
||
| private val confDir = Option(conf.sparkConf.getenv(ENV_HADOOP_CONF_DIR)) | ||
| private val existingConfMap = conf.get(KUBERNETES_HADOOP_CONF_CONFIG_MAP) | ||
|
|
||
| KubernetesUtils.requireNandDefined( | ||
| confDir, | ||
| existingConfMap, | ||
| "Do not specify both the `HADOOP_CONF_DIR` in your ENV and the ConfigMap " + | ||
| "as the creation of an additional ConfigMap, when one is already specified is extraneous") | ||
|
|
||
| private lazy val confFiles: Seq[File] = { | ||
| val dir = new File(confDir.get) | ||
| if (dir.isDirectory) { | ||
| dir.listFiles.filter(_.isFile).toSeq | ||
| } else { | ||
| Nil | ||
| } | ||
| } | ||
|
|
||
| private def newConfigMapName: String = s"${conf.resourceNamePrefix}-hadoop-config" | ||
|
|
||
| private def hasHadoopConf: Boolean = confDir.isDefined || existingConfMap.isDefined | ||
|
|
||
| override def configurePod(original: SparkPod): SparkPod = { | ||
| original.transform { case pod if hasHadoopConf => | ||
| val confVolume = if (confDir.isDefined) { | ||
| val keyPaths = confFiles.map { file => | ||
| new KeyToPathBuilder() | ||
| .withKey(file.getName()) | ||
| .withPath(file.getName()) | ||
| .build() | ||
| } | ||
| new VolumeBuilder() | ||
| .withName(HADOOP_CONF_VOLUME) | ||
| .withNewConfigMap() | ||
| .withName(newConfigMapName) | ||
| .withItems(keyPaths.asJava) | ||
| .endConfigMap() | ||
| .build() | ||
| } else { | ||
| new VolumeBuilder() | ||
| .withName(HADOOP_CONF_VOLUME) | ||
| .withNewConfigMap() | ||
| .withName(existingConfMap.get) | ||
| .endConfigMap() | ||
| .build() | ||
| } | ||
|
|
||
| val podWithConf = new PodBuilder(pod.pod) | ||
| .editSpec() | ||
| .addNewVolumeLike(confVolume) | ||
| .endVolume() | ||
| .endSpec() | ||
| .build() | ||
|
|
||
| val containerWithMount = new ContainerBuilder(pod.container) | ||
| .addNewVolumeMount() | ||
| .withName(HADOOP_CONF_VOLUME) | ||
| .withMountPath(HADOOP_CONF_DIR_PATH) | ||
| .endVolumeMount() | ||
| .addNewEnv() | ||
| .withName(ENV_HADOOP_CONF_DIR) | ||
| .withValue(HADOOP_CONF_DIR_PATH) | ||
| .endEnv() | ||
| .build() | ||
|
|
||
| SparkPod(podWithConf, containerWithMount) | ||
| } | ||
| } | ||
|
|
||
| override def getAdditionalKubernetesResources(): Seq[HasMetadata] = { | ||
| if (confDir.isDefined) { | ||
| val fileMap = confFiles.map { file => | ||
| (file.getName(), Files.toString(file, StandardCharsets.UTF_8)) | ||
| }.toMap.asJava | ||
|
|
||
| Seq(new ConfigMapBuilder() | ||
| .withNewMetadata() | ||
| .withName(newConfigMapName) | ||
| .endMetadata() | ||
| .withImmutable(true) | ||
| .addToData(fileMap) | ||
| .build()) | ||
| } else { | ||
| Nil | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
.../test/scala/org/apache/spark/deploy/k8s/features/HadoopConfExecutorFeatureStepSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * 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.features | ||
|
|
||
| import java.io.File | ||
| import java.nio.charset.StandardCharsets.UTF_8 | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import com.google.common.io.Files | ||
| import io.fabric8.kubernetes.api.model.ConfigMap | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkFunSuite} | ||
| import org.apache.spark.deploy.k8s._ | ||
| import org.apache.spark.deploy.k8s.Constants._ | ||
| import org.apache.spark.util.{SparkConfWithEnv, Utils} | ||
|
|
||
| class HadoopConfExecutorFeatureStepSuite extends SparkFunSuite { | ||
|
|
||
| import KubernetesFeaturesTestUtils._ | ||
| import SecretVolumeUtils._ | ||
|
|
||
| test("mount hadoop config map if defined") { | ||
| val sparkConf = new SparkConf(false) | ||
| .set(Config.KUBERNETES_HADOOP_CONF_CONFIG_MAP, "testConfigMap") | ||
| val conf = KubernetesTestConf.createExecutorConf(sparkConf = sparkConf) | ||
| val step = new HadoopConfExecutorFeatureStep(conf) | ||
| checkPod(step.configurePod(SparkPod.initialPod())) | ||
| assert(step.getAdditionalKubernetesResources().isEmpty) | ||
| } | ||
|
|
||
| test("create hadoop config map if config dir is defined") { | ||
| val confDir = Utils.createTempDir() | ||
| val confFiles = Set("core-site.xml", "hdfs-site.xml") | ||
|
|
||
| confFiles.foreach { f => | ||
| Files.write("some data", new File(confDir, f), UTF_8) | ||
| } | ||
|
|
||
| val sparkConf = new SparkConfWithEnv(Map(ENV_HADOOP_CONF_DIR -> confDir.getAbsolutePath())) | ||
| val conf = KubernetesTestConf.createExecutorConf(sparkConf = sparkConf) | ||
|
|
||
| val step = new HadoopConfExecutorFeatureStep(conf) | ||
| checkPod(step.configurePod(SparkPod.initialPod())) | ||
|
|
||
| val hadoopConfMap = filter[ConfigMap](step.getAdditionalKubernetesResources()).head | ||
| assert(hadoopConfMap.getData().keySet().asScala === confFiles) | ||
| } | ||
|
|
||
| private def checkPod(pod: SparkPod): Unit = { | ||
| assert(podHasVolume(pod.pod, HADOOP_CONF_VOLUME)) | ||
| assert(containerHasVolume(pod.container, HADOOP_CONF_VOLUME, HADOOP_CONF_DIR_PATH)) | ||
| assert(containerHasEnvVar(pod.container, ENV_HADOOP_CONF_DIR)) | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.