-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-36061][K8S] Add support for PodGroup #34456
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,7 +70,15 @@ trait KubernetesFeatureConfigStep { | |
|
|
||
| /** | ||
| * Return any additional Kubernetes resources that should be added to support this feature. Only | ||
| * applicable when creating the driver in cluster mode. | ||
| * applicable when creating the driver in cluster mode. Resources would be setup/refresh after | ||
| * Pod creation. | ||
| */ | ||
| def getAdditionalKubernetesResources(): Seq[HasMetadata] = Seq.empty | ||
|
|
||
|
Member
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. This is submited as a separated PR in #34599 .(1st and 2nd commits) You could only see the 3rd commit for more clearly understand, that is, we only add pod feature step in this PR. |
||
| /** | ||
| * Return any additional Kubernetes resources that should be added to support this feature. Only | ||
| * applicable when creating the driver in cluster mode. Resources would be setup/refresh before | ||
| * Pod creation. | ||
| */ | ||
| def getAdditionalPreKubernetesResources(): Seq[HasMetadata] = Seq.empty | ||
| } | ||
97 changes: 97 additions & 0 deletions
97
...rnetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/PodGroupFeatureStep.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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} | ||
Yikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| 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() | ||
Yikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...s/core/src/test/scala/org/apache/spark/deploy/k8s/features/PodGroupFeatureStepSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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") { | ||
Yikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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") { | ||
Yikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
Yikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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") { | ||
Yikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| val sparkConf = new SparkConf() | ||
| .set(KUBERNETES_EXECUTOR_SCHEDULER_NAME, "volcano") | ||
| .set(KUBERNETES_ENABLE_PODGROUP, true) | ||
| val kubernetesConf = KubernetesTestConf.createExecutorConf(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.asInstanceOf[PodGroup] | ||
| assert(podGroup.getMetadata.getName === s"${kubernetesConf.appId}-podgroup") | ||
| assert(podGroup.getSpec.getMinResources.get("cpu") === new Quantity("2.0")) | ||
| assert(podGroup.getSpec.getMinResources.get("memory") === new Quantity("3072")) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Volcano support in k8s-cli would be released at kubernetes-client v5.11
fabric8io/kubernetes-client#3580
TODO: neet to bump kubernetes-client version to latest when it publised.
spark/pom.xml
Line 207 in 7b50cf0
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.
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