Skip to content
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

[SPARK-39006][K8S] Check PVC claimName must be OnDemand when multiple executors required #36333

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.fabric8.kubernetes.api.model._

import org.apache.spark.deploy.k8s._
import org.apache.spark.deploy.k8s.Constants.{ENV_EXECUTOR_ID, SPARK_APP_ID_LABEL}
import org.apache.spark.internal.config.EXECUTOR_INSTANCES

private[spark] class MountVolumesFeatureStep(conf: KubernetesConf)
extends KubernetesFeatureConfigStep {
Expand Down Expand Up @@ -71,6 +72,7 @@ private[spark] class MountVolumesFeatureStep(conf: KubernetesConf)
case KubernetesPVCVolumeConf(claimNameTemplate, storageClass, size) =>
val claimName = conf match {
case c: KubernetesExecutorConf =>
checkPVCOnDemandWhenMultiExecutors(claimNameTemplate)
claimNameTemplate
.replaceAll(PVC_ON_DEMAND,
s"${conf.resourceNamePrefix}-exec-${c.executorId}$PVC_POSTFIX-$i")
Expand Down Expand Up @@ -120,6 +122,16 @@ private[spark] class MountVolumesFeatureStep(conf: KubernetesConf)
override def getAdditionalKubernetesResources(): Seq[HasMetadata] = {
additionalResources.toSeq
}

private def checkPVCOnDemandWhenMultiExecutors(claimName: String): Unit = {
val executorInstances = conf.get(EXECUTOR_INSTANCES)
if (executorInstances.isEmpty) return
if (claimName != PVC_ON_DEMAND && executorInstances.get > 1) {
throw new IllegalArgumentException("ClaimName of PVC must be " +
PVC_ON_DEMAND +
" when multiple executors are required")
}
}
}

private[spark] object MountVolumesFeatureStep {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ package org.apache.spark.deploy.k8s.features

import scala.collection.JavaConverters._

import org.apache.spark.SparkFunSuite
import org.apache.spark.{SparkConf, SparkFunSuite}
import org.apache.spark.deploy.k8s._
import org.apache.spark.internal.config.EXECUTOR_INSTANCES

class MountVolumesFeatureStepSuite extends SparkFunSuite {
test("Mounts hostPath volumes") {
Expand Down Expand Up @@ -148,6 +149,26 @@ class MountVolumesFeatureStepSuite extends SparkFunSuite {
assert(executorPVC.getClaimName.endsWith("-exec-1-pvc-0"))
}

test("SPARK-39006 PVC claimName must be onDemand when multiple executors") {
val volumeConf = KubernetesVolumeSpec(
"testVolume",
"/tmp",
"",
mountReadOnly = true,
KubernetesPVCVolumeConf("testClaimName")
)
val conf = new SparkConf().set(EXECUTOR_INSTANCES, 2)
val executorConf =
KubernetesTestConf.createExecutorConf(sparkConf = conf, volumes = Seq(volumeConf))
val executorStep = new MountVolumesFeatureStep(executorConf)
assertThrows[IllegalArgumentException] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it would be good to assert on the exception message too. Or use a specialized exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help. I have addressed this comment.

executorStep.configurePod(SparkPod.initialPod())
}
assert(intercept[IllegalArgumentException] {
executorStep.configurePod(SparkPod.initialPod())
}.getMessage.contains("ClaimName of PVC must be OnDemand"))
}

test("Mounts emptyDir") {
val volumeConf = KubernetesVolumeSpec(
"testVolume",
Expand Down