From 6d9ffb3671e5bd9b0cf1e8ee33091219cf3981dc Mon Sep 17 00:00:00 2001 From: Shubham Pampattiwar Date: Wed, 18 Sep 2024 17:50:07 -0700 Subject: [PATCH] Add backupPVC config e2e Signed-off-by: Shubham Pampattiwar --- test/e2e/basic/backup-pvc-config.go | 105 ++++++++++++++++++++++++++++ test/e2e/e2e_suite_test.go | 3 + 2 files changed, 108 insertions(+) create mode 100644 test/e2e/basic/backup-pvc-config.go diff --git a/test/e2e/basic/backup-pvc-config.go b/test/e2e/basic/backup-pvc-config.go new file mode 100644 index 00000000000..aeaf9ce1659 --- /dev/null +++ b/test/e2e/basic/backup-pvc-config.go @@ -0,0 +1,105 @@ +package basic + +import ( + "fmt" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + . "github.com/vmware-tanzu/velero/test" + . "github.com/vmware-tanzu/velero/test/e2e/test" + . "github.com/vmware-tanzu/velero/test/util/k8s" + . "github.com/vmware-tanzu/velero/test/util/velero" +) + +type BackupPVCConfigChange struct { + TestCase + data map[string]string + configmapName string + namespace string + sourcePVCStorageClassName string + backupPVCStorageClassName string + pvcName string + volumeName string + podName string + deploymentName string +} + +var BackupPVCConfigChangeTest = TestFunc(&BackupPVCConfigChange{}) +var configData = map[string]string{ + "backupPVC": ` + { + "e2e-storage-class": { + "storageClass": "e2e-storage-class-2", + "readOnly": true + }, + }`, +} + +func (b *BackupPVCConfigChange) Init() error { + b.TestCase.Init() + b.configmapName = "node-agent-configmap" + b.VeleroCfg.Options.NodeAgentConfigMap = b.configmapName + b.CaseBaseName = "BackupPVCConfigChange" + b.UUIDgen + b.namespace = b.CaseBaseName + b.BackupName = "backup-" + b.CaseBaseName + b.RestoreName = "restore-" + b.CaseBaseName + b.sourcePVCStorageClassName = StorageClassName + b.backupPVCStorageClassName = StorageClassName2 + b.data = configData + b.volumeName = "volume-1" + b.pvcName = fmt.Sprintf("pvc-%s", b.volumeName) + b.podName = "pod-1" + b.BackupArgs = []string{ + "create", "--namespace", b.VeleroCfg.VeleroNamespace, "pvc", b.pvcName, "backup", b.BackupName, + "--include-namespaces", b.namespace, + "--snapshot-move-data=true", "--wait", + } + return nil +} + +func (b *BackupPVCConfigChange) CreateResources() error { + label := map[string]string{ + "app": "test", + } + + By(fmt.Sprintf("Installing Storage Class %s"), func() { + Expect(InstallTestStorageClasses(fmt.Sprintf("../testdata/storage-class/%s.yaml", b.VeleroCfg.CloudProvider))).To(Succeed(), "Failed to install Storage Class") + }) + + By(fmt.Sprintf("Creating namespace %s", b.namespace), func() { + Expect(CreateNamespace(b.Ctx, b.Client, b.namespace)).To(Succeed(), "Failed to create namespace %s", b.namespace) + }) + + By(fmt.Sprintf("Creating test app deployment in namespace %s", b.namespace), func() { + pvc, err := CreatePVC(b.Client, b.namespace, b.pvcName, b.sourcePVCStorageClassName, nil) + Expect(err).To(Succeed(), "Failed to create pvc in namespace %s", b.namespace) + + vols := CreateVolumes(pvc.Name, []string{b.volumeName}) + + deployment := NewDeployment(b.CaseBaseName, b.namespace, 1, label, nil).WithVolume(vols).Result() + deployment, err = CreateDeployment(b.Client.ClientGo, b.namespace, deployment) + Expect(err).To(Succeed(), "Failed to create deployment in namespace %s", b.namespace) + b.deploymentName = deployment.Name + err = WaitForReadyDeployment(b.Client.ClientGo, b.namespace, b.deploymentName) + Expect(err).To(Succeed(), "Deployment %s in namespace %s should be ready", b.deploymentName, b.namespace) + }) + + By(fmt.Sprintf("Creating Node Agent Config Map %s in namespace %s", b.configmapName, b.namespace), func() { + _, err := CreateConfigMap(b.Client.ClientGo, b.VeleroCfg.Namespace, b.configmapName, nil, b.data) + Expect(err).To(Succeed(), "Failed to create configmap in namespace %s", b.namespace) + }) + + return nil +} + +func (b *BackupPVCConfigChange) Clean() error { + if !b.VeleroCfg.Debug { + By(fmt.Sprintf("Start to destroy namespace %s", b.CaseBaseName), func() { + Expect(CleanupNamespacesWithPoll(b.Ctx, b.Client, b.CaseBaseName)).To(Succeed(), "Failed to destroy namespace %s", b.CaseBaseName) + }) + DeleteConfigmap(b.Client.ClientGo, b.VeleroCfg.Namespace, b.configmapName) + DeleteStorageClass(b.Ctx, b.Client, b.sourcePVCStorageClassName) + DeleteStorageClass(b.Ctx, b.Client, b.backupPVCStorageClassName) + b.TestCase.Clean() + } + return nil +} diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 10319580845..42631b9aff4 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -139,6 +139,9 @@ var _ = Describe("Service NodePort reservation during restore is configurable", var _ = Describe("Storage class of persistent volumes and persistent volume claims can be changed during restores", Label("Basic", "StorageClass"), StorageClasssChangingTest) +var _ = Describe("Changing BackupPVC Configuration for Data Movement Backup Operation", + Label("Basic", "backupPVCConfig"), BackupPVCConfigChangeTest) + var _ = Describe("Node selectors of persistent volume claims can be changed during restores", Label("Basic", "SelectedNode", "SKIP_KIND"), PVCSelectedNodeChangingTest)