Skip to content

Commit

Permalink
Allow RWX, FS infra PVC (#107)
Browse files Browse the repository at this point in the history
For RWX pvc request, don't limit the infra PVC to be Block, but also
allw FS.

Signed-off-by: Nahshon Unna-Tsameret <[email protected]>
  • Loading branch information
nunnatsa authored Apr 18, 2024
1 parent bfd317b commit acc2730
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 19 deletions.
72 changes: 68 additions & 4 deletions e2e/create-pvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"

cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"

Expand Down Expand Up @@ -113,8 +114,71 @@ var _ = Describe("CreatePVC", func() {
pvcName := "test-pvc"
storageClassName := "kubevirt"
pvc := pvcSpec(pvcName, storageClassName, "10Mi")
volumeMode := k8sv1.PersistentVolumeBlock
pvc.Spec.VolumeMode = &volumeMode
pvc.Spec.VolumeMode = ptr.To(k8sv1.PersistentVolumeBlock)
pvc.Spec.AccessModes = []k8sv1.PersistentVolumeAccessMode{k8sv1.ReadWriteMany}

By("creating a pvc")
_, err := tenantClient.CoreV1().PersistentVolumeClaims(namespace).Create(context.Background(), pvc, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

By("creating a pod that attaches pvc")
const (
labelKey = "app"
writerLabelValue = "writer"
)

writerPod := runPod(
tenantClient.CoreV1(),
namespace,
createPod("writer-pod",
withBlock(pvc.Name),
withCommand(blockWriteCommand+" && sleep 60"),
withLabel(labelKey, writerLabelValue),
),
false,
)

GinkgoWriter.Printf("[DEBUG] writer pod node: %s\n", writerPod.Spec.NodeName)

By("creating a different pod that reads from pvc")
Eventually(func(g Gomega) {
readerPod := runPod(
tenantClient.CoreV1(),
namespace,
createPod("reader-pod",
withCommand(blockReadCommand),
withBlock(pvc.Name),
withPodAntiAffinity(labelKey, writerLabelValue),
),
true,
)

defer deletePod(tenantClient.CoreV1(), namespace, readerPod.Name)
GinkgoWriter.Printf("[DEBUG] reader pod node: %s\n", readerPod.Spec.NodeName)

s := tenantClient.CoreV1().Pods(namespace).GetLogs(readerPod.Name, &k8sv1.PodLogOptions{})
reader, err := s.Stream(context.Background())
g.Expect(err).ToNot(HaveOccurred())
defer reader.Close()
buf := new(bytes.Buffer)
n, err := buf.ReadFrom(reader)
g.Expect(err).ToNot(HaveOccurred())

g.Expect(n).To(BeEquivalentTo(len("testing\n")))
out := buf.String()
g.Expect(strings.TrimSpace(out)).To(Equal("testing"))

}).WithTimeout(120 * time.Second).WithPolling(20 * time.Second).Should(Succeed())

deletePod(tenantClient.CoreV1(), namespace, writerPod.Name)
})

It("should creates a RW-Many block pvc, with FS infra storage class, and attaches to pod", Label("pvcCreation", "RWX", "Block", "infra-FS"), func() {
pvcName := "test-pvc"
storageClassName := "infra-fs"
pvc := pvcSpec(pvcName, storageClassName, "10Mi")

pvc.Spec.VolumeMode = ptr.To(k8sv1.PersistentVolumeBlock)
pvc.Spec.AccessModes = []k8sv1.PersistentVolumeAccessMode{k8sv1.ReadWriteMany}

By("creating a pvc")
Expand Down Expand Up @@ -177,8 +241,8 @@ var _ = Describe("CreatePVC", func() {
const pvcName = "test-pvc"
storageClassName := "kubevirt"
pvc := pvcSpec(pvcName, storageClassName, "10Mi")
volumeMode := k8sv1.PersistentVolumeFilesystem
pvc.Spec.VolumeMode = &volumeMode

pvc.Spec.VolumeMode = ptr.To(k8sv1.PersistentVolumeFilesystem)
pvc.Spec.AccessModes = []k8sv1.PersistentVolumeAccessMode{k8sv1.ReadWriteMany}

By("creating a pvc")
Expand Down
16 changes: 16 additions & 0 deletions hack/ci/deploy-infra-fs-sc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -ex

source hack/common.sh

cat <<EOF | _kubectl_tenant apply -f -
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: infra-fs
provisioner: csi.kubevirt.io
parameters:
infraStorageClassName: nfs-csi
bus: scsi
EOF
3 changes: 2 additions & 1 deletion hack/ci/e2e-latest-split.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -ex

make cluster-up
KUBEVIRT_DEPLOY_NFS_CSI=true make cluster-up
make cluster-sync-split
./hack/ci/deploy-infra-fs-sc.sh
make e2e-test
3 changes: 2 additions & 1 deletion hack/ci/e2e-latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -ex

make cluster-up
KUBEVIRT_DEPLOY_NFS_CSI=true make cluster-up
make cluster-sync
./hack/ci/deploy-infra-fs-sc.sh
make e2e-test
2 changes: 0 additions & 2 deletions pkg/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
kubevirtv1 "kubevirt.io/api/core/v1"
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"

Expand Down Expand Up @@ -166,7 +165,6 @@ func (c *ControllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
}

if isRWX {
dv.Spec.Storage.VolumeMode = ptr.To(corev1.PersistentVolumeBlock)
dv.Spec.Storage.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteMany}
}

Expand Down
15 changes: 4 additions & 11 deletions pkg/service/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var _ = Describe("StorageClass", func() {
})

var _ = Describe("CreateVolume", func() {
DescribeTable("should successfully create a volume", func(cap *csi.VolumeCapability, expectedAC *corev1.PersistentVolumeAccessMode, expectedVolumeMode *corev1.PersistentVolumeMode) {
DescribeTable("should successfully create a volume", func(cap *csi.VolumeCapability, expectedAC *corev1.PersistentVolumeAccessMode) {
client := &ControllerClientMock{}
controller := ControllerService{client, testInfraNamespace, testInfraLabels, storageClassEnforcement}

Expand All @@ -74,17 +74,10 @@ var _ = Describe("CreateVolume", func() {
} else if dv.Spec.Storage != nil {
Expect(dv.Spec.Storage.AccessModes).To(BeEmpty())
}

if expectedVolumeMode != nil {
Expect(dv.Spec.Storage).ToNot(BeNil())
Expect(dv.Spec.Storage.VolumeMode).To(HaveValue(Equal(*expectedVolumeMode)))
} else if dv.Spec.Storage != nil {
Expect(dv.Spec.Storage.VolumeMode).To(BeNil())
}
},
Entry("volume mode = block; [RWX]", getVolumeCapability(corev1.PersistentVolumeBlock, csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER), ptr.To(corev1.ReadWriteMany), ptr.To(corev1.PersistentVolumeBlock)),
Entry("volume mode = block; [RWO]", getVolumeCapability(corev1.PersistentVolumeBlock, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), nil, nil),
Entry("volume mode = filesystem; [RWO]", getVolumeCapability(corev1.PersistentVolumeFilesystem, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), nil, nil),
Entry("volume mode = block; [RWX]", getVolumeCapability(corev1.PersistentVolumeBlock, csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER), ptr.To(corev1.ReadWriteMany)),
Entry("volume mode = block; [RWO]", getVolumeCapability(corev1.PersistentVolumeBlock, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), nil),
Entry("volume mode = filesystem; [RWO]", getVolumeCapability(corev1.PersistentVolumeFilesystem, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), nil),
)

It("should reject create volume request for FS & RWX", func() {
Expand Down

0 comments on commit acc2730

Please sign in to comment.