mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
e2e: adjust migration e2e tests and introduce helper functions
This commit adjust existing migration e2e tests to a couple of tests to cover the scenarios. The seperate filesystem and block tests have been shrinked to single one and also introduced a couple of helper functions to setup and teardown migraition specific secret,configmap and sc. The static pv function has been renamed to a general name while the tests were adjusted. Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
784c3ef06d
commit
cf6fdcb796
136
e2e/migration.go
136
e2e/migration.go
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@ -12,96 +11,6 @@ import (
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
)
|
||||
|
||||
func validateRBDStaticMigrationPVDeletion(f *framework.Framework, appPath, scName string, isBlock bool) error {
|
||||
opt := make(map[string]string)
|
||||
var (
|
||||
rbdImageName = "kubernetes-dynamic-pvc-e0b45b52-7e09-47d3-8f1b-806995fa4412"
|
||||
pvName = "pv-name"
|
||||
pvcName = "pvc-name"
|
||||
namespace = f.UniqueName
|
||||
sc = scName
|
||||
provisionerAnnKey = "pv.kubernetes.io/provisioned-by"
|
||||
provisionerAnnValue = "rbd.csi.ceph.com"
|
||||
)
|
||||
|
||||
c := f.ClientSet
|
||||
PVAnnMap := make(map[string]string)
|
||||
PVAnnMap[provisionerAnnKey] = provisionerAnnValue
|
||||
mons, err := getMons(rookNamespace, c)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get mons: %w", err)
|
||||
}
|
||||
mon := strings.Join(mons, ",")
|
||||
size := staticPVSize
|
||||
// create rbd image
|
||||
cmd := fmt.Sprintf(
|
||||
"rbd create %s --size=%s --image-feature=layering %s",
|
||||
rbdImageName,
|
||||
staticPVSize,
|
||||
rbdOptions(defaultRBDPool))
|
||||
|
||||
_, stdErr, err := execCommandInToolBoxPod(f, cmd, rookNamespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if stdErr != "" {
|
||||
return fmt.Errorf("failed to create rbd image %s", stdErr)
|
||||
}
|
||||
|
||||
opt["migration"] = "true"
|
||||
opt["clusterID"] = getMonsHash(mon)
|
||||
opt["imageFeatures"] = staticPVImageFeature
|
||||
opt["pool"] = defaultRBDPool
|
||||
opt["staticVolume"] = strconv.FormatBool(true)
|
||||
opt["imageName"] = rbdImageName
|
||||
|
||||
// Make volumeID similar to the migration volumeID
|
||||
volID := composeIntreeMigVolID(mon, rbdImageName)
|
||||
pv := getStaticPV(
|
||||
pvName,
|
||||
volID,
|
||||
size,
|
||||
rbdNodePluginSecretName,
|
||||
cephCSINamespace,
|
||||
sc,
|
||||
provisionerAnnValue,
|
||||
isBlock,
|
||||
opt,
|
||||
PVAnnMap,
|
||||
deletePolicy)
|
||||
|
||||
_, err = c.CoreV1().PersistentVolumes().Create(context.TODO(), pv, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("PV Create API error: %w", err)
|
||||
}
|
||||
|
||||
pvc := getStaticPVC(pvcName, pvName, size, namespace, sc, isBlock)
|
||||
|
||||
_, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("PVC Create API error: %w", err)
|
||||
}
|
||||
// bind pvc to app
|
||||
app, err := loadApp(appPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
app.Namespace = namespace
|
||||
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvcName
|
||||
err = createApp(f.ClientSet, app, deployTimeout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = deletePVCAndApp("", f, pvc, app)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete PVC and application: %w", err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// composeIntreeMigVolID create a volID similar to intree migration volID
|
||||
// the migration volID format looks like below
|
||||
// mig-mons-<hash>-image-<UUID_<poolhash>
|
||||
@ -190,6 +99,7 @@ func createMigrationUserSecretAndSC(f *framework.Framework, scName string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// createMigrationSC create a SC with migration specific secrets and clusterid.
|
||||
func createMigrationSC(f *framework.Framework, scName string) error {
|
||||
err := deleteResource(rbdExamplePath + "storageclass.yaml")
|
||||
if err != nil {
|
||||
@ -203,6 +113,13 @@ func createMigrationSC(f *framework.Framework, scName string) error {
|
||||
param["csi.storage.k8s.io/controller-expand-secret-name"] = rbdMigrationProvisionerSecretName
|
||||
param["csi.storage.k8s.io/node-stage-secret-namespace"] = cephCSINamespace
|
||||
param["csi.storage.k8s.io/node-stage-secret-name"] = rbdMigrationNodePluginSecretName
|
||||
mons, err := getMons(rookNamespace, f.ClientSet)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get mons: %w", err)
|
||||
}
|
||||
mon := strings.Join(mons, ",")
|
||||
param["migration"] = "true"
|
||||
param["clusterID"] = getMonsHash(mon)
|
||||
err = createRBDStorageClass(f.ClientSet, f, scName, nil, param, deletePolicy)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create storageclass: %w", err)
|
||||
@ -274,3 +191,40 @@ func deleteProvNodeMigrationSecret(f *framework.Framework, provisionerSecret, no
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// setupMigrationCMSecretAndSC create custom configmap, secret and SC for migration tests.
|
||||
func setupMigrationCMSecretAndSC(f *framework.Framework, scName string) error {
|
||||
c := f.ClientSet
|
||||
if scName == "" {
|
||||
scName = defaultSCName
|
||||
}
|
||||
err := generateClusterIDConfigMapForMigration(f, c)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to generate clusterID configmap: %w", err)
|
||||
}
|
||||
|
||||
err = createMigrationUserSecretAndSC(f, scName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create storageclass: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// tearDownMigrationSetup deletes custom configmap and secret.
|
||||
func tearDownMigrationSetup(f *framework.Framework) error {
|
||||
err := deleteConfigMap(rbdDirPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete configmap: %w", err)
|
||||
}
|
||||
err = createConfigMap(rbdDirPath, f.ClientSet, f)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create configmap: %w", err)
|
||||
}
|
||||
err = deleteProvNodeMigrationSecret(f, true, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete migration users and Secrets associated: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user