Skip to content

Commit

Permalink
Support V1 volumesnapshotclass
Browse files Browse the repository at this point in the history
Signed-off-by: danfengl <[email protected]>
  • Loading branch information
danfengliu committed Jul 17, 2023
1 parent b5bd55f commit 95c83a2
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 10 deletions.
51 changes: 48 additions & 3 deletions test/e2e/util/csi/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 7 additions & 1 deletion test/e2e/util/velero/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
49 changes: 43 additions & 6 deletions test/e2e/util/velero/velero_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
}
}
Expand Down

0 comments on commit 95c83a2

Please sign in to comment.