From 819f4f90487e62d94f319abc06c98080ac00c72b Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Fri, 8 Oct 2021 14:01:33 +0530 Subject: [PATCH] e2e: adjust migration tests to use clusterID in the volume context Signed-off-by: Humble Chirammal --- e2e/migration.go | 32 +++++++++++++++++++++++++++++- e2e/rbd.go | 51 ++++++++++++++++++++++++++++-------------------- e2e/staticpvc.go | 2 +- 3 files changed, 62 insertions(+), 23 deletions(-) diff --git a/e2e/migration.go b/e2e/migration.go index c2bad637e..ddeaeaf8b 100644 --- a/e2e/migration.go +++ b/e2e/migration.go @@ -8,6 +8,7 @@ import ( "strings" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/test/e2e/framework" ) @@ -48,7 +49,7 @@ func validateRBDStaticMigrationPVDeletion(f *framework.Framework, appPath, scNam } opt["migration"] = "true" - opt["monitors"] = mon + opt["clusterID"] = getMonsHash(mon) opt["imageFeatures"] = staticPVImageFeature opt["pool"] = defaultRBDPool opt["staticVolume"] = strconv.FormatBool(true) @@ -114,3 +115,32 @@ func composeIntreeMigVolID(mons, rbdImageName string) string { return strings.Join(vhSlice, "_") } + +// generateClusterIDConfigMapForMigration retrieve monitors and generate a hash value which +// is used as a clusterID in the custom configmap, this function also recreate RBD CSI pods +// once the custom config map has been recreated. +func generateClusterIDConfigMapForMigration(f *framework.Framework, c kubernetes.Interface) error { + // create monitors hash by fetching monitors from the cluster. + mons, err := getMons(rookNamespace, c) + if err != nil { + return fmt.Errorf("failed to get monitors %w", err) + } + mon := strings.Join(mons, ",") + inClusterID := getMonsHash(mon) + + clusterInfo := map[string]map[string]string{} + clusterInfo[inClusterID] = map[string]string{} + + // create custom configmap + err = createCustomConfigMap(f.ClientSet, rbdDirPath, clusterInfo) + if err != nil { + return fmt.Errorf("failed to create configmap with error %w", err) + } + // restart csi pods for the configmap to take effect. + err = recreateCSIRBDPods(f) + if err != nil { + return fmt.Errorf("failed to recreate rbd csi pods with error %w", err) + } + + return nil +} diff --git a/e2e/rbd.go b/e2e/rbd.go index e5fb66380..8fcac8228 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -367,32 +367,17 @@ var _ = Describe("RBD", func() { } }) } + // todo: may be remove the below deletion test later once the migration nodestage tests are adjusted + // also to have deletion validation through the same. By("validate RBD migration+static Block PVC Deletion", func() { - // create monitors hash by fetching monitors from the cluster. - mons, err := getMons(rookNamespace, c) + err := generateClusterIDConfigMapForMigration(f, c) if err != nil { - e2elog.Failf("failed to get monitors %v", err) - } - mon := strings.Join(mons, ",") - inClusterID := getMonsHash(mon) - - clusterInfo := map[string]map[string]string{} - clusterInfo[inClusterID] = map[string]string{} - - // create custom configmap - err = createCustomConfigMap(f.ClientSet, rbdDirPath, clusterInfo) - if err != nil { - e2elog.Failf("failed to create configmap with error %v", err) + e2elog.Failf("failed to generate clusterID configmap with error %v", err) } err = createRBDStorageClass(f.ClientSet, f, "migrationsc", nil, nil, deletePolicy) if err != nil { e2elog.Failf("failed to create storageclass with error %v", err) } - // restart csi pods for the configmap to take effect. - err = recreateCSIRBDPods(f) - if err != nil { - e2elog.Failf("failed to recreate rbd csi pods with error %v", err) - } err = validateRBDStaticMigrationPVDeletion(f, rawAppPath, "migrationsc", true) if err != nil { e2elog.Failf("failed to validate rbd migrated static block pv with error %v", err) @@ -1617,21 +1602,45 @@ var _ = Describe("RBD", func() { }) By("validate RBD migration+static FileSystem PVC", func() { - err := validateRBDStaticMigrationPV(f, appPath, false) + err := generateClusterIDConfigMapForMigration(f, c) + if err != nil { + e2elog.Failf("failed to generate clusterID configmap with error %v", err) + } + err = validateRBDStaticMigrationPV(f, appPath, false) if err != nil { e2elog.Failf("failed to validate rbd migrated static pv with error %v", err) } // validate created backend rbd images validateRBDImageCount(f, 0, defaultRBDPool) + err = deleteConfigMap(rbdDirPath) + if err != nil { + e2elog.Failf("failed to delete configmap with error %v", err) + } + err = createConfigMap(rbdDirPath, f.ClientSet, f) + if err != nil { + e2elog.Failf("failed to create configmap with error %v", err) + } }) By("validate RBD migration+static Block PVC", func() { - err := validateRBDStaticMigrationPV(f, rawAppPath, true) + err := generateClusterIDConfigMapForMigration(f, c) + if err != nil { + e2elog.Failf("failed to generate clusterID configmap with error %v", err) + } + err = validateRBDStaticMigrationPV(f, rawAppPath, true) if err != nil { e2elog.Failf("failed to validate rbd migrated static block pv with error %v", err) } // validate created backend rbd images validateRBDImageCount(f, 0, defaultRBDPool) + err = deleteConfigMap(rbdDirPath) + if err != nil { + e2elog.Failf("failed to delete configmap with error %v", err) + } + err = createConfigMap(rbdDirPath, f.ClientSet, f) + if err != nil { + e2elog.Failf("failed to create configmap with error %v", err) + } }) By("validate failure of RBD static PVC without imageFeatures parameter", func() { diff --git a/e2e/staticpvc.go b/e2e/staticpvc.go index c428e51d2..3ef2c96c5 100644 --- a/e2e/staticpvc.go +++ b/e2e/staticpvc.go @@ -256,7 +256,7 @@ func validateRBDStaticMigrationPV(f *framework.Framework, appPath string, isBloc } opt["migration"] = "true" - opt["monitors"] = mon + opt["clusterID"] = getMonsHash(mon) opt["imageFeatures"] = staticPVImageFeature opt["pool"] = defaultRBDPool opt["staticVolume"] = strconv.FormatBool(true)