|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.spark.deploy.k8s.features |
| 19 | + |
| 20 | +import java.io.File |
| 21 | +import java.nio.charset.StandardCharsets.UTF_8 |
| 22 | + |
| 23 | +import com.google.common.io.Files |
| 24 | + |
| 25 | +import org.apache.spark.{SparkConf, SparkFunSuite} |
| 26 | +import org.apache.spark.deploy.k8s.{Constants, KubernetesTestConf, SecretVolumeUtils, SparkPod} |
| 27 | +import org.apache.spark.deploy.k8s.Constants._ |
| 28 | +import org.apache.spark.deploy.k8s.features.KubernetesFeaturesTestUtils.containerHasEnvVar |
| 29 | +import org.apache.spark.util.{SparkConfWithEnv, Utils} |
| 30 | + |
| 31 | +class HadoopConfExecutorFeatureStepSuite extends SparkFunSuite { |
| 32 | + import SecretVolumeUtils._ |
| 33 | + |
| 34 | + test("SPARK-43504: mounts the hadoop config map on the executor pod") { |
| 35 | + val confDir = Utils.createTempDir() |
| 36 | + val confFiles = Set("core-site.xml", "hdfs-site.xml") |
| 37 | + |
| 38 | + confFiles.foreach { f => |
| 39 | + Files.write("some data", new File(confDir, f), UTF_8) |
| 40 | + } |
| 41 | + |
| 42 | + Seq( |
| 43 | + Map(ENV_HADOOP_CONF_DIR -> confDir.getAbsolutePath()), |
| 44 | + Map.empty[String, String]).foreach { env => |
| 45 | + val hasHadoopConf = env.contains(ENV_HADOOP_CONF_DIR) |
| 46 | + |
| 47 | + val driverSparkConf = new SparkConfWithEnv(env) |
| 48 | + val executorSparkConf = new SparkConf(false) |
| 49 | + |
| 50 | + val driverConf = KubernetesTestConf.createDriverConf(sparkConf = driverSparkConf) |
| 51 | + val driverStep = new HadoopConfDriverFeatureStep(driverConf) |
| 52 | + |
| 53 | + val additionalPodSystemProperties = driverStep.getAdditionalPodSystemProperties() |
| 54 | + if (hasHadoopConf) { |
| 55 | + assert(additionalPodSystemProperties.contains(Constants.HADOOP_CONFIG_MAP_NAME)) |
| 56 | + additionalPodSystemProperties.foreach { case (key, value) => |
| 57 | + executorSparkConf.set(key, value) |
| 58 | + } |
| 59 | + } else { |
| 60 | + assert(additionalPodSystemProperties.isEmpty) |
| 61 | + } |
| 62 | + |
| 63 | + val executorConf = KubernetesTestConf.createExecutorConf(sparkConf = executorSparkConf) |
| 64 | + val executorStep = new HadoopConfExecutorFeatureStep(executorConf) |
| 65 | + val executorPod = executorStep.configurePod(SparkPod.initialPod()) |
| 66 | + |
| 67 | + checkPod(executorPod, hasHadoopConf) |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + private def checkPod(pod: SparkPod, hasHadoopConf: Boolean): Unit = { |
| 72 | + if (hasHadoopConf) { |
| 73 | + assert(podHasVolume(pod.pod, HADOOP_CONF_VOLUME)) |
| 74 | + assert(containerHasVolume(pod.container, HADOOP_CONF_VOLUME, HADOOP_CONF_DIR_PATH)) |
| 75 | + assert(containerHasEnvVar(pod.container, ENV_HADOOP_CONF_DIR)) |
| 76 | + } else { |
| 77 | + assert(!podHasVolume(pod.pod, HADOOP_CONF_VOLUME)) |
| 78 | + assert(!containerHasVolume(pod.container, HADOOP_CONF_VOLUME, HADOOP_CONF_DIR_PATH)) |
| 79 | + assert(!containerHasEnvVar(pod.container, ENV_HADOOP_CONF_DIR)) |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments