Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip uninstall and resource cleanup when fail-fast is enabled. #8216

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,9 @@ func BackupRestoreTest(backupRestoreTestConfig BackupRestoreTestConfig) {
})

AfterEach(func() {
if !veleroCfg.Debug {
if CurrentSpecReport().Failed() && veleroCfg.FailFast {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
if backupRestoreTestConfig.isRetainPVTest {
Expand Down
10 changes: 8 additions & 2 deletions test/e2e/backups/deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func backup_deletion_test(useVolumeSnapshots bool) {
})

AfterEach(func() {
if !veleroCfg.Debug {
if CurrentSpecReport().Failed() && veleroCfg.FailFast {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
Expand Down Expand Up @@ -104,13 +106,17 @@ 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 {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
defer func() {
if err := DeleteNamespace(context.Background(), client, ns, true); err != nil {
fmt.Println(errors.Wrapf(err, "failed to delete the namespace %q", ns))
}
}()
}

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,9 @@ func BackupsSyncTest() {
})

AfterEach(func() {
if !veleroCfg.Debug {
if CurrentSpecReport().Failed() && veleroCfg.FailFast {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
Expand All @@ -82,7 +84,10 @@ 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 {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
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,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
5 changes: 4 additions & 1 deletion test/e2e/backups/ttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ func TTLTest() {

AfterEach(func() {
veleroCfg.GCFrequency = ""
if !veleroCfg.Debug {

if CurrentSpecReport().Failed() && veleroCfg.FailFast {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
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,14 @@ 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 {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
By("Clean backups after test", func() {
DeleteAllBackups(context.Background(), &veleroCfg)
})
Expand All @@ -86,10 +93,6 @@ 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
})
}
})
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,9 @@ func APIGroupVersionsTest() {
})

AfterEach(func() {
if !veleroCfg.Debug {
if CurrentSpecReport().Failed() && veleroCfg.FailFast {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
for i := 0; i < testCaseNum; i++ {
curResource := fmt.Sprintf("rockband%ds", i)
curGroup := fmt.Sprintf("%s.%d", group, i)
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,9 @@ func (n *NamespaceMapping) Verify() error {
}

func (n *NamespaceMapping) Clean() error {
if !n.VeleroCfg.Debug {
if CurrentSpecReport().Failed() && n.VeleroCfg.FailFast {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
if err := DeleteStorageClass(context.Background(), n.Client, KibishiiStorageClassName); err != nil {
return err
}
Expand All @@ -128,5 +130,6 @@ func (n *NamespaceMapping) Clean() error {

return n.GetTestCase().Clean()
}

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 {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
p.TestCase.Clean()
By(fmt.Sprintf("Clean namespace with prefix %s after test", p.mappedNS), func() {
CleanupNamespaces(p.Ctx, p.Client, p.mappedNS)
})
}

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 {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
return r.Destroy()
}

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,7 +142,9 @@ func (s *StorageClasssChanging) Verify() error {
}

func (s *StorageClasssChanging) Clean() error {
if !s.VeleroCfg.Debug {
if CurrentSpecReport().Failed() && s.VeleroCfg.FailFast {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
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 All @@ -151,5 +153,6 @@ func (s *StorageClasssChanging) Clean() error {
DeleteStorageClass(s.Ctx, s.Client, s.desStorageClass)
s.TestCase.Clean()
}

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,9 @@ func BslDeletionTest(useVolumeSnapshots bool) {
})

AfterEach(func() {
if !veleroCfg.Debug {
if CurrentSpecReport().Failed() && veleroCfg.FailFast {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
By("Clean backups after test", func() {
veleroCfg.ClientToInstallVelero = veleroCfg.DefaultClient
DeleteAllBackups(context.Background(), &veleroCfg)
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
15 changes: 9 additions & 6 deletions test/e2e/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@ 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 {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
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 +113,6 @@ 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
})
}
})
When("kibishii is the sample workload", func() {
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/resourcemodifiers/resource_modifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ 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 CurrentSpecReport().Failed() && r.VeleroCfg.FailFast {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
if err := DeleteConfigmap(r.Client.ClientGo, r.VeleroCfg.VeleroNamespace, r.cmName); err != nil {
return err
}

return r.GetTestCase().Clean() // only clean up resources in test namespace
}

return nil
}

Expand Down
5 changes: 4 additions & 1 deletion test/e2e/resourcepolicies/resource_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ 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 {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
if err := r.deleteTestStorageClassList([]string{StorageClassName, StorageClassName2}); err != nil {
return err
}
Expand All @@ -189,6 +191,7 @@ func (r *ResourcePoliciesCase) Clean() error {

return r.GetTestCase().Clean() // only clean up resources in test namespace
}

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 {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
Expect(VeleroScheduleDelete(o.Ctx, o.VeleroCfg.VeleroCLI, o.VeleroCfg.VeleroNamespace, o.ScheduleName)).To(Succeed())
Expect(o.TestCase.Clean()).To(Succeed())
}

return nil
}

Expand Down
Loading
Loading