Skip to content

Commit 7190f93

Browse files
committed
add ut
1 parent f881767 commit 7190f93

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
import org.scalatest.BeforeAndAfter
25+
26+
import org.apache.spark.{SparkConf, SparkFunSuite}
27+
import org.apache.spark.deploy.k8s.{KubernetesExecutorConf, KubernetesTestConf, SecretVolumeUtils, SparkPod}
28+
import org.apache.spark.deploy.k8s.Constants._
29+
import org.apache.spark.deploy.k8s.features.KubernetesFeaturesTestUtils.containerHasEnvVar
30+
import org.apache.spark.util.{SparkConfWithEnv, Utils}
31+
32+
class HadoopConfExecutorFeatureStepSuite extends SparkFunSuite with BeforeAndAfter {
33+
import SecretVolumeUtils._
34+
35+
private var baseConf: SparkConf = _
36+
37+
before {
38+
baseConf = new SparkConf(false)
39+
}
40+
41+
private def newExecutorConf(environment: Map[String, String] = Map.empty):
42+
KubernetesExecutorConf = {
43+
KubernetesTestConf.createExecutorConf(
44+
sparkConf = baseConf,
45+
environment = environment)
46+
}
47+
48+
test("SPARK-43504: mount hadoop config map in executor side") {
49+
val confDir = Utils.createTempDir()
50+
val confFiles = Set("core-site.xml", "hdfs-site.xml")
51+
52+
confFiles.foreach { f =>
53+
Files.write("some data", new File(confDir, f), UTF_8)
54+
}
55+
56+
val sparkConf = new SparkConfWithEnv(Map(ENV_HADOOP_CONF_DIR -> confDir.getAbsolutePath()))
57+
val conf = KubernetesTestConf.createDriverConf(sparkConf = sparkConf)
58+
59+
val driverStep = new HadoopConfDriverFeatureStep(conf)
60+
driverStep.getAdditionalPodSystemProperties().foreach { case (key, value) =>
61+
baseConf.set(key, value)
62+
}
63+
64+
val executorStep = new HadoopConfExecutorFeatureStep(newExecutorConf())
65+
val executorPod = executorStep.configurePod(SparkPod.initialPod())
66+
67+
assert(podHasVolume(executorPod.pod, HADOOP_CONF_VOLUME))
68+
assert(containerHasVolume(executorPod.container, HADOOP_CONF_VOLUME, HADOOP_CONF_DIR_PATH))
69+
assert(containerHasEnvVar(executorPod.container, ENV_HADOOP_CONF_DIR))
70+
}
71+
}

0 commit comments

Comments
 (0)