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
Bump v1.13 and 1.14 plugin versions for E2E test.

Signed-off-by: Xun Jiang <[email protected]>
  • Loading branch information
blackpiglet committed Sep 18, 2024
1 parent 3f9c2dc commit 7a3886b
Show file tree
Hide file tree
Showing 27 changed files with 380 additions and 254 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.

4 changes: 3 additions & 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 !CurrentSpecReport().Failed() || !veleroCfg.FailFast {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
if backupRestoreTestConfig.isRetainPVTest {
Expand All @@ -111,6 +111,8 @@ func BackupRestoreTest(backupRestoreTestConfig BackupRestoreTestConfig) {
err = VeleroUninstall(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace)
Expect(err).To(Succeed())
}
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}
})

Expand Down
9 changes: 7 additions & 2 deletions test/e2e/backups/deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ func backup_deletion_test(useVolumeSnapshots bool) {
})

AfterEach(func() {
if !veleroCfg.Debug {
if !CurrentSpecReport().Failed() || !veleroCfg.FailFast {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}
})

Expand Down Expand Up @@ -104,13 +106,16 @@ 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 !CurrentSpecReport().Failed() || !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))
}
}()
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}

if err := KibishiiPrepareBeforeBackup(oneHourTimeout, client, providerName, ns,
registryCredentialFile, veleroFeatures, kibishiiDirectory, useVolumeSnapshots, DefaultKibishiiData); err != nil {
return errors.Wrapf(err, "Failed to install and prepare data for kibishii %s", ns)
Expand Down
15 changes: 12 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 !CurrentSpecReport().Failed() || !veleroCfg.FailFast {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
Expand All @@ -72,6 +72,8 @@ func BackupsSyncTest() {
defer ctxCancel()
Expect(VeleroUninstall(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace)).To(Succeed())
}
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}
})

Expand All @@ -82,10 +84,13 @@ 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 !CurrentSpecReport().Failed() || !veleroCfg.FailFast {
defer func() {
Expect(DeleteNamespace(ctx, *veleroCfg.ClientToInstallVelero, test.testNS, false)).To(Succeed(), fmt.Sprintf("Failed to delete the namespace %s", test.testNS))
}()
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}

var BackupCfg BackupConfig
Expand Down Expand Up @@ -125,12 +130,16 @@ func BackupsSyncTest() {
Expect(CreateNamespace(ctx, *veleroCfg.ClientToInstallVelero, test.testNS)).To(Succeed(),
fmt.Sprintf("Failed to create %s namespace", test.testNS))
})
if !veleroCfg.Debug {

if !CurrentSpecReport().Failed() || !veleroCfg.FailFast {
defer func() {
Expect(DeleteNamespace(ctx, *veleroCfg.ClientToInstallVelero, test.testNS, false)).To(Succeed(),
fmt.Sprintf("Failed to delete the namespace %s", test.testNS))
}()
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}

var BackupCfg BackupConfig
BackupCfg.BackupName = test.backupName
BackupCfg.Namespace = test.testNS
Expand Down
4 changes: 3 additions & 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 !CurrentSpecReport().Failed() || !veleroCfg.FailFast {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
Expand All @@ -84,6 +84,8 @@ func TTLTest() {
Expect(VeleroUninstall(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace)).To(Succeed())
}
Expect(DeleteNamespace(ctx, client, test.testNS, false)).To(Succeed(), fmt.Sprintf("Failed to delete the namespace %s", test.testNS))
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}
})

Expand Down
13 changes: 8 additions & 5 deletions 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,12 @@ func APIExtensionsVersionsTest() {
})
})
AfterEach(func() {
if !veleroCfg.Debug {
By(fmt.Sprintf("Switch to default kubeconfig context %s", veleroCfg.DefaultClusterContext), func() {
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.DefaultClusterContext)).To(Succeed())
veleroCfg.ClientToInstallVelero = veleroCfg.DefaultClient
})

if !CurrentSpecReport().Failed() || !veleroCfg.FailFast {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
Expand All @@ -86,10 +91,8 @@ func APIExtensionsVersionsTest() {
Expect(DeleteCRDByName(context.Background(), crdName)).To(Succeed())
})
}
By(fmt.Sprintf("Switch to default kubeconfig context %s", veleroCfg.DefaultClusterContext), func() {
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.DefaultClusterContext)).To(Succeed())
veleroCfg.ClientToInstallVelero = veleroCfg.DefaultClient
})
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}
})
Context("When EnableAPIGroupVersions flag is set", func() {
Expand Down
4 changes: 3 additions & 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 !CurrentSpecReport().Failed() || !veleroCfg.FailFast {
for i := 0; i < testCaseNum; i++ {
curResource := fmt.Sprintf("rockband%ds", i)
curGroup := fmt.Sprintf("%s.%d", group, i)
Expand All @@ -101,6 +101,8 @@ func APIGroupVersionsTest() {
Expect(VeleroUninstall(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace)).NotTo(HaveOccurred())
})
}
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}
})

Expand Down
5 changes: 4 additions & 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 !CurrentSpecReport().Failed() || !n.VeleroCfg.FailFast {
if err := DeleteStorageClass(context.Background(), n.Client, KibishiiStorageClassName); err != nil {
return err
}
Expand All @@ -127,6 +127,9 @@ func (n *NamespaceMapping) Clean() error {
}

return n.GetTestCase().Clean()
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}

