Github user tnachen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16061#discussion_r90063528
  
    --- Diff: 
kubernetes/src/main/scala/org/apache/spark/scheduler/cluster/kubernetes/KubernetesClusterScheduler.scala
 ---
    @@ -0,0 +1,236 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.scheduler.cluster.kubernetes
    +
    +import java.io.File
    +import java.util.Date
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import io.fabric8.kubernetes.client.{ConfigBuilder, 
DefaultKubernetesClient, KubernetesClient}
    +import io.fabric8.kubernetes.api.model.{PodBuilder, ServiceBuilder}
    +import io.fabric8.kubernetes.client.dsl.LogWatch
    +import org.apache.spark.deploy.Command
    +import org.apache.spark.deploy.kubernetes.ClientArguments
    +import org.apache.spark.{io, _}
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.internal.config._
    +
    +import collection.JavaConverters._
    +import org.apache.spark.util.Utils
    +
    +import scala.util.Random
    +
    +private[spark] object KubernetesClusterScheduler {
    +  def defaultNameSpace = "default"
    +  def defaultServiceAccountName = "default"
    +}
    +
    +/**
    +  * This is a simple extension to ClusterScheduler
    +  * */
    +private[spark] class KubernetesClusterScheduler(conf: SparkConf)
    +    extends Logging {
    +  private val DEFAULT_SUPERVISE = false
    +  private val DEFAULT_MEMORY = Utils.DEFAULT_DRIVER_MEM_MB // mb
    +  private val DEFAULT_CORES = 1.0
    +
    +  logInfo("Created KubernetesClusterScheduler instance")
    +
    +  var client = setupKubernetesClient()
    +  val driverName = s"spark-driver-${Random.alphanumeric take 5 
mkString("")}".toLowerCase()
    +  val svcName = s"spark-svc-${Random.alphanumeric take 5 
mkString("")}".toLowerCase()
    +  val nameSpace = conf.get(
    +    "spark.kubernetes.namespace",
    +    KubernetesClusterScheduler.defaultNameSpace)
    +  val serviceAccountName = conf.get(
    +    "spark.kubernetes.serviceAccountName",
    +    KubernetesClusterScheduler.defaultServiceAccountName)
    +
    +  // Anything that should either not be passed to driver config in the 
cluster, or
    +  // that is going to be explicitly managed as command argument to the 
driver pod
    +  val confBlackList = scala.collection.Set(
    +    "spark.master",
    +    "spark.app.name",
    +    "spark.submit.deployMode",
    +    "spark.executor.jar",
    +    "spark.dynamicAllocation.enabled",
    +    "spark.shuffle.service.enabled")
    +
    +  def start(args: ClientArguments): Unit = {
    +    startDriver(client, args)
    +  }
    +
    +  def stop(): Unit = {
    +    client.pods().inNamespace(nameSpace).withName(driverName).delete()
    +    client
    +      .services()
    +      .inNamespace(nameSpace)
    +      .withName(svcName)
    +      .delete()
    +  }
    +
    +  def startDriver(client: KubernetesClient,
    +                  args: ClientArguments): Unit = {
    +    logInfo("Starting spark driver on kubernetes cluster")
    +    val driverDescription = buildDriverDescription(args)
    +
    +    // image needs to support shim scripts "/opt/driver.sh" and 
"/opt/executor.sh"
    +    val sparkImage = 
conf.getOption("spark.kubernetes.sparkImage").getOrElse {
    +      // TODO: this needs to default to some standard Apache Spark image
    +      throw new SparkException("Spark image not set. Please configure 
spark.kubernetes.sparkImage")
    +    }
    +
    +    // This is the URL of the client jar.
    +    val clientJarUri = args.userJar
    +
    +    // This is the kubernetes master we're launching on.
    +    val kubernetesHost = "k8s://" + client.getMasterUrl().getHost()
    +    logInfo("Using as kubernetes-master: " + kubernetesHost.toString())
    +
    +    val submitArgs = scala.collection.mutable.ArrayBuffer.empty[String]
    +    submitArgs ++= Vector(
    +      clientJarUri,
    +      s"--class=${args.userClass}",
    +      s"--master=$kubernetesHost",
    +      s"--executor-memory=${driverDescription.mem}",
    +      s"--conf spark.executor.jar=$clientJarUri")
    +
    +    submitArgs ++= conf.getAll.filter { case (name, _) => 
!confBlackList.contains(name) }
    +      .map { case (name, value) => s"--conf ${name}=${value}" }
    +
    +    if (conf.getBoolean("spark.dynamicAllocation.enabled", false)) {
    +      submitArgs ++= Vector(
    +        "--conf spark.dynamicAllocation.enabled=true",
    +        "--conf spark.shuffle.service.enabled=true")
    +    }
    +
    +    // these have to come at end of arg list
    +    submitArgs ++= Vector("/opt/spark/kubernetes/client.jar",
    +      args.userArgs.mkString(" "))
    +
    +    val labelMap = Map("type" -> "spark-driver")
    +    val pod = new PodBuilder()
    +      .withNewMetadata()
    +      .withLabels(labelMap.asJava)
    +      .withName(driverName)
    +      .endMetadata()
    +      .withNewSpec()
    +      .withRestartPolicy("OnFailure")
    +      .withServiceAccount(serviceAccountName)
    +      .addNewContainer()
    +      .withName("spark-driver")
    +      .withImage(sparkImage)
    +      .withImagePullPolicy("Always")
    +      .withCommand(s"/opt/driver.sh")
    +      .withArgs(submitArgs :_*)
    +      .endContainer()
    +      .endSpec()
    +      .build()
    +    client.pods().inNamespace(nameSpace).withName(driverName).create(pod)
    +
    +    var svc = new ServiceBuilder()
    +      .withNewMetadata()
    +      .withLabels(labelMap.asJava)
    +      .withName(svcName)
    +      .endMetadata()
    +      .withNewSpec()
    +      .addNewPort()
    +      .withPort(4040)
    +      .withNewTargetPort()
    +      .withIntVal(4040)
    +      .endTargetPort()
    +      .endPort()
    +      .withSelector(labelMap.asJava)
    +      .withType("LoadBalancer")
    +      .endSpec()
    +      .build()
    +
    +    client
    +      .services()
    +      .inNamespace(nameSpace)
    +      .withName(svcName)
    +      .create(svc)
    +
    +//    try {
    --- End diff --
    
    Remove


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to