Skip to content

Commit

Permalink
e2e: add test cases for pv.Spec.MountOptions
Browse files Browse the repository at this point in the history
Signed-off-by: Rakshith R <rar@redhat.com>
  • Loading branch information
Rakshith-R committed Jun 14, 2023
1 parent a0c5c4d commit 8ec8aa7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
19 changes: 19 additions & 0 deletions e2e/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
cephFSExamplePath = examplePath + "cephfs/"
subvolumegroup = "e2e"
fileSystemName = "myfs"
seLinuxMountOption = []string{"context=\"system_u:object_r:container_file_t:s0:c0,c1\""}
)

func deployCephfsPlugin() {
Expand Down Expand Up @@ -318,6 +319,24 @@ var _ = Describe(cephfsType, func() {
}
})
}

By("verify seLinuxMountOptions support", func() {
err := createCephfsStorageClass(f.ClientSet, f, true, nil)
if err != nil {
framework.Failf("failed to create CephFS storageclass: %v", err)
}

err = checkMountOptions(pvcPath, appPath, f, seLinuxMountOption, seLinuxMountOption)
if err != nil {
framework.Failf("failed to verify mount options: %v", err)
}

err = deleteResource(cephFSExamplePath + "storageclass.yaml")
if err != nil {
framework.Failf("failed to delete CephFS storageclass: %v", err)
}
})

By("verify generic ephemeral volume support", func() {
err := createCephfsStorageClass(f.ClientSet, f, true, nil)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions e2e/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,23 @@ var _ = Describe("nfs", func() {
}
})

By("verify mountOptions support", func() {
err := createNFSStorageClass(f.ClientSet, f, false, nil)
if err != nil {
framework.Failf("failed to create NFS storageclass: %v", err)
}

err = checkMountOptions(pvcPath, appPath, f, seLinuxMountOption, seLinuxMountOption)
if err != nil {
framework.Failf("failed to verify mount options: %v", err)
}

err = deleteResource(nfsExamplePath + "storageclass.yaml")
if err != nil {
framework.Failf("failed to delete NFS storageclass: %v", err)
}
})

By("verify RWOP volume support", func() {
err := createNFSStorageClass(f.ClientSet, f, false, nil)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion e2e/rbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,13 @@ var _ = Describe("RBD", func() {
})
}

By("verify seLinuxMountOptions support", func() {
err := checkMountOptions(pvcPath, appPath, f, seLinuxMountOption, seLinuxMountOption)
if err != nil {
framework.Failf("failed to verify mount options: %v", err)
}
})

By("create a PVC and check PVC/PV metadata on RBD image", func() {
pvc, err := loadPVC(pvcPath)
if err != nil {
Expand Down Expand Up @@ -2955,7 +2962,7 @@ var _ = Describe("RBD", func() {

By("validate mount options in app pod", func() {
mountFlags := []string{"discard"}
err := checkMountOptions(pvcPath, appPath, f, mountFlags)
err := checkMountOptions(pvcPath, appPath, f, nil, mountFlags)
if err != nil {
framework.Failf("failed to check mount options: %v", err)
}
Expand Down
23 changes: 21 additions & 2 deletions e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,32 @@ func pvcDeleteWhenPoolNotFound(pvcPath string, cephFS bool, f *framework.Framewo
return err
}

func checkMountOptions(pvcPath, appPath string, f *framework.Framework, mountFlags []string) error {
func checkMountOptions(pvcPath, appPath string, f *framework.Framework,
mountOptions, mountFlags []string) error {
pvc, err := loadPVC(pvcPath)
if err != nil {
return err
}

pvc.Namespace = f.UniqueName
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
if err != nil {
framework.Failf("failed to create PVC: %v", err)
}
if len(mountOptions) > 0 {
// modify PV spec.MountOptions
pv, err := getBoundPV(f.ClientSet, pvc)
if err != nil {
framework.Failf("failed to get PV: %v", err)
}
pv.Spec.MountOptions = mountOptions

// update PV
_, err = f.ClientSet.CoreV1().PersistentVolumes().Update(context.TODO(), pv, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("failed to update pv: %w", err)
}
}

app, err := loadApp(appPath)
if err != nil {
Expand All @@ -784,7 +803,7 @@ func checkMountOptions(pvcPath, appPath string, f *framework.Framework, mountFla
app.Labels = map[string]string{"app": "validate-mount-opt"}
app.Namespace = f.UniqueName

err = createPVCAndApp("", f, pvc, app, deployTimeout)
err = createApp(f.ClientSet, app, deployTimeout)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions examples/cephfs/storageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ parameters:

reclaimPolicy: Delete
allowVolumeExpansion: true
mountOptions:
- debug
# mountOptions:
# - context="system_u:object_r:container_file_t:s0:c0,c1"

0 comments on commit 8ec8aa7

Please sign in to comment.