Skip to content

Commit

Permalink
Add backupPVC config e2e
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Pampattiwar <[email protected]>
  • Loading branch information
shubham-pampattiwar committed Sep 19, 2024
1 parent 3f9c2dc commit 6d9ffb3
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
105 changes: 105 additions & 0 deletions test/e2e/basic/backup-pvc-config.go
Original file line number Diff line number Diff line change
@@ -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() {

Check failure on line 64 in test/e2e/basic/backup-pvc-config.go

View workflow job for this annotation

GitHub Actions / Run Linter Check

printf: fmt.Sprintf format %s reads arg #1, but call has 0 args (govet)
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
}
3 changes: 3 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 6d9ffb3

Please sign in to comment.