From 95c83a2df5bbc0719cf1ff48863d6e07895b43e1 Mon Sep 17 00:00:00 2001 From: danfengl Date: Mon, 17 Jul 2023 09:57:34 +0000 Subject: [PATCH] Support V1 volumesnapshotclass Signed-off-by: danfengl --- test/e2e/util/csi/common.go | 51 ++++++++++++++++++++++++++-- test/e2e/util/velero/install.go | 8 ++++- test/e2e/util/velero/velero_utils.go | 49 ++++++++++++++++++++++---- 3 files changed, 98 insertions(+), 10 deletions(-) diff --git a/test/e2e/util/csi/common.go b/test/e2e/util/csi/common.go index 677de41279..56af1ef58f 100644 --- a/test/e2e/util/csi/common.go +++ b/test/e2e/util/csi/common.go @@ -91,6 +91,43 @@ func GetCsiSnapshotHandle(client TestClient, backupName string) ([]string, error } return snapshotHandleList, nil } +func GetCsiSnapshotHandleV1(client TestClient, backupName string) ([]string, error) { + _, snapshotClient, err := GetClients() + if err != nil { + return nil, err + } + vscList, err1 := snapshotClient.SnapshotV1().VolumeSnapshotContents().List(context.TODO(), metav1.ListOptions{}) + if err1 != nil { + return nil, err + } + + var snapshotHandleList []string + for _, i := range vscList.Items { + if i.Status == nil { + fmt.Println("SnapshotHandle Status s nil") + continue + } + if i.Status.SnapshotHandle == nil { + fmt.Println("SnapshotHandle is nil") + continue + } + + if i.Labels == nil { + fmt.Println("VolumeSnapshotContents label is nil") + continue + } + + if i.Labels["velero.io/backup-name"] == backupName { + tmp := strings.Split(*i.Status.SnapshotHandle, "/") + snapshotHandleList = append(snapshotHandleList, tmp[len(tmp)-1]) + } + } + + if len(snapshotHandleList) == 0 { + fmt.Printf("No VolumeSnapshotContent from backup %s", backupName) + } + return snapshotHandleList, nil +} func GetVolumeSnapshotContentNameByPod(client TestClient, podName, namespace, backupName string) (string, error) { pvcList, err := GetPvcByPodName(context.Background(), namespace, podName) if err != nil { @@ -128,11 +165,19 @@ func GetVolumeSnapshotContentNameByPod(client TestClient, podName, namespace, ba return "", errors.New(fmt.Sprintf("Fail to get VolumeSnapshotContentName for pod %s under namespace %s", podName, namespace)) } -func CheckVolumeSnapshotCR(client TestClient, backupName string, expectedCount int) ([]string, error) { +func CheckVolumeSnapshotCR(client TestClient, backupName string, expectedCount int, apiVersion string) ([]string, error) { var err error var snapshotContentNameList []string - if snapshotContentNameList, err = GetCsiSnapshotHandle(client, backupName); err != nil { - return nil, errors.Wrap(err, "Fail to get Azure CSI snapshot content") + if apiVersion == "v1beta1" { + if snapshotContentNameList, err = GetCsiSnapshotHandle(client, backupName); err != nil { + return nil, errors.Wrap(err, "Fail to get Azure CSI snapshot content") + } + } else if apiVersion == "v1" { + if snapshotContentNameList, err = GetCsiSnapshotHandleV1(client, backupName); err != nil { + return nil, errors.Wrap(err, "Fail to get Azure CSI snapshot content") + } + } else { + return nil, errors.New("API version is invalid") } if len(snapshotContentNameList) != expectedCount { return nil, errors.New(fmt.Sprintf("Snapshot count %d is not as expect %d", len(snapshotContentNameList), expectedCount)) diff --git a/test/e2e/util/velero/install.go b/test/e2e/util/velero/install.go index 1830b15d3a..be8727b549 100644 --- a/test/e2e/util/velero/install.go +++ b/test/e2e/util/velero/install.go @@ -111,7 +111,10 @@ func VeleroInstall(ctx context.Context, veleroCfg *VeleroConfig, isStandbyCluste return errors.WithMessagef(err, "Failed to get Velero InstallOptions for plugin provider %s", veleroCfg.ObjectStoreProvider) } veleroInstallOptions.UseVolumeSnapshots = veleroCfg.UseVolumeSnapshots - veleroInstallOptions.UseNodeAgent = veleroCfg.UseNodeAgent + if !veleroCfg.UseRestic { + veleroInstallOptions.UseNodeAgent = veleroCfg.UseNodeAgent + } + veleroInstallOptions.UseRestic = veleroCfg.UseRestic veleroInstallOptions.Image = veleroCfg.VeleroImage veleroInstallOptions.Namespace = veleroCfg.VeleroNamespace veleroInstallOptions.UploaderType = veleroCfg.UploaderType @@ -198,6 +201,9 @@ func installVeleroServer(ctx context.Context, cli, cloudProvider string, options if len(options.Image) > 0 { args = append(args, "--image", options.Image) } + if options.UseRestic { + args = append(args, "--use-restic") + } if options.UseNodeAgent { args = append(args, "--use-node-agent") } diff --git a/test/e2e/util/velero/velero_utils.go b/test/e2e/util/velero/velero_utils.go index c5d1834c16..279d0f4a1b 100644 --- a/test/e2e/util/velero/velero_utils.go +++ b/test/e2e/util/velero/velero_utils.go @@ -56,6 +56,27 @@ const RestoreObjectsPrefix = "restores" const PluginsObjectsPrefix = "plugins" var pluginsMatrix = map[string]map[string][]string{ + "v1.7": { + "aws": {"velero/velero-plugin-for-aws:v1.3.0"}, + "azure": {"velero/velero-plugin-for-microsoft-azure:v1.3.0"}, + "vsphere": {"vsphereveleroplugin/velero-plugin-for-vsphere:v1.3.0"}, + "gcp": {"velero/velero-plugin-for-gcp:v1.3.0"}, + "csi": {"velero/velero-plugin-for-csi:v0.2.0"}, + }, + "v1.8": { + "aws": {"velero/velero-plugin-for-aws:v1.4.0"}, + "azure": {"velero/velero-plugin-for-microsoft-azure:v1.4.0"}, + "vsphere": {"vsphereveleroplugin/velero-plugin-for-vsphere:v1.3.1"}, + "gcp": {"velero/velero-plugin-for-gcp:v1.4.0"}, + "csi": {"velero/velero-plugin-for-csi:v0.2.0"}, + }, + "v1.9": { + "aws": {"velero/velero-plugin-for-aws:v1.5.0"}, + "azure": {"velero/velero-plugin-for-microsoft-azure:v1.5.0"}, + "vsphere": {"vsphereveleroplugin/velero-plugin-for-vsphere:v1.4.0"}, + "gcp": {"velero/velero-plugin-for-gcp:v1.5.0"}, + "csi": {"velero/velero-plugin-for-csi:v0.3.0"}, + }, "v1.10": { "aws": {"velero/velero-plugin-for-aws:v1.6.0"}, "azure": {"velero/velero-plugin-for-microsoft-azure:v1.6.0"}, @@ -593,11 +614,17 @@ func getPlugins(ctx context.Context, veleroCfg VeleroConfig) ([]string, error) { if objectStoreProvider == "" { objectStoreProvider = cloudProvider } - version, err := getVeleroVersion(ctx, veleroCLI, true) - if err != nil { - return nil, errors.WithMessage(err, "failed to get velero version") - } + var version string + var err error + if veleroCfg.VeleroVersion != "" { + version = veleroCfg.VeleroVersion + } else { + version, err = getVeleroVersion(ctx, veleroCLI, true) + if err != nil { + return nil, errors.WithMessage(err, "failed to get velero version") + } + } if veleroCfg.SnapshotMoveData && veleroCfg.DataMoverPlugin == "" { needDataMoverPlugin = true } @@ -1107,13 +1134,23 @@ func GetResticRepositories(ctx context.Context, veleroNamespace, targetNamespace func GetSnapshotCheckPoint(client TestClient, VeleroCfg VeleroConfig, expectCount int, namespaceBackedUp, backupName string, KibishiiPVCNameList []string) (SnapshotCheckPoint, error) { var snapshotCheckPoint SnapshotCheckPoint - var err error + snapshotCheckPoint.ExpectCount = expectCount snapshotCheckPoint.NamespaceBackedUp = namespaceBackedUp snapshotCheckPoint.PodName = KibishiiPVCNameList if VeleroCfg.CloudProvider == "azure" && strings.EqualFold(VeleroCfg.Features, "EnableCSI") { snapshotCheckPoint.EnableCSI = true - if snapshotCheckPoint.SnapshotIDList, err = util.CheckVolumeSnapshotCR(client, backupName, expectCount); err != nil { + resourceName := "snapshot.storage.k8s.io" + + srcVersions, err := GetAPIVersions(VeleroCfg.DefaultClient, resourceName) + + if err != nil { + return snapshotCheckPoint, err + } + if len(srcVersions) == 0 { + return snapshotCheckPoint, errors.New("Fail to get APIVersion") + } + if snapshotCheckPoint.SnapshotIDList, err = util.CheckVolumeSnapshotCR(client, backupName, expectCount, srcVersions[0]); err != nil { return snapshotCheckPoint, errors.Wrapf(err, "Fail to get Azure CSI snapshot content") } }