Skip to content

Commit

Permalink
Modify the StorageClass install and delete code.
Browse files Browse the repository at this point in the history
* Only install and uninstall SC and VSC once for default cluster.
* Install and uninstall SC and VSC for standby cluster on migration case.
* Refactor the StorageClass and VolumeSnapshotClass YAMLs.
* Prettify the e2e_suite_test.go

Signed-off-by: Xun Jiang <[email protected]>
  • Loading branch information
blackpiglet committed Nov 20, 2024
1 parent aed944c commit 217b38b
Show file tree
Hide file tree
Showing 40 changed files with 813 additions and 372 deletions.
2 changes: 1 addition & 1 deletion test/e2e/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func BackupRestoreTest(backupRestoreTestConfig BackupRestoreTestConfig) {
if InstallVelero {
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*5)
defer ctxCancel()
err = VeleroUninstall(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace)
err = VeleroUninstall(ctx, veleroCfg)
Expect(err).To(Succeed())
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/backups/sync_backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func BackupsSyncTest() {
if InstallVelero {
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*5)
defer ctxCancel()
Expect(VeleroUninstall(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace)).To(Succeed())
Expect(VeleroUninstall(ctx, veleroCfg)).To(Succeed())
}
}
})
Expand Down Expand Up @@ -108,7 +108,7 @@ func BackupsSyncTest() {
})

By("Uninstall velero", func() {
Expect(VeleroUninstall(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace)).To(Succeed())
Expect(VeleroUninstall(ctx, veleroCfg)).To(Succeed())
})

By("Install velero", func() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/backups/ttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TTLTest() {
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*5)
defer ctxCancel()
if InstallVelero {
Expect(VeleroUninstall(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace)).To(Succeed())
Expect(VeleroUninstall(ctx, veleroCfg)).To(Succeed())
}
Expect(DeleteNamespace(ctx, client, test.testNS, false)).To(Succeed(), fmt.Sprintf("Failed to delete the namespace %s", test.testNS))
}
Expand Down
6 changes: 2 additions & 4 deletions test/e2e/basic/api-group/enable_api_group_extentions.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ func APIExtensionsVersionsTest() {
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*5)
defer ctxCancel()
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.DefaultClusterContext)).To(Succeed())
Expect(VeleroUninstall(ctx, veleroCfg.VeleroCLI,
veleroCfg.VeleroNamespace)).To(Succeed())
Expect(VeleroUninstall(ctx, veleroCfg)).To(Succeed())
Expect(DeleteCRDByName(context.Background(), crdName)).To(Succeed())

Expect(KubectlConfigUseContext(context.Background(), veleroCfg.StandbyClusterContext)).To(Succeed())
Expect(VeleroUninstall(ctx, veleroCfg.VeleroCLI,
veleroCfg.VeleroNamespace)).To(Succeed())
Expect(VeleroUninstall(ctx, veleroCfg)).To(Succeed())
Expect(DeleteCRDByName(context.Background(), crdName)).To(Succeed())
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/basic/api-group/enable_api_group_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func APIGroupVersionsTest() {
})
if InstallVelero {
By("Uninstall Velero in api group version case", func() {
Expect(VeleroUninstall(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace)).NotTo(HaveOccurred())
Expect(VeleroUninstall(ctx, veleroCfg)).NotTo(HaveOccurred())
})
}
}
Expand Down
14 changes: 1 addition & 13 deletions test/e2e/basic/backup-volume-info/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/util/common"
. "github.com/vmware-tanzu/velero/test/util/k8s"
. "github.com/vmware-tanzu/velero/test/util/velero"
)

type BackupVolumeInfo struct {
Expand Down Expand Up @@ -108,9 +107,6 @@ func (v *BackupVolumeInfo) CreateResources() error {
return errors.Wrapf(err, "Failed to create namespace %s", createNSName)
}

// Install StorageClass
Expect(InstallTestStorageClasses(fmt.Sprintf("../testdata/storage-class/%s-csi.yaml", v.VeleroCfg.CloudProvider))).To(Succeed(), "Failed to install StorageClass")

// Create deployment
fmt.Printf("Creating deployment in namespaces ...%s\n", createNSName)
// Make sure PVC count is great than 3 to allow both empty volumes and file populated volumes exist per pod
Expand All @@ -120,7 +116,7 @@ func (v *BackupVolumeInfo) CreateResources() error {
var vols []*v1.Volume
for i := 0; i <= pvcCount-1; i++ {
pvcName := fmt.Sprintf("volume-info-pvc-%d", i)
pvc, err := CreatePVC(v.Client, createNSName, pvcName, CSIStorageClassName, nil)
pvc, err := CreatePVC(v.Client, createNSName, pvcName, StorageClassName, nil)
Expect(err).To(Succeed())
volumeName := fmt.Sprintf("volume-info-pv-%d", i)
vols = append(vols, CreateVolumes(pvc.Name, []string{volumeName})...)
Expand Down Expand Up @@ -159,11 +155,3 @@ func (v *BackupVolumeInfo) Destroy() error {

return WaitAllSelectedNSDeleted(v.Ctx, v.Client, "ns-test=true")
}

func (v *BackupVolumeInfo) cleanResource() error {
if err := DeleteStorageClass(v.Ctx, v.Client, CSIStorageClassName); err != nil {
return errors.Wrap(err, "fail to delete the StorageClass")
}

return nil
}
3 changes: 1 addition & 2 deletions test/e2e/basic/backup-volume-info/csi_data_mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@ func (c *CSIDataMoverVolumeInfo) Verify() error {
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].SnapshotDataMovementInfo).NotTo(BeNil())

// Clean SC and VSC
return c.cleanResource()
return nil
}
3 changes: 1 addition & 2 deletions test/e2e/basic/backup-volume-info/csi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,5 @@ func (c *CSISnapshotVolumeInfo) Verify() error {
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].CSISnapshotInfo).NotTo(BeNil())

