Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 =>
checkPVCClaimNameWhenMultiExecutors(claimNameTemplate)
claimNameTemplate
.replaceAll(PVC_ON_DEMAND,
s"${conf.resourceNamePrefix}-exec-${c.executorId}$PVC_POSTFIX-$i")
Expand Down Expand Up @@ -120,6 +122,20 @@ private[spark] class MountVolumesFeatureStep(conf: KubernetesConf)
override def getAdditionalKubernetesResources(): Seq[HasMetadata] = {
additionalResources.toSeq
}

private def checkPVCClaimNameWhenMultiExecutors(claimName: String): Unit = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

checkPVCClaimNameWhenMultiExecutors -> checkPVCClaimName because this PR checks all cases instead of WhenMultiExecutors and doesn't raise exception for single instance case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Change it as checkPVCClaimName :)

val invalidClaimName =
if (!claimName.contains(PVC_ON_DEMAND) && !claimName.contains(ENV_EXECUTOR_ID)) true
else false

@dongjoon-hyun dongjoon-hyun Apr 28, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is misleading because this is totally valid when there is only one executor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, check it when multiple executors


val executorInstances = conf.get(EXECUTOR_INSTANCES)
if (executorInstances.isEmpty) return

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please try to avoid return in Scala method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, remove return

if (invalidClaimName && executorInstances.get > 1) {
throw new IllegalArgumentException("PVC ClaimName should contain " +
PVC_ON_DEMAND + " or " + ENV_EXECUTOR_ID +
" when multiple executors are required")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The error message looks informative but please include the current claim name in the error message too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Have added the current claim name

}
}
}

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 Show a directional error message for PVC Dynamic Allocation Failure") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. We need :, e.g., SPARK-39006 -> SPARK-39006:.
  2. After this PR, we don't have PVC Dynamic Allocation Failure. Please revise the test case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Have two changes here:

  • Add : after SPARK-39006
  • Change test case as Check PVC ClaimName

val volumeConf = KubernetesVolumeSpec(
"testVolume",
"/tmp",
"",
mountReadOnly = true,
KubernetesPVCVolumeConf("testClaimName")
)
val conf = new SparkConf().set(EXECUTOR_INSTANCES, 2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a positive test case where executor instance is 1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fine, added a positive test here

val executorConf =
KubernetesTestConf.createExecutorConf(sparkConf = conf, volumes = Seq(volumeConf))
val executorStep = new MountVolumesFeatureStep(executorConf)
assertThrows[IllegalArgumentException] {
executorStep.configurePod(SparkPod.initialPod())
}
assert(intercept[IllegalArgumentException] {
executorStep.configurePod(SparkPod.initialPod())
}.getMessage.contains("PVC ClaimName should contain OnDemand or SPARK_EXECUTOR_ID"))
}

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