Skip to content

Commit

Permalink
Skip uninstall and resource cleanup when fail-fast is enabled.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <[email protected]>
  • Loading branch information
blackpiglet committed Sep 13, 2024
1 parent 3f9c2dc commit f8a1045
Show file tree
Hide file tree
Showing 26 changed files with 301 additions and 235 deletions.
5 changes: 2 additions & 3 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ ADDITIONAL_BSL_PREFIX ?=
ADDITIONAL_BSL_CONFIG ?=

FEATURES ?=
DEBUG_E2E_TEST ?= false
DEBUG_VELERO_POD_RESTART ?= false
VELERO_SERVER_DEBUG_MODE ?= false

Expand Down Expand Up @@ -148,10 +147,10 @@ COMMON_ARGS := --velerocli=$(VELERO_CLI) \
--features=$(FEATURES) \
--install-velero=$(INSTALL_VELERO) \
--registry-credential-file=$(REGISTRY_CREDENTIAL_FILE) \
--debug-e2e-test=$(DEBUG_E2E_TEST) \
--velero-server-debug-mode=$(VELERO_SERVER_DEBUG_MODE) \
--uploader-type=$(UPLOADER_TYPE) \
--debug-velero-pod-restart=$(DEBUG_VELERO_POD_RESTART)
--debug-velero-pod-restart=$(DEBUG_VELERO_POD_RESTART) \
--fail-fast=$(FAIL_FAST)

# Make sure ginkgo is in $GOBIN
.PHONY:ginkgo
Expand Down
383 changes: 222 additions & 161 deletions test/e2e/README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/e2e/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func BackupRestoreTest(backupRestoreTestConfig BackupRestoreTestConfig) {
})