// Clean SC and VSC
return c.cleanResource()
return nil
}
3 changes: 1 addition & 2 deletions test/e2e/basic/backup-volume-info/filesystem_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,5 @@ func (f *FilesystemUploadVolumeInfo) Verify() error {
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].PVBInfo).NotTo(BeNil())

// Clean SC and VSC
return f.cleanResource()
return nil
}
3 changes: 1 addition & 2 deletions test/e2e/basic/backup-volume-info/native_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@ func (n *NativeSnapshotVolumeInfo) Verify() error {
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].NativeSnapshotInfo).NotTo(BeNil())

// Clean SC and VSC
return n.cleanResource()
return nil
}
3 changes: 1 addition & 2 deletions test/e2e/basic/backup-volume-info/skipped_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,5 @@ func (s *SkippedVolumeInfo) Verify() error {
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].Skipped).To(BeIdenticalTo(true))

// Clean SC and VSC
return s.cleanResource()
return nil
}
8 changes: 0 additions & 8 deletions test/e2e/basic/pvc-selected-node-changing.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ func (p *PVCSelectedNodeChanging) CreateResources() error {
fmt.Sprintf("Failed to create namespace %s", p.namespace))
})

By(fmt.Sprintf("Create a storage class %s.", StorageClassName), func() {
Expect(InstallStorageClass(context.Background(), fmt.Sprintf("../testdata/storage-class/%s.yaml", p.VeleroCfg.CloudProvider))).To(Succeed())
})

By(fmt.Sprintf("Create a storage class %s.", StorageClassName), func() {
Expect(InstallTestStorageClasses(fmt.Sprintf("../testdata/storage-class/%s.yaml", p.VeleroCfg.CloudProvider))).To(Succeed(), "Failed to install storage class")
})

By(fmt.Sprintf("Create pod %s in namespace %s", p.podName, p.namespace), func() {
nodeNameList, err := GetWorkerNodes(p.Ctx)
Expect(err).To(Succeed())
Expand Down
15 changes: 5 additions & 10 deletions test/e2e/basic/storage-class-changing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type StorageClasssChanging struct {
TestCase
labels map[string]string
data map[string]string
configmaptName string
cmName string
namespace string
srcStorageClass string
desStorageClass string
Expand Down Expand Up @@ -51,7 +51,7 @@ func (s *StorageClasssChanging) Init() error {
s.labels = map[string]string{"velero.io/change-storage-class": "RestoreItemAction",
"velero.io/plugin-config": ""}
s.data = map[string]string{s.srcStorageClass: s.desStorageClass}
s.configmaptName = "change-storage-class-config"
s.cmName = "change-storage-class-config"
s.volume = "volume-1"
s.pvcName = fmt.Sprintf("pvc-%s", s.volume)
s.podName = "pod-1"
Expand All @@ -72,10 +72,6 @@ func (s *StorageClasssChanging) CreateResources() error {
"app": "test",
}

By(("Installing storage class..."), func() {
Expect(InstallTestStorageClasses(fmt.Sprintf("../testdata/storage-class/%s.yaml", s.VeleroCfg.CloudProvider))).To(Succeed(), "Failed to install storage class")
})

By(fmt.Sprintf("Create namespace %s", s.namespace), func() {
Expect(CreateNamespace(s.Ctx, s.Client, s.namespace)).To(Succeed(),
fmt.Sprintf("Failed to create namespace %s", s.namespace))
Expand All @@ -94,8 +90,8 @@ func (s *StorageClasssChanging) CreateResources() error {
Expect(err).To(Succeed())
})

By(fmt.Sprintf("Create ConfigMap %s in namespace %s", s.configmaptName, s.VeleroCfg.VeleroNamespace), func() {
_, err := CreateConfigMap(s.Client.ClientGo, s.VeleroCfg.VeleroNamespace, s.configmaptName, s.labels, s.data)
By(fmt.Sprintf("Create ConfigMap %s in namespace %s", s.cmName, s.VeleroCfg.VeleroNamespace), func() {
_, err := CreateConfigMap(s.Client.ClientGo, s.VeleroCfg.VeleroNamespace, s.cmName, s.labels, s.data)
Expect(err).To(Succeed(), fmt.Sprintf("failed to create configmap in the namespace %q", s.VeleroCfg.VeleroNamespace))
})
return nil
Expand Down Expand Up @@ -149,8 +145,7 @@ func (s *StorageClasssChanging) Clean() error {
Expect(CleanupNamespacesWithPoll(s.Ctx, s.Client, s.CaseBaseName)).To(Succeed(),
fmt.Sprintf("Failed to delete namespace %s", s.CaseBaseName))
})
DeleteConfigmap(s.Client.ClientGo, s.VeleroCfg.VeleroNamespace, s.configmaptName)
DeleteStorageClass(s.Ctx, s.Client, s.desStorageClass)
DeleteConfigMap(s.Client.ClientGo, s.VeleroCfg.VeleroNamespace, s.cmName)
s.TestCase.Clean()
}

Expand Down
Loading

0 comments on commit 217b38b

Please sign in to comment.