-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-54605][K8S] Override default spark env in driver pod #53338
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,9 @@ import io.fabric8.kubernetes.api.model.{ConfigMap, ConfigMapBuilder, KeyToPath} | |
|
|
||
| import org.apache.spark.SparkConf | ||
| import org.apache.spark.annotation.{DeveloperApi, Since, Unstable} | ||
| import org.apache.spark.deploy.k8s.{Config, Constants, KubernetesUtils} | ||
| import org.apache.spark.deploy.k8s.{Config, Constants, KubernetesDriverConf, KubernetesUtils} | ||
| import org.apache.spark.deploy.k8s.Config.{KUBERNETES_DNS_SUBDOMAIN_NAME_MAX_LENGTH, KUBERNETES_NAMESPACE} | ||
| import org.apache.spark.deploy.k8s.Constants.ENV_SPARK_CONF_DIR | ||
| import org.apache.spark.deploy.k8s.Constants.{ENV_SPARK_CONF_DIR, SPARK_ENV_FILE_NAME} | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.internal.LogKeys.{CONFIG, PATH, PATHS} | ||
| import org.apache.spark.util.ArrayImplicits._ | ||
|
|
@@ -116,6 +116,31 @@ object KubernetesClientUtils extends Logging { | |
| }.toList.sortBy(x => x.getKey) // List is sorted to make mocking based tests work | ||
| } | ||
|
|
||
| @Since("4.2.0") | ||
| def overrideDefaultSparkEnv(conf: KubernetesDriverConf, | ||
| confFilesMap: Map[String, String]): Map[String, String] = { | ||
| if (conf.environment.isEmpty) { | ||
| return confFilesMap | ||
| } | ||
| val customEnvs = conf.environment.map { | ||
| case (k, v) => s"export $k=$v" | ||
| }.mkString("\n", "\n", "\n") | ||
| val mapSize = confFilesMap.map { | ||
| case (k, v) => k.length + v.length | ||
| }.sum | ||
| val maxSize = conf.sparkConf.get(Config.CONFIG_MAP_MAXSIZE) | ||
| if (mapSize + customEnvs.length < maxSize) { | ||
| confFilesMap ++ Map(SPARK_ENV_FILE_NAME -> | ||
| s"${confFilesMap.getOrElse(SPARK_ENV_FILE_NAME, "")}$customEnvs") | ||
| } else { | ||
| logWarning(log"Skipped custom driver env, due to size constraint" + | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to introduce unsafe behavior to the Spark. Previously, we didn't fail?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this! You're absolutely right - the original behavior didn't fail when it should have. I agree this introduces unsafe behavior. To address this, I've submitted a separate PR that adds proper validation: Could you please review this new fix when you have a moment? Would love to hear your thoughts! |
||
| log" Please see, config: `${MDC(CONFIG, Config.CONFIG_MAP_MAXSIZE.key)}`" + | ||
| log" for more details.") | ||
| confFilesMap | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Build a ConfigMap that will hold the content for environment variable SPARK_CONF_DIR | ||
| * on remote pods. (Java-friendly) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From Apache Spark 4.1.0, we need to provide a Java-friendly version together like the following.