Skip to content

Commit

Permalink
[SPARK-46783][K8S][TESTS] Use built-in storage classes in PVTestsSuite
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

This PR aims to use `built-in` storage classes in PVTestsSuite.

### Why are the changes needed?

`Minikube` already has `built-in` storage classe, `standard`, for `hostpath`. We don't need to create a new one.
```
$ minikube kubectl get storageclass
NAME                 PROVISIONER                    RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
standard (default)   k8s.io/minikube-hostpath       Delete          Immediate              false                  109m
```

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #44809 from dongjoon-hyun/SPARK-46783.

Authored-by: Dongjoon Hyun <dhyun@apple.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
  • Loading branch information
dongjoon-hyun committed Jan 20, 2024
1 parent 7b4fd90 commit b7356b6
Showing 1 changed file with 4 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,17 @@ package org.apache.spark.deploy.k8s.integrationtest
import scala.jdk.CollectionConverters._

import io.fabric8.kubernetes.api.model._
import io.fabric8.kubernetes.api.model.storage.StorageClassBuilder
import org.scalatest.concurrent.{Eventually, PatienceConfiguration}
import org.scalatest.time.{Milliseconds, Span}

import org.apache.spark.deploy.k8s.integrationtest.KubernetesSuite._
import org.apache.spark.deploy.k8s.integrationtest.backend.minikube.MinikubeTestBackend

private[spark] trait PVTestsSuite { k8sSuite: KubernetesSuite =>
import PVTestsSuite._

private def setupLocalStorageClass(): Unit = {
val scBuilder = new StorageClassBuilder()
.withKind("StorageClass")
.withApiVersion("storage.k8s.io/v1")
.withNewMetadata()
.withName(STORAGE_NAME)
.endMetadata()
.withProvisioner("kubernetes.io/no-provisioner")
.withVolumeBindingMode("WaitForFirstConsumer")
try {
kubernetesTestComponents
.kubernetesClient
.storage()
.v1()
.storageClasses()
.create(scBuilder.build())
} catch {
case e: io.fabric8.kubernetes.client.KubernetesClientException =>
// Ignore storage class error sometimes we have a dangling class
}
}

private def setupLocalStorage(): Unit = {

setupLocalStorageClass()

val storageClassName = if (testBackend == MinikubeTestBackend) "standard" else "hostpath"
val pvBuilder = new PersistentVolumeBuilder()
.withKind("PersistentVolume")
.withApiVersion("v1")
Expand All @@ -64,7 +40,7 @@ private[spark] trait PVTestsSuite { k8sSuite: KubernetesSuite =>
.withCapacity(Map("storage" -> new Quantity("1Gi")).asJava)
.withAccessModes("ReadWriteOnce")
.withPersistentVolumeReclaimPolicy("Retain")
.withStorageClassName("test-local-storage")
.withStorageClassName(storageClassName)
.withLocal(new LocalVolumeSourceBuilder().withPath(VM_PATH).build())
.withNewNodeAffinity()
.withNewRequired()
Expand All @@ -86,7 +62,7 @@ private[spark] trait PVTestsSuite { k8sSuite: KubernetesSuite =>
.endMetadata()
.withNewSpec()
.withAccessModes("ReadWriteOnce")
.withStorageClassName("test-local-storage")
.withStorageClassName(storageClassName)
.withResources(new VolumeResourceRequirementsBuilder()
.withRequests(Map("storage" -> new Quantity("1Gi")).asJava).build())
.endSpec()
Expand Down Expand Up @@ -116,14 +92,6 @@ private[spark] trait PVTestsSuite { k8sSuite: KubernetesSuite =>
.persistentVolumes()
.withName(PV_NAME)
.delete()

kubernetesTestComponents
.kubernetesClient
.storage()
.v1()
.storageClasses()
.withName(STORAGE_NAME)
.delete()
}

private def checkPVs(pod: Pod, file: String) = {
Expand Down Expand Up @@ -237,7 +205,6 @@ private[spark] trait PVTestsSuite { k8sSuite: KubernetesSuite =>
}

private[spark] object PVTestsSuite {
val STORAGE_NAME = "test-local-storage"
val PV_NAME = "test-local-pv"
val PVC_NAME = "test-local-pvc"
val CONTAINER_MOUNT_PATH = "/opt/spark/pv-tests"
Expand Down

0 comments on commit b7356b6

Please sign in to comment.