Skip to content

Commit b2f4c27

Browse files
authored
[SPARK-25200][YARN] Allow specifying HADOOP_CONF_DIR as spark property (apache-spark-on-k8s#410)
1 parent c26bd93 commit b2f4c27

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

core/src/main/scala/org/apache/spark/deploy/SparkSubmitArguments.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,11 @@ private[deploy] class SparkSubmitArguments(args: Seq[String], env: Map[String, S
286286

287287
if (master.startsWith("yarn")) {
288288
val hasHadoopEnv = env.contains("HADOOP_CONF_DIR") || env.contains("YARN_CONF_DIR")
289-
if (!hasHadoopEnv && !Utils.isTesting) {
289+
val hasHadoopProp = sparkProperties.contains("spark.yarn.conf.dir")
290+
if (!hasHadoopEnv && !hasHadoopProp && !Utils.isTesting) {
290291
error(s"When running with master '$master' " +
291-
"either HADOOP_CONF_DIR or YARN_CONF_DIR must be set in the environment.")
292+
"either HADOOP_CONF_DIR or YARN_CONF_DIR must be set in the environment, +" +
293+
"or spark.yarn.conf.dir in the spark properties.")
292294
}
293295
}
294296

launcher/src/main/java/org/apache/spark/launcher/AbstractCommandBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ List<String> buildClassPath(String appClassPath) throws IOException {
200200

201201
addToClassPath(cp, getenv("HADOOP_CONF_DIR"));
202202
addToClassPath(cp, getenv("YARN_CONF_DIR"));
203+
addToClassPath(cp, getEffectiveConfig().get("spark.yarn.conf.dir"));
203204
addToClassPath(cp, getenv("SPARK_DIST_CLASSPATH"));
204205
return new ArrayList<>(cp);
205206
}

resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -697,21 +697,21 @@ private[spark] class Client(
697697
// SPARK-23630: during testing, Spark scripts filter out hadoop conf dirs so that user's
698698
// environments do not interfere with tests. This allows a special env variable during
699699
// tests so that custom conf dirs can be used by unit tests.
700-
val confDirs = Seq("HADOOP_CONF_DIR", "YARN_CONF_DIR") ++
701-
(if (Utils.isTesting) Seq("SPARK_TEST_HADOOP_CONF_DIR") else Nil)
702-
703-
confDirs.foreach { envKey =>
704-
sys.env.get(envKey).foreach { path =>
705-
val dir = new File(path)
706-
if (dir.isDirectory()) {
707-
val files = dir.listFiles()
708-
if (files == null) {
709-
logWarning("Failed to list files under directory " + dir)
710-
} else {
711-
files.foreach { file =>
712-
if (file.isFile && !hadoopConfFiles.contains(file.getName())) {
713-
hadoopConfFiles(file.getName()) = file
714-
}
700+
val confDirs = Seq("HADOOP_CONF_DIR", "YARN_CONF_DIR").map(sys.env.get)
701+
val confDirProp = sparkConf.getOption("spark.yarn.conf.dir")
702+
703+
val confDirPaths = (confDirs :+ confDirProp).flatten
704+
confDirPaths.foreach { path =>
705+
logDebug("Reading config files from " + path)
706+
val dir = new File(path)
707+
if (dir.isDirectory) {
708+
val files = dir.listFiles()
709+
if (files == null) {
710+
logWarning("Failed to list files under directory " + dir)
711+
} else {
712+
files.foreach { file =>
713+
if (file.isFile && !hadoopConfFiles.contains(file.getName)) {
714+
hadoopConfFiles(file.getName) = file
715715
}
716716
}
717717
}

resource-managers/yarn/src/test/scala/org/apache/spark/deploy/yarn/YarnClusterSuite.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ class YarnClusterSuite extends BaseYarnClusterSuite {
168168
val finalState = runSpark(false,
169169
mainClassName(YarnClusterDriverUseSparkHadoopUtilConf.getClass),
170170
appArgs = Seq("key=value", "spark.test.key=testvalue", result.getAbsolutePath()),
171-
extraConf = Map("spark.hadoop.key" -> "value"),
172-
extraEnv = Map("SPARK_TEST_HADOOP_CONF_DIR" -> customConf.getAbsolutePath()))
171+
extraConf = Map(
172+
"spark.hadoop.key" -> "value",
173+
"spark.yarn.conf.dir" -> customConf.getAbsolutePath))
173174
checkResult(finalState, result)
174175
}
175176

0 commit comments

Comments
 (0)