return nil
}
5 changes: 4 additions & 1 deletion test/e2e/basic/pvc-selected-node-changing.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,14 @@ func (p *PVCSelectedNodeChanging) Verify() error {
}

func (p *PVCSelectedNodeChanging) Clean() error {
if !p.VeleroCfg.Debug {
if !CurrentSpecReport().Failed() || !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)
})
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}

return nil
}
6 changes: 5 additions & 1 deletion test/e2e/basic/resources-check/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"fmt"
"strings"

. "github.com/onsi/ginkgo/v2"
"github.com/pkg/errors"

. "github.com/vmware-tanzu/velero/test/e2e/test"
Expand Down Expand Up @@ -176,8 +177,11 @@ func (r *RBACCase) Destroy() error {
}

func (r *RBACCase) Clean() error {
if !r.VeleroCfg.Debug {
if !CurrentSpecReport().Failed() || !r.VeleroCfg.FailFast {
return r.Destroy()
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}

return nil
}
5 changes: 4 additions & 1 deletion test/e2e/basic/storage-class-changing.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ func (s *StorageClasssChanging) Verify() error {
}

func (s *StorageClasssChanging) Clean() error {
if !s.VeleroCfg.Debug {
if !CurrentSpecReport().Failed() || !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))
})
DeleteConfigmap(s.Client.ClientGo, s.VeleroCfg.VeleroNamespace, s.configmaptName)
DeleteStorageClass(s.Ctx, s.Client, s.desStorageClass)
s.TestCase.Clean()
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}

return nil
}
4 changes: 3 additions & 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 !CurrentSpecReport().Failed() || !veleroCfg.FailFast {
By("Clean backups after test", func() {
veleroCfg.ClientToInstallVelero = veleroCfg.DefaultClient
DeleteAllBackups(context.Background(), &veleroCfg)
Expand All @@ -84,6 +84,8 @@ func BslDeletionTest(useVolumeSnapshots bool) {
true)).To(Succeed(), fmt.Sprintf("failed to delete the namespace %q",
bslDeletionTestNs))
})
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}
})

Expand Down
10 changes: 7 additions & 3 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 @@ -264,6 +264,8 @@ func GetKubeconfigContext() error {
return nil
}

var testSuitePassed bool

func TestE2e(t *testing.T) {
// Skip running E2E tests when running only "short" tests because:
// 1. E2E tests are long running tests involving installation of Velero and performing backup and restore operations.
Expand Down Expand Up @@ -291,7 +293,7 @@ func TestE2e(t *testing.T) {
}

RegisterFailHandler(Fail)
RunSpecs(t, "E2e Suite")
testSuitePassed = RunSpecs(t, "E2e Suite")
}

var _ = BeforeSuite(func() {
Expand All @@ -302,7 +304,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 on failure.
if InstallVelero && (testSuitePassed || !VeleroCfg.FailFast) {
By("release test resources after testing")
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*5)
defer ctxCancel()
Expand Down
14 changes: 8 additions & 6 deletions test/e2e/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ func MigrationTest(useVolumeSnapshots bool, veleroCLI2Version VeleroCLI2Version)
}
})
AfterEach(func() {
if !veleroCfg.Debug {
By(fmt.Sprintf("Switch to default kubeconfig context %s", veleroCfg.DefaultClusterContext), func() {
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.DefaultClusterContext)).To(Succeed())
veleroCfg.ClientToInstallVelero = veleroCfg.DefaultClient
veleroCfg.ClusterToInstallVelero = veleroCfg.DefaultClusterName
})
if !CurrentSpecReport().Failed() || !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 All @@ -105,11 +110,8 @@ func MigrationTest(useVolumeSnapshots bool, veleroCLI2Version VeleroCLI2Version)
DeleteNamespace(context.Background(), *veleroCfg.StandbyClient, migrationNamespace, true)
})
}
By(fmt.Sprintf("Switch to default kubeconfig context %s", veleroCfg.DefaultClusterContext), func() {
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.DefaultClusterContext)).To(Succeed())
veleroCfg.ClientToInstallVelero = veleroCfg.DefaultClient
veleroCfg.ClusterToInstallVelero = veleroCfg.DefaultClusterName
})
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}
})
When("kibishii is the sample workload", func() {
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
4 changes: 3 additions & 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 !CurrentSpecReport().Failed() || !r.VeleroCfg.FailFast {
if err := r.deleteTestStorageClassList([]string{StorageClassName, StorageClassName2}); err != nil {
return err
}
Expand All @@ -188,6 +188,8 @@ func (r *ResourcePoliciesCase) Clean() error {
}

return r.GetTestCase().Clean() // only clean up resources in test namespace
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}
return nil
}
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/schedule/ordered_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,13 @@ func (o *OrderedResources) Verify() error {
}

func (o *OrderedResources) Clean() error {
if !o.VeleroCfg.Debug {
if !CurrentSpecReport().Failed() || !o.VeleroCfg.FailFast {
Expect(VeleroScheduleDelete(o.Ctx, o.VeleroCfg.VeleroCLI, o.VeleroCfg.VeleroNamespace, o.ScheduleName)).To(Succeed())
Expect(o.TestCase.Clean()).To(Succeed())
} else {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
}

return nil
}

Expand Down
Loading

0 comments on commit 7a3886b

Please sign in to comment.