From 90f62308f2348e59b8b47f8ff2c1102d4f49b9f0 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 2 Mar 2020 14:01:44 +0530 Subject: [PATCH] Fix mountoption issue in rbd use mountoptions when mounting rbd to stagingpath in stagevolume request, add E2E for mount options fixes: #846 updates: #757 Signed-off-by: Madhu Rajanna (cherry picked from commit b4e6504e9b6cf0e9920deb5b230061c22adf5b1b) --- e2e/rbd.go | 8 ++++++++ e2e/utils.go | 37 +++++++++++++++++++++++++++++++++++++ pkg/rbd/nodeserver.go | 1 + 3 files changed, 46 insertions(+) diff --git a/e2e/rbd.go b/e2e/rbd.go index 34c4409f4..24fa2f6c5 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -326,6 +326,14 @@ var _ = Describe("RBD", func() { } }) + By("validate mount options in app pod", func() { + mountFlags := []string{"discard"} + err := checkMountOptions(pvcPath, appPath, f, mountFlags) + if err != nil { + Fail(err.Error()) + } + }) + // Make sure this should be last testcase in this file, because // it deletes pool By("Create a PVC and Delete PVC when backend pool deleted", func() { diff --git a/e2e/utils.go b/e2e/utils.go index 08cc314b2..77979404a 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -943,3 +943,40 @@ func pvcDeleteWhenPoolNotFound(pvcPath string, cephfs bool, f *framework.Framewo err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout) return err } + +func checkMountOptions(pvcPath, appPath string, f *framework.Framework, mountFlags []string) error { + pvc, err := loadPVC(pvcPath) + if pvc == nil { + return err + } + + pvc.Namespace = f.UniqueName + + app, err := loadApp(appPath) + if err != nil { + return err + } + app.Labels = map[string]string{"app": "validate-mount-opt"} + app.Namespace = f.UniqueName + + err = createPVCAndApp("", f, pvc, app) + if err != nil { + return err + } + + opt := metav1.ListOptions{ + LabelSelector: "app=validate-mount-opt", + } + + cmd := fmt.Sprintf("mount |grep %s", app.Spec.Containers[0].VolumeMounts[0].MountPath) + data, stdErr := execCommandInPod(f, cmd, app.Namespace, &opt) + Expect(stdErr).Should(BeEmpty()) + for _, f := range mountFlags { + if !strings.Contains(data, f) { + return fmt.Errorf("mount option %s not found in %s", f, data) + } + } + + err = deletePVCAndApp("", f, pvc, app) + return err +} diff --git a/pkg/rbd/nodeserver.go b/pkg/rbd/nodeserver.go index a866b0f48..7a33e947a 100644 --- a/pkg/rbd/nodeserver.go +++ b/pkg/rbd/nodeserver.go @@ -332,6 +332,7 @@ func (ns *NodeServer) mountVolumeToStagePath(ctx context.Context, req *csi.NodeS } opt := []string{"_netdev"} + opt = csicommon.ConstructMountOptions(opt, req.GetVolumeCapability()) isBlock := req.GetVolumeCapability().GetBlock() != nil if isBlock {