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

    https://github.com/apache/spark/pull/16061#discussion_r90342705
  
    --- Diff: 
kubernetes/src/main/scala/org/apache/spark/scheduler/cluster/kubernetes/KubernetesClusterSchedulerBackend.scala
 ---
    @@ -0,0 +1,222 @@
    +/*
    + * 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 collection.JavaConverters._
    +import io.fabric8.kubernetes.api.model.PodBuilder
    +import io.fabric8.kubernetes.api.model.extensions.JobBuilder
    +import io.fabric8.kubernetes.client.{ConfigBuilder, 
DefaultKubernetesClient}
    +import org.apache.spark.internal.config._
    +import org.apache.spark.scheduler._
    +import org.apache.spark.scheduler.cluster._
    +import org.apache.spark.scheduler.cluster.CoarseGrainedClusterMessages._
    +import org.apache.spark.{SparkConf, SparkContext, SparkException}
    +import org.apache.spark.rpc.RpcEndpointAddress
    +import org.apache.spark.scheduler.TaskSchedulerImpl
    +import org.apache.spark.util.Utils
    +
    +import scala.collection.mutable
    +import scala.util.Random
    +import scala.concurrent.Future
    +
    +private[spark] class KubernetesClusterSchedulerBackend(
    +                                                  scheduler: 
TaskSchedulerImpl,
    +                                                  sc: SparkContext)
    +  extends CoarseGrainedSchedulerBackend(scheduler, sc.env.rpcEnv) {
    +
    +  val client = new DefaultKubernetesClient()
    +
    +  val DEFAULT_NUMBER_EXECUTORS = 2
    +  val sparkExecutorName = s"spark-executor-${Random.alphanumeric take 5 
mkString("")}".toLowerCase()
    +
    +  // TODO: do these need mutex guarding?
    +  // key is executor id, value is pod name
    +  var executorToPod = mutable.Map.empty[String, String] // active executors
    +  var shutdownToPod = mutable.Map.empty[String, String] // pending shutdown
    +  var executorID = 0
    +
    +  val sparkImage = conf.get("spark.kubernetes.sparkImage")
    +  val clientJarUri = conf.get("spark.executor.jar")
    +  val ns = conf.get(
    +    "spark.kubernetes.namespace",
    +    KubernetesClusterScheduler.defaultNameSpace)
    +  val dynamicExecutors = Utils.isDynamicAllocationEnabled(conf)
    +
    +  // executor back-ends take their configuration this way
    +  if (dynamicExecutors) {
    +    conf.setExecutorEnv("spark.dynamicAllocation.enabled", "true")
    +    conf.setExecutorEnv("spark.shuffle.service.enabled", "true")
    +  }
    +
    +  override def start(): Unit = {
    +    super.start()
    +    createExecutorPods(getInitialTargetExecutorNumber(sc.getConf))
    +  }
    +
    +  override def stop(): Unit = {
    +    // Kill all executor pods indiscriminately
    +    killExecutorPods(executorToPod.toVector)
    +    killExecutorPods(shutdownToPod.toVector)
    +    super.stop()
    +  }
    +
    +  // Dynamic allocation interfaces
    +  override def doRequestTotalExecutors(requestedTotal: Int): 
Future[Boolean] = {
    +    logInfo(s"Received doRequestTotalExecutors: $requestedTotal")
    +    val n = executorToPod.size
    +    val delta = requestedTotal - n
    +    if (delta > 0) {
    +      logInfo(s"Adding $delta new executors")
    +      createExecutorPods(delta)
    +    } else if (delta < 0) {
    +      val d = -delta
    --- End diff --
    
    I had started in on keeping track of new pods until they stop saying 
"pending", however I think this may be a good use case for a `PodWatcher` 


---
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