Skip to content

Commit

Permalink
[SPARK-48077][K8S] Promote KubernetesClientUtils to DeveloperApi
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

This PR aims to promote `KubernetesClientUtils` to `DeveloperApi`.

### Why are the changes needed?

Since `Apache Spark Kubernetes Operator` requires this, we had better maintain it as a developer API officially from `Apache Spark 4.0.0`.
- apache/spark-kubernetes-operator#10

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #46327 from dongjoon-hyun/SPARK-48077.

Authored-by: Dongjoon Hyun <dhyun@apple.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
  • Loading branch information
dongjoon-hyun committed May 2, 2024
1 parent 0fc7c4a commit a42eef9
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,34 @@ import scala.jdk.CollectionConverters._
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.{KUBERNETES_DNS_SUBDOMAIN_NAME_MAX_LENGTH, KUBERNETES_NAMESPACE}
import org.apache.spark.deploy.k8s.Constants.ENV_SPARK_CONF_DIR
import org.apache.spark.internal.{Logging, MDC}
import org.apache.spark.internal.LogKeys.{CONFIG, PATH, PATHS}
import org.apache.spark.util.ArrayImplicits._

private[spark] object KubernetesClientUtils extends Logging {
/**
* :: DeveloperApi ::
*
* A utility class used for K8s operations internally and Spark K8s operator.
*/
@Unstable
@DeveloperApi
object KubernetesClientUtils extends Logging {

// Config map name can be KUBERNETES_DNS_SUBDOMAIN_NAME_MAX_LENGTH chars at max.
@Since("3.3.0")
def configMapName(prefix: String): String = {
val suffix = "-conf-map"
s"${prefix.take(KUBERNETES_DNS_SUBDOMAIN_NAME_MAX_LENGTH - suffix.length)}$suffix"
}

@Since("3.1.0")
val configMapNameExecutor: String = configMapName(s"spark-exec-${KubernetesUtils.uniqueID()}")

@Since("3.1.0")
val configMapNameDriver: String = configMapName(s"spark-drv-${KubernetesUtils.uniqueID()}")

private def buildStringFromPropertiesMap(configMapName: String,
Expand All @@ -62,6 +73,7 @@ private[spark] object KubernetesClientUtils extends Logging {
/**
* Build, file -> 'file's content' map of all the selected files in SPARK_CONF_DIR.
*/
@Since("3.1.1")
def buildSparkConfDirFilesMap(
configMapName: String,
sparkConf: SparkConf,
Expand All @@ -77,6 +89,7 @@ private[spark] object KubernetesClientUtils extends Logging {
}
}

@Since("3.1.0")
def buildKeyToPathObjects(confFilesMap: Map[String, String]): Seq[KeyToPath] = {
confFilesMap.map {
case (fileName: String, _: String) =>
Expand All @@ -89,6 +102,7 @@ private[spark] object KubernetesClientUtils extends Logging {
* Build a Config Map that will hold the content for environment variable SPARK_CONF_DIR
* on remote pods.
*/
@Since("3.1.0")
def buildConfigMap(configMapName: String, confFileMap: Map[String, String],
withLabels: Map[String, String] = Map()): ConfigMap = {
val configMapNameSpace =
Expand Down

0 comments on commit a42eef9

Please sign in to comment.