AfterEach(func() {
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
if backupRestoreTestConfig.isRetainPVTest {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/backups/deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func backup_deletion_test(useVolumeSnapshots bool) {
})

AfterEach(func() {
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
Expand Down Expand Up @@ -104,7 +104,7 @@ func runBackupDeletionTests(client TestClient, veleroCfg VeleroConfig, backupLoc
if err := CreateNamespace(oneHourTimeout, client, ns); err != nil {
return errors.Wrapf(err, "Failed to create namespace %s to install Kibishii workload", ns)
}
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
defer func() {
if err := DeleteNamespace(context.Background(), client, ns, true); err != nil {
fmt.Println(errors.Wrapf(err, "failed to delete the namespace %q", ns))
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/backups/sync_backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func BackupsSyncTest() {
})

AfterEach(func() {
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
Expand All @@ -82,7 +82,7 @@ func BackupsSyncTest() {
By(fmt.Sprintf("Prepare workload as target to backup by creating namespace %s namespace", test.testNS))
Expect(CreateNamespace(ctx, *veleroCfg.ClientToInstallVelero, test.testNS)).To(Succeed(),
fmt.Sprintf("Failed to create %s namespace", test.testNS))
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
defer func() {
Expect(DeleteNamespace(ctx, *veleroCfg.ClientToInstallVelero, test.testNS, false)).To(Succeed(), fmt.Sprintf("Failed to delete the namespace %s", test.testNS))
}()
Expand Down Expand Up @@ -125,7 +125,7 @@ func BackupsSyncTest() {
Expect(CreateNamespace(ctx, *veleroCfg.ClientToInstallVelero, test.testNS)).To(Succeed(),
fmt.Sprintf("Failed to create %s namespace", test.testNS))
})
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
defer func() {
Expect(DeleteNamespace(ctx, *veleroCfg.ClientToInstallVelero, test.testNS, false)).To(Succeed(),
fmt.Sprintf("Failed to delete the namespace %s", test.testNS))
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 @@ -74,7 +74,7 @@ func TTLTest() {

AfterEach(func() {
veleroCfg.GCFrequency = ""
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/basic/api-group/enable_api_group_extentions.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func APIExtensionsVersionsTest() {
})
})
AfterEach(func() {
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
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 @@ -79,7 +79,7 @@ func APIGroupVersionsTest() {
})

AfterEach(func() {
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
for i := 0; i < testCaseNum; i++ {
curResource := fmt.Sprintf("rockband%ds", i)
curGroup := fmt.Sprintf("%s.%d", group, i)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/basic/namespace-mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (n *NamespaceMapping) Verify() error {
}

func (n *NamespaceMapping) Clean() error {
if !n.VeleroCfg.Debug {
if !n.VeleroCfg.FailFast {
if err := DeleteStorageClass(context.Background(), n.Client, KibishiiStorageClassName); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/basic/pvc-selected-node-changing.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (p *PVCSelectedNodeChanging) Verify() error {
}

func (p *PVCSelectedNodeChanging) Clean() error {
if !p.VeleroCfg.Debug {
if !p.VeleroCfg.FailFast {
p.TestCase.Clean()
By(fmt.Sprintf("Clean namespace with prefix %s after test", p.mappedNS), func() {
CleanupNamespaces(p.Ctx, p.Client, p.mappedNS)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/basic/resources-check/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (r *RBACCase) Destroy() error {
}

func (r *RBACCase) Clean() error {
if !r.VeleroCfg.Debug {
if !r.VeleroCfg.FailFast {
return r.Destroy()
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/basic/storage-class-changing.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *StorageClasssChanging) Verify() error {
}

func (s *StorageClasssChanging) Clean() error {
if !s.VeleroCfg.Debug {
if !s.VeleroCfg.FailFast {
By(fmt.Sprintf("Start to destroy namespace %s......", s.CaseBaseName), func() {
Expect(CleanupNamespacesWithPoll(s.Ctx, s.Client, s.CaseBaseName)).To(Succeed(),
fmt.Sprintf("Failed to delete namespace %s", s.CaseBaseName))
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/bsl-mgmt/deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func BslDeletionTest(useVolumeSnapshots bool) {
})

AfterEach(func() {
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
By("Clean backups after test", func() {
veleroCfg.ClientToInstallVelero = veleroCfg.DefaultClient
DeleteAllBackups(context.Background(), &veleroCfg)
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func init() {
flag.StringVar(&VeleroCfg.AdditionalBSLConfig, "additional-bsl-config", "", "configuration to use for the additional backup storage location. Format is key1=value1,key2=value2")
flag.StringVar(&VeleroCfg.AdditionalBSLCredentials, "additional-bsl-credentials-file", "", "file containing credentials for additional backup storage location provider. Required if testing multiple credentials support.")
flag.StringVar(&VeleroCfg.Features, "features", "", "comma-separated list of features to enable for this Velero process.")
flag.BoolVar(&VeleroCfg.Debug, "debug-e2e-test", false, "A Switch for enable or disable test data cleaning action.")
flag.StringVar(&VeleroCfg.GCFrequency, "garbage-collection-frequency", "", "frequency of garbage collection.")
flag.StringVar(&VeleroCfg.DefaultClusterContext, "default-cluster-context", "", "default cluster's kube config context, it's for migration test.")
flag.StringVar(&VeleroCfg.StandbyClusterContext, "standby-cluster-context", "", "standby cluster's kube config context, it's for migration test.")
Expand All @@ -103,6 +102,7 @@ func init() {
flag.StringVar(&VeleroCfg.EKSPolicyARN, "eks-policy-arn", "", "EKS plicy ARN for creating AWS IAM service account.")
flag.StringVar(&VeleroCfg.DefaultCLSServiceAccountName, "default-cls-service-account-name", "", "default cluster service account name.")
flag.StringVar(&VeleroCfg.StandbyCLSServiceAccountName, "standby-cls-service-account-name", "", "standby cluster service account name.")
flag.BoolVar(&VeleroCfg.FailFast, "fail-fast", true, "a switch for failing fast on meeting error.")
}

// Add label [SkipVanillaZfs]:
Expand Down Expand Up @@ -302,7 +302,9 @@ var _ = BeforeSuite(func() {
})

var _ = AfterSuite(func() {
if InstallVelero && !VeleroCfg.Debug {
// If the Velero is installed during test, and the FailFast is not enabled,
// uninstall Velero. If not, either Velero is not installed, or kept it for debug.
if InstallVelero && !VeleroCfg.FailFast {
By("release test resources after testing")
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*5)
defer ctxCancel()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func MigrationTest(useVolumeSnapshots bool, veleroCLI2Version VeleroCLI2Version)
}
})
AfterEach(func() {
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
By(fmt.Sprintf("Uninstall Velero on cluster %s", veleroCfg.DefaultClusterContext), func() {
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*5)
defer ctxCancel()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/resourcemodifiers/resource_modifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (r *ResourceModifiersCase) Verify() error {

func (r *ResourceModifiersCase) Clean() error {
// If created some resources which is not in current test namespace, we NEED to override the base Clean function
if !r.VeleroCfg.Debug {
if !r.VeleroCfg.FailFast {
if err := DeleteConfigmap(r.Client.ClientGo, r.VeleroCfg.VeleroNamespace, r.cmName); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/resourcepolicies/resource_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (r *ResourcePoliciesCase) Verify() error {

func (r *ResourcePoliciesCase) Clean() error {
// If created some resources which is not in current test namespace, we NEED to override the base Clean function
if !r.VeleroCfg.Debug {
if !r.VeleroCfg.FailFast {
if err := r.deleteTestStorageClassList([]string{StorageClassName, StorageClassName2}); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/schedule/ordered_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (o *OrderedResources) Verify() error {
}

func (o *OrderedResources) Clean() error {
if !o.VeleroCfg.Debug {
if !o.VeleroCfg.FailFast {
Expect(VeleroScheduleDelete(o.Ctx, o.VeleroCfg.VeleroCLI, o.VeleroCfg.VeleroNamespace, o.ScheduleName)).To(Succeed())
Expect(o.TestCase.Clean()).To(Succeed())
}
Expand Down
84 changes: 42 additions & 42 deletions test/e2e/schedule/schedule-backup-creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,63 +32,63 @@ type ScheduleBackupCreation struct {

var ScheduleBackupCreationTest func() = TestFunc(&ScheduleBackupCreation{})

func (n *ScheduleBackupCreation) Init() error {
n.TestCase.Init()
n.CaseBaseName = "schedule-backup-creation-test" + n.UUIDgen
n.ScheduleName = "schedule-" + n.CaseBaseName
n.namespace = n.GetTestCase().CaseBaseName
n.Period = 3 // Unit is minute
n.verifyTimes = 5 // More larger verify times more confidence we have
func (s *ScheduleBackupCreation) Init() error {
s.TestCase.Init()
s.CaseBaseName = "schedule-backup-creation-test" + s.UUIDgen
s.ScheduleName = "schedule-" + s.CaseBaseName
s.namespace = s.GetTestCase().CaseBaseName
s.Period = 3 // Unit is minute
s.verifyTimes = 5 // More larger verify times more confidence we have
podSleepDurationStr := "300s"
n.podSleepDuration, _ = time.ParseDuration(podSleepDurationStr)
n.TestMsg = &TestMSG{
s.podSleepDuration, _ = time.ParseDuration(podSleepDurationStr)
s.TestMsg = &TestMSG{
Desc: "Schedule controller wouldn't create a new backup when it still has pending or InProgress backup",
FailedMSG: "Failed to verify schedule back creation behavior",
Text: "Schedule controller wouldn't create a new backup when it still has pending or InProgress backup",
}
n.podAnn = map[string]string{
"pre.hook.backup.velero.io/container": n.podName,
s.podAnn = map[string]string{
"pre.hook.backup.velero.io/container": s.podName,
"pre.hook.backup.velero.io/command": "[\"sleep\", \"" + podSleepDurationStr + "\"]",
"pre.hook.backup.velero.io/timeout": "600s",
}
n.volume = "volume-1"
n.podName = "pod-1"
n.pvcName = "pvc-1"
n.ScheduleArgs = []string{
"--include-namespaces", n.namespace,
"--schedule=*/" + fmt.Sprintf("%v", n.Period) + " * * * *",
s.volume = "volume-1"
s.podName = "pod-1"
s.pvcName = "pvc-1"
s.ScheduleArgs = []string{
"--include-namespaces", s.namespace,
"--schedule=*/" + fmt.Sprintf("%v", s.Period) + " * * * *",
}
Expect(n.Period).To(BeNumerically("<", 30))
Expect(s.Period).To(BeNumerically("<", 30))
return nil
}

func (p *ScheduleBackupCreation) CreateResources() error {
By(fmt.Sprintf("Create namespace %s", p.namespace), func() {
Expect(CreateNamespace(p.Ctx, p.Client, p.namespace)).To(Succeed(),
fmt.Sprintf("Failed to create namespace %s", p.namespace))
func (s *ScheduleBackupCreation) CreateResources() error {
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))
})

By(fmt.Sprintf("Create pod %s in namespace %s", p.podName, p.namespace), func() {
_, err := CreatePod(p.Client, p.namespace, p.podName, "default", p.pvcName, []string{p.volume}, nil, p.podAnn)
By(fmt.Sprintf("Create pod %s in namespace %s", s.podName, s.namespace), func() {
_, err := CreatePod(s.Client, s.namespace, s.podName, "default", s.pvcName, []string{s.volume}, nil, s.podAnn)
Expect(err).To(Succeed())
err = WaitForPods(p.Ctx, p.Client, p.namespace, []string{p.podName})
err = WaitForPods(s.Ctx, s.Client, s.namespace, []string{s.podName})
Expect(err).To(Succeed())
})
return nil
}

func (n *ScheduleBackupCreation) Backup() error {
func (s *ScheduleBackupCreation) Backup() error {
// Wait until the beginning of the given period to create schedule, it will give us
// a predictable period to wait for the first scheduled backup, and verify no immediate
// scheduled backup was created between schedule creation and first scheduled backup.
By(fmt.Sprintf("Creating schedule %s ......\n", n.ScheduleName), func() {
for i := 0; i < n.Period*60/30; i++ {
By(fmt.Sprintf("Creating schedule %s ......\n", s.ScheduleName), func() {
for i := 0; i < s.Period*60/30; i++ {
time.Sleep(30 * time.Second)
now := time.Now().Minute()
triggerNow := now % n.Period
triggerNow := now % s.Period
if triggerNow == 0 {
Expect(VeleroScheduleCreate(n.Ctx, n.VeleroCfg.VeleroCLI, n.VeleroCfg.VeleroNamespace, n.ScheduleName, n.ScheduleArgs)).To(Succeed(), func() string {
RunDebug(context.Background(), n.VeleroCfg.VeleroCLI, n.VeleroCfg.VeleroNamespace, "", "")
Expect(VeleroScheduleCreate(s.Ctx, s.VeleroCfg.VeleroCLI, s.VeleroCfg.VeleroNamespace, s.ScheduleName, s.ScheduleArgs)).To(Succeed(), func() string {
RunDebug(context.Background(), s.VeleroCfg.VeleroCLI, s.VeleroCfg.VeleroNamespace, "", "")
return "Fail to create schedule"
})
break
Expand All @@ -100,13 +100,13 @@ func (n *ScheduleBackupCreation) Backup() error {
time.Sleep(1 * time.Minute)
})

By(fmt.Sprintf("Get backups every %d minute, and backups count should increase 1 more step in the same pace\n", n.Period), func() {
for i := 1; i <= n.verifyTimes; i++ {
fmt.Printf("Start to sleep %d minute #%d time...\n", n.podSleepDuration, i)
By(fmt.Sprintf("Get backups every %d minute, and backups count should increase 1 more step in the same pace\n", s.Period), func() {
for i := 1; i <= s.verifyTimes; i++ {
fmt.Printf("Start to sleep %d minute #%d time...\n", s.podSleepDuration, i)
mi, _ := time.ParseDuration("60s")
time.Sleep(n.podSleepDuration + mi)
time.Sleep(s.podSleepDuration + mi)
bMap := make(map[string]string)
backupsInfo, err := GetScheduledBackupsCreationTime(n.Ctx, n.VeleroCfg.VeleroCLI, "default", n.ScheduleName)
backupsInfo, err := GetScheduledBackupsCreationTime(s.Ctx, s.VeleroCfg.VeleroCLI, "default", s.ScheduleName)
Expect(err).To(Succeed())
Expect(backupsInfo).To(HaveLen(i))
for index, bi := range backupsInfo {
Expand All @@ -116,19 +116,19 @@ func (n *ScheduleBackupCreation) Backup() error {
_, err := time.Parse("2006-01-02 15:04:05 -0700 MST", bList[1])
Expect(err).To(Succeed())
}
if i == n.verifyTimes-1 {
if i == s.verifyTimes-1 {
backupInfo := backupsInfo[rand.Intn(len(backupsInfo))]
n.randBackupName = strings.Split(backupInfo, ",")[0]
s.randBackupName = strings.Split(backupInfo, ",")[0]
}
}
})
return nil
}

func (n *ScheduleBackupCreation) Clean() error {
if !n.VeleroCfg.Debug {
Expect(VeleroScheduleDelete(n.Ctx, n.VeleroCfg.VeleroCLI, n.VeleroCfg.VeleroNamespace, n.ScheduleName)).To(Succeed())
Expect(n.TestCase.Clean()).To(Succeed())
func (s *ScheduleBackupCreation) Clean() error {
if !s.VeleroCfg.FailFast {
Expect(VeleroScheduleDelete(s.Ctx, s.VeleroCfg.VeleroCLI, s.VeleroCfg.VeleroNamespace, s.ScheduleName)).To(Succeed())
Expect(s.TestCase.Clean()).To(Succeed())
}
return nil
}
2 changes: 1 addition & 1 deletion test/e2e/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (n *ScheduleBackup) Verify() error {
}

func (n *ScheduleBackup) Clean() error {
if !n.VeleroCfg.Debug {
if !n.VeleroCfg.FailFast {
Expect(VeleroScheduleDelete(n.Ctx, n.VeleroCfg.VeleroCLI, n.VeleroCfg.VeleroNamespace, n.ScheduleName)).To(Succeed())
Expect(n.TestCase.Clean()).To(Succeed())
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (t *TestCase) Start() error {

func (t *TestCase) Clean() error {
veleroCfg := t.GetTestCase().VeleroCfg
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
By(fmt.Sprintf("Clean namespace with prefix %s after test", t.CaseBaseName), func() {
if err := CleanupNamespaces(t.Ctx, t.Client, t.CaseBaseName); err != nil {
fmt.Println("Fail to cleanup namespaces: ", err)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func BackupUpgradeRestoreTest(useVolumeSnapshots bool, veleroCLI2Version VeleroC
}
})
AfterEach(func() {
if !veleroCfg.Debug {
if !veleroCfg.FailFast {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
Expand Down
Loading

0 comments on commit f8a1045

Please sign in to comment.