You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/02/07 07:13:45 UTC

[GitHub] [spark] martin-g commented on a change in pull request #34456: [SPARK-36061][K8S] Add support for PodGroup

martin-g commented on a change in pull request #34456:
URL: https://github.com/apache/spark/pull/34456#discussion_r800355093



##########
File path: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/PodGroupFeatureStep.scala
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.deploy.k8s.features
+
+import scala.collection.JavaConverters._
+
+import io.fabric8.kubernetes.api.model._
+import io.fabric8.volcano.scheduling.v1beta1.PodGroupBuilder
+
+import org.apache.spark.SparkConf
+import org.apache.spark.deploy.k8s.{KubernetesConf, SparkPod}
+import org.apache.spark.deploy.k8s.Config._
+
+private[spark] class PodGroupFeatureStep(kubernetesConf: KubernetesConf)
+  extends KubernetesFeatureConfigStep {
+
+  val conf: SparkConf = kubernetesConf.sparkConf
+  val POD_GROUP_ANNOTATION = "scheduling.k8s.io/group-name"
+  val podGroupName = s"${kubernetesConf.appId}-podgroup"
+  val enablePodGroup: Boolean = conf.get(KUBERNETES_ENABLE_PODGROUP)
+
+  override def configurePod(pod: SparkPod): SparkPod = {
+    if (enablePodGroup) {
+      val k8sPodBuilder = new PodBuilder(pod.pod)
+        .editMetadata()
+        .addToAnnotations(POD_GROUP_ANNOTATION, podGroupName)
+        .endMetadata()
+      val k8sPod = k8sPodBuilder.build()
+      SparkPod(k8sPod, pod.container)
+    } else {
+      pod
+    }
+  }
+
+  private def getPodGroupMinResources(): java.util.HashMap[String, Quantity] = {
+    val cpu = kubernetesConf.get(KUBERNETES_PODGROUP_MIN_CPU)
+    val memory = kubernetesConf.get(KUBERNETES_PODGROUP_MIN_MEMORY)
+
+    val cpuQ = new QuantityBuilder(false)
+      .withAmount(s"${cpu}")
+      .build()
+    val memoryQ = new QuantityBuilder(false)
+      .withAmount(s"${memory}Mi")
+      .build()
+    new java.util.HashMap(Map("cpu" -> cpuQ, "memory" -> memoryQ).asJava)
+  }
+
+  private def getVolcanoResources(): Seq[HasMetadata] = {
+    val podGroup = new PodGroupBuilder()
+      .editOrNewMetadata()
+        .withName(podGroupName)
+        .withNamespace(kubernetesConf.get(KUBERNETES_NAMESPACE))
+      .endMetadata()
+      .editOrNewSpec()
+        .withMinResources(getPodGroupMinResources())
+      .endSpec()
+      .build()
+
+    Seq{podGroup}
+  }
+
+  private def getPodGroupResources(): Seq[HasMetadata] = {
+    if (enablePodGroup) {
+      kubernetesConf.schedulerName match {
+        case "volcano" =>
+          getVolcanoResources()
+        case _ =>
+          Seq.empty
+      }
+    } else {
+      Seq.empty
+    }
+  }
+
+  override def getAdditionalKubernetesResources(): Seq[HasMetadata] = {
+    getPodGroupResources()
+  }
+
+  override def getAdditionalPreKubernetesResources(): Seq[HasMetadata] = {
+    getPodGroupResources()

Review comment:
       This looks strange.
   Both pre- and post- resources return the same sequence of resources - `getPodGroupResources()`

##########
File path: resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/features/PodGroupFeatureStepSuite.scala
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.deploy.k8s.features
+
+import io.fabric8.kubernetes.api.model.Quantity
+import io.fabric8.volcano.scheduling.v1beta1.PodGroup
+
+import org.apache.spark.{SparkConf, SparkFunSuite}
+import org.apache.spark.deploy.k8s._
+import org.apache.spark.deploy.k8s.Config._
+
+class PodGroupFeatureStepSuite extends SparkFunSuite {
+  test("Do nothing when KUBERNETES_ENABLE_PODGROUP is false") {
+    val conf = KubernetesTestConf.createDriverConf()
+    val step = new PodGroupFeatureStep(conf)
+
+    val initialPod = SparkPod.initialPod()
+    val configuredPod = step.configurePod(initialPod)
+    assert(configuredPod === initialPod)
+
+    assert(step.getAdditionalKubernetesResources().isEmpty)
+    assert(step.getAdditionalPodSystemProperties().isEmpty)
+  }
+
+  test("Driver Pod with Volcano PodGroup") {

Review comment:
       prefix with `SPARK-36061: `?

##########
File path: resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/features/PodGroupFeatureStepSuite.scala
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.deploy.k8s.features
+
+import io.fabric8.kubernetes.api.model.Quantity
+import io.fabric8.volcano.scheduling.v1beta1.PodGroup
+
+import org.apache.spark.{SparkConf, SparkFunSuite}
+import org.apache.spark.deploy.k8s._
+import org.apache.spark.deploy.k8s.Config._
+
+class PodGroupFeatureStepSuite extends SparkFunSuite {
+  test("Do nothing when KUBERNETES_ENABLE_PODGROUP is false") {

Review comment:
       prefix with `SPARK-36061:` ?

##########
File path: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/PodGroupFeatureStep.scala
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.deploy.k8s.features
+
+import scala.collection.JavaConverters._
+
+import io.fabric8.kubernetes.api.model._
+import io.fabric8.volcano.scheduling.v1beta1.PodGroupBuilder
+
+import org.apache.spark.SparkConf
+import org.apache.spark.deploy.k8s.{KubernetesConf, SparkPod}
+import org.apache.spark.deploy.k8s.Config._
+
+private[spark] class PodGroupFeatureStep(kubernetesConf: KubernetesConf)
+  extends KubernetesFeatureConfigStep {
+
+  val conf: SparkConf = kubernetesConf.sparkConf
+  val POD_GROUP_ANNOTATION = "scheduling.k8s.io/group-name"
+  val podGroupName = s"${kubernetesConf.appId}-podgroup"
+  val enablePodGroup: Boolean = conf.get(KUBERNETES_ENABLE_PODGROUP)
+
+  override def configurePod(pod: SparkPod): SparkPod = {
+    if (enablePodGroup) {
+      val k8sPodBuilder = new PodBuilder(pod.pod)
+        .editMetadata()
+        .addToAnnotations(POD_GROUP_ANNOTATION, podGroupName)
+        .endMetadata()
+      val k8sPod = k8sPodBuilder.build()
+      SparkPod(k8sPod, pod.container)
+    } else {
+      pod
+    }
+  }
+
+  private def getPodGroupMinResources(): java.util.HashMap[String, Quantity] = {
+    val cpu = kubernetesConf.get(KUBERNETES_PODGROUP_MIN_CPU)
+    val memory = kubernetesConf.get(KUBERNETES_PODGROUP_MIN_MEMORY)
+
+    val cpuQ = new QuantityBuilder(false)
+      .withAmount(s"${cpu}")
+      .build()
+    val memoryQ = new QuantityBuilder(false)
+      .withAmount(s"${memory}Mi")
+      .build()
+    new java.util.HashMap(Map("cpu" -> cpuQ, "memory" -> memoryQ).asJava)
+  }
+
+  private def getVolcanoResources(): Seq[HasMetadata] = {
+    val podGroup = new PodGroupBuilder()
+      .editOrNewMetadata()
+        .withName(podGroupName)
+        .withNamespace(kubernetesConf.get(KUBERNETES_NAMESPACE))
+      .endMetadata()
+      .editOrNewSpec()
+        .withMinResources(getPodGroupMinResources())
+      .endSpec()
+      .build()
+
+    Seq{podGroup}

Review comment:
       `Seq(podGroup)` ?

##########
File path: resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/features/PodGroupFeatureStepSuite.scala
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.deploy.k8s.features
+
+import io.fabric8.kubernetes.api.model.Quantity
+import io.fabric8.volcano.scheduling.v1beta1.PodGroup
+
+import org.apache.spark.{SparkConf, SparkFunSuite}
+import org.apache.spark.deploy.k8s._
+import org.apache.spark.deploy.k8s.Config._
+
+class PodGroupFeatureStepSuite extends SparkFunSuite {
+  test("Do nothing when KUBERNETES_ENABLE_PODGROUP is false") {
+    val conf = KubernetesTestConf.createDriverConf()
+    val step = new PodGroupFeatureStep(conf)
+
+    val initialPod = SparkPod.initialPod()
+    val configuredPod = step.configurePod(initialPod)
+    assert(configuredPod === initialPod)
+
+    assert(step.getAdditionalKubernetesResources().isEmpty)
+    assert(step.getAdditionalPodSystemProperties().isEmpty)
+  }
+
+  test("Driver Pod with Volcano PodGroup") {
+    val sparkConf = new SparkConf()
+      .set(KUBERNETES_DRIVER_SCHEDULER_NAME, "volcano")
+      .set(KUBERNETES_ENABLE_PODGROUP, true)
+    val kubernetesConf = KubernetesTestConf.createDriverConf(sparkConf)
+    val step = new PodGroupFeatureStep(kubernetesConf)
+    val configuredPod = step.configurePod(SparkPod.initialPod())
+
+    val annotation = configuredPod.pod.getMetadata.getAnnotations
+
+    assert(annotation.get("scheduling.k8s.io/group-name") === step.podGroupName)
+    val podGroup = step.getAdditionalKubernetesResources().head
+    assert(podGroup.getMetadata.getName === step.podGroupName)
+  }
+
+  test("Executor Pod with Volcano PodGroup") {

Review comment:
       prefix with `SPARK-36061: ` ?

##########
File path: resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/features/PodGroupFeatureStepSuite.scala
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.deploy.k8s.features
+
+import io.fabric8.kubernetes.api.model.Quantity
+import io.fabric8.volcano.scheduling.v1beta1.PodGroup
+
+import org.apache.spark.{SparkConf, SparkFunSuite}
+import org.apache.spark.deploy.k8s._
+import org.apache.spark.deploy.k8s.Config._
+
+class PodGroupFeatureStepSuite extends SparkFunSuite {
+  test("Do nothing when KUBERNETES_ENABLE_PODGROUP is false") {
+    val conf = KubernetesTestConf.createDriverConf()
+    val step = new PodGroupFeatureStep(conf)
+
+    val initialPod = SparkPod.initialPod()
+    val configuredPod = step.configurePod(initialPod)
+    assert(configuredPod === initialPod)
+
+    assert(step.getAdditionalKubernetesResources().isEmpty)
+    assert(step.getAdditionalPodSystemProperties().isEmpty)
+  }
+
+  test("Driver Pod with Volcano PodGroup") {
+    val sparkConf = new SparkConf()
+      .set(KUBERNETES_DRIVER_SCHEDULER_NAME, "volcano")
+      .set(KUBERNETES_ENABLE_PODGROUP, true)
+    val kubernetesConf = KubernetesTestConf.createDriverConf(sparkConf)
+    val step = new PodGroupFeatureStep(kubernetesConf)
+    val configuredPod = step.configurePod(SparkPod.initialPod())
+
+    val annotation = configuredPod.pod.getMetadata.getAnnotations

Review comment:
       annotation`s` ?

##########
File path: resource-managers/kubernetes/core/pom.xml
##########
@@ -51,7 +51,16 @@
       <artifactId>spark-tags_${scala.binary.version}</artifactId>
       <type>test-jar</type>
     </dependency>
-
+    <dependency>

Review comment:
       The new dependencies are available since 5.11.0 - e.g. https://search.maven.org/artifact/io.fabric8/volcano-model-v1beta1
   
   Latest available is 5.12.1 - https://search.maven.org/artifact/io.fabric8/volcano-model-v1beta1/5.12.1/bundle




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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