From 0dd152928d5b7d11d1ff5b5a8c8d6dd5dbf6e153 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 28 Oct 2020 11:38:11 +0530 Subject: [PATCH] e2e: add option to set retainpolicy for rbd storageclass added an option to set retain policy for rbd storageclasses. Signed-off-by: Madhu Rajanna --- e2e/rbd.go | 34 +++++++++++++++++----------------- e2e/rbd_helper.go | 3 ++- e2e/upgrade-rbd.go | 2 +- e2e/utils.go | 3 +++ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/e2e/rbd.go b/e2e/rbd.go index 8dfd0ff19..07c316b9d 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -165,7 +165,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to create configmap with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, nil) + err = createRBDStorageClass(f.ClientSet, f, nil, nil, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -282,7 +282,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, map[string]string{"csi.storage.k8s.io/fstype": "ext4"}) + err = createRBDStorageClass(f.ClientSet, f, nil, map[string]string{"csi.storage.k8s.io/fstype": "ext4"}, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -296,7 +296,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, nil) + err = createRBDStorageClass(f.ClientSet, f, nil, nil, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -307,7 +307,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, map[string]string{"encrypted": "true"}) + err = createRBDStorageClass(f.ClientSet, f, nil, map[string]string{"encrypted": "true"}, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -321,7 +321,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, nil) + err = createRBDStorageClass(f.ClientSet, f, nil, nil, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -336,7 +336,7 @@ var _ = Describe("RBD", func() { "encrypted": "true", "encryptionKMSID": "vault-test", } - err = createRBDStorageClass(f.ClientSet, f, nil, scOpts) + err = createRBDStorageClass(f.ClientSet, f, nil, scOpts, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -350,7 +350,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, nil) + err = createRBDStorageClass(f.ClientSet, f, nil, nil, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -640,7 +640,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, map[string]string{"csi.storage.k8s.io/fstype": "xfs"}) + err = createRBDStorageClass(f.ClientSet, f, nil, map[string]string{"csi.storage.k8s.io/fstype": "xfs"}, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -710,7 +710,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, map[string]string{"volumeNamePrefix": volumeNamePrefix}) + err = createRBDStorageClass(f.ClientSet, f, nil, map[string]string{"volumeNamePrefix": volumeNamePrefix}, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -753,7 +753,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, nil) + err = createRBDStorageClass(f.ClientSet, f, nil, nil, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -812,7 +812,7 @@ var _ = Describe("RBD", func() { "{\"domainLabel\":\"zone\",\"value\":\"" + zoneValue + "\"}]}]" err = createRBDStorageClass(f.ClientSet, f, map[string]string{"volumeBindingMode": "WaitForFirstConsumer"}, - map[string]string{"topologyConstrainedPools": topologyConstraint}) + map[string]string{"topologyConstrainedPools": topologyConstraint}, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -861,7 +861,7 @@ var _ = Describe("RBD", func() { "{\"domainLabel\":\"zone\",\"value\":\"" + zoneValue + "\"}]}]" err = createRBDStorageClass(f.ClientSet, f, map[string]string{"volumeBindingMode": "WaitForFirstConsumer"}, - map[string]string{"topologyConstrainedPools": topologyConstraint}) + map[string]string{"topologyConstrainedPools": topologyConstraint}, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -895,7 +895,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, nil) + err = createRBDStorageClass(f.ClientSet, f, nil, nil, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -908,7 +908,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, map[string]string{rbdmountOptions: "debug,invalidOption"}, nil) + err = createRBDStorageClass(f.ClientSet, f, map[string]string{rbdmountOptions: "debug,invalidOption"}, nil, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -946,7 +946,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, nil) + err = createRBDStorageClass(f.ClientSet, f, nil, nil, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -1223,7 +1223,7 @@ var _ = Describe("RBD", func() { } err = createRBDStorageClass(f.ClientSet, f, nil, map[string]string{ "mapOptions": "lock_on_read,queue_depth=1024", - "unmapOptions": "force"}) + "unmapOptions": "force"}, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } @@ -1235,7 +1235,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, nil) + err = createRBDStorageClass(f.ClientSet, f, nil, nil, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } diff --git a/e2e/rbd_helper.go b/e2e/rbd_helper.go index 9f7813c56..a8b20202c 100644 --- a/e2e/rbd_helper.go +++ b/e2e/rbd_helper.go @@ -30,7 +30,7 @@ func rbdOptions(pool string) string { return "--pool=" + pool } -func createRBDStorageClass(c kubernetes.Interface, f *framework.Framework, scOptions, parameters map[string]string) error { +func createRBDStorageClass(c kubernetes.Interface, f *framework.Framework, scOptions, parameters map[string]string, policy v1.PersistentVolumeReclaimPolicy) error { scPath := fmt.Sprintf("%s/%s", rbdExamplePath, "storageclass.yaml") sc, err := getStorageClass(scPath) if err != nil { @@ -72,6 +72,7 @@ func createRBDStorageClass(c kubernetes.Interface, f *framework.Framework, scOpt mOpt := strings.Split(opt, ",") sc.MountOptions = append(sc.MountOptions, mOpt...) } + sc.ReclaimPolicy = &policy _, err = c.StorageV1().StorageClasses().Create(context.TODO(), &sc, metav1.CreateOptions{}) return err } diff --git a/e2e/upgrade-rbd.go b/e2e/upgrade-rbd.go index 8540c9135..a9e2119bf 100644 --- a/e2e/upgrade-rbd.go +++ b/e2e/upgrade-rbd.go @@ -63,7 +63,7 @@ var _ = Describe("RBD Upgrade Testing", func() { if err != nil { e2elog.Failf("failed to create configmap with error %v", err) } - err = createRBDStorageClass(f.ClientSet, f, nil, nil) + err = createRBDStorageClass(f.ClientSet, f, nil, nil, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } diff --git a/e2e/utils.go b/e2e/utils.go index f2803d287..ddb730e72 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -37,6 +37,9 @@ const ( rookTolBoxPodLabel = "app=rook-ceph-tools" rbdmountOptions = "mountOptions" + + retainPolicy = v1.PersistentVolumeReclaimRetain + deletePolicy = v1.PersistentVolumeReclaimDelete ) var (