From 50fc332db46674498468159fd71cedb0b49cdc56 Mon Sep 17 00:00:00 2001 From: nitishSr Date: Wed, 12 Jan 2022 18:19:21 +0530 Subject: [PATCH 1/4] New structural changes to test repo --- Makefile | 2 +- go.mod | 7 +++---- go.sum | 8 ++++---- tests/e2e/{ => lib}/apps.go | 0 tests/e2e/{ => lib}/backup.go | 0 tests/e2e/{ => lib}/plugins_helpers.go | 0 tests/e2e/{ => lib}/registry_helpers.go | 0 tests/e2e/{ => lib}/restic_helpers.go | 0 tests/e2e/{ => lib}/restore.go | 0 tests/e2e/{ => lib}/subscription_helpers.go | 0 tests/e2e/{ => lib}/velero_helpers.go | 0 tests/e2e/{ => suites}/backup_restore_suite_test.go | 0 tests/e2e/{ => suites}/e2e_suite_test.go | 0 tests/e2e/{ => suites}/subscription_suite_test.go | 0 tests/e2e/{ => suites}/velero_deployment_suite_test.go | 0 tests/e2e/{ => utils}/common.go | 0 16 files changed, 8 insertions(+), 9 deletions(-) rename tests/e2e/{ => lib}/apps.go (100%) rename tests/e2e/{ => lib}/backup.go (100%) rename tests/e2e/{ => lib}/plugins_helpers.go (100%) rename tests/e2e/{ => lib}/registry_helpers.go (100%) rename tests/e2e/{ => lib}/restic_helpers.go (100%) rename tests/e2e/{ => lib}/restore.go (100%) rename tests/e2e/{ => lib}/subscription_helpers.go (100%) rename tests/e2e/{ => lib}/velero_helpers.go (100%) rename tests/e2e/{ => suites}/backup_restore_suite_test.go (100%) rename tests/e2e/{ => suites}/e2e_suite_test.go (100%) rename tests/e2e/{ => suites}/subscription_suite_test.go (100%) rename tests/e2e/{ => suites}/velero_deployment_suite_test.go (100%) rename tests/e2e/{ => utils}/common.go (100%) diff --git a/Makefile b/Makefile index 9e00489584..9abcc0b56e 100644 --- a/Makefile +++ b/Makefile @@ -290,7 +290,7 @@ catalog-push: ## Push a catalog image. $(MAKE) docker-push IMG=$(CATALOG_IMG) test-e2e: - ginkgo -mod=mod tests/e2e/ -- -cloud=$(OADP_AWS_CRED_FILE) \ + ginkgo -mod=mod tests/e2e/suites -- -cloud=$(OADP_AWS_CRED_FILE) \ -s3_bucket=$(OADP_S3_BUCKET) -velero_namespace=$(OADP_TEST_NAMESPACE) \ -creds_secret_ref=$(CREDS_SECRET_REF) \ -velero_instance_name=$(VELERO_INSTANCE_NAME) \ diff --git a/go.mod b/go.mod index 6936061db7..77a843d2fd 100644 --- a/go.mod +++ b/go.mod @@ -6,11 +6,12 @@ require ( github.com/aws/aws-sdk-go v1.28.2 github.com/go-logr/logr v0.4.0 github.com/google/uuid v1.1.2 - github.com/onsi/ginkgo v1.16.4 - github.com/onsi/gomega v1.16.0 + github.com/onsi/ginkgo v1.16.5 + github.com/onsi/gomega v1.17.0 github.com/openshift/api v0.0.0-20210805075156-d8fab4513288 github.com/operator-framework/api v0.10.7 github.com/operator-framework/operator-lib v0.9.0 + github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.51.2 github.com/vmware-tanzu/velero v1.7.0 // TODO: Update this to a pinned version k8s.io/api v0.22.2 k8s.io/apiextensions-apiserver v0.22.2 @@ -18,6 +19,4 @@ require ( k8s.io/client-go v0.22.2 k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a sigs.k8s.io/controller-runtime v0.10.3 - github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.51.2 - github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.51.2 ) diff --git a/go.sum b/go.sum index e242519544..b9550e2a44 100644 --- a/go.sum +++ b/go.sum @@ -569,8 +569,9 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108 github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= -github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= @@ -580,8 +581,8 @@ github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= github.com/onsi/gomega v1.14.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0= github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0= -github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c= -github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/openshift/api v0.0.0-20210805075156-d8fab4513288 h1:Yw96Z8gygCXxjeMTm55gGsTNxwnJkr6L2Baf3NsUQFU= @@ -1289,7 +1290,6 @@ k8s.io/apiserver v0.22.1/go.mod h1:2mcM6dzSt+XndzVQJX21Gx0/Klo7Aen7i0Ai6tIa400= k8s.io/apiserver v0.22.2/go.mod h1:vrpMmbyjWrgdyOvZTSpsusQq5iigKNWv9o9KlDAbBHI= k8s.io/cli-runtime v0.19.2/go.mod h1:CMynmJM4Yf02TlkbhKxoSzi4Zf518PukJ5xep/NaNeY= k8s.io/cli-runtime v0.20.9/go.mod h1:MjEpWNIcmJL+gANS1+SVfvWpRSQRxOvTcx+vzvDTtTY= -k8s.io/cli-runtime v0.19.12/go.mod h1:KopjJ53HaHZjG+WhJmH8WxZzxnXVNkxP7GO1QiQJ2uI= k8s.io/client-go v0.18.3/go.mod h1:4a/dpQEvzAhT1BbuWW09qvIaGw6Gbu1gZYiQZIi1DMw= k8s.io/client-go v0.19.0/go.mod h1:H9E/VT95blcFQnlyShFgnFT9ZnJOAceiUHM3MlRC+mU= k8s.io/client-go v0.19.2/go.mod h1:S5wPhCqyDNAlzM9CnEdgTGV4OqhsW3jGO1UM1epwfJA= diff --git a/tests/e2e/apps.go b/tests/e2e/lib/apps.go similarity index 100% rename from tests/e2e/apps.go rename to tests/e2e/lib/apps.go diff --git a/tests/e2e/backup.go b/tests/e2e/lib/backup.go similarity index 100% rename from tests/e2e/backup.go rename to tests/e2e/lib/backup.go diff --git a/tests/e2e/plugins_helpers.go b/tests/e2e/lib/plugins_helpers.go similarity index 100% rename from tests/e2e/plugins_helpers.go rename to tests/e2e/lib/plugins_helpers.go diff --git a/tests/e2e/registry_helpers.go b/tests/e2e/lib/registry_helpers.go similarity index 100% rename from tests/e2e/registry_helpers.go rename to tests/e2e/lib/registry_helpers.go diff --git a/tests/e2e/restic_helpers.go b/tests/e2e/lib/restic_helpers.go similarity index 100% rename from tests/e2e/restic_helpers.go rename to tests/e2e/lib/restic_helpers.go diff --git a/tests/e2e/restore.go b/tests/e2e/lib/restore.go similarity index 100% rename from tests/e2e/restore.go rename to tests/e2e/lib/restore.go diff --git a/tests/e2e/subscription_helpers.go b/tests/e2e/lib/subscription_helpers.go similarity index 100% rename from tests/e2e/subscription_helpers.go rename to tests/e2e/lib/subscription_helpers.go diff --git a/tests/e2e/velero_helpers.go b/tests/e2e/lib/velero_helpers.go similarity index 100% rename from tests/e2e/velero_helpers.go rename to tests/e2e/lib/velero_helpers.go diff --git a/tests/e2e/backup_restore_suite_test.go b/tests/e2e/suites/backup_restore_suite_test.go similarity index 100% rename from tests/e2e/backup_restore_suite_test.go rename to tests/e2e/suites/backup_restore_suite_test.go diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/suites/e2e_suite_test.go similarity index 100% rename from tests/e2e/e2e_suite_test.go rename to tests/e2e/suites/e2e_suite_test.go diff --git a/tests/e2e/subscription_suite_test.go b/tests/e2e/suites/subscription_suite_test.go similarity index 100% rename from tests/e2e/subscription_suite_test.go rename to tests/e2e/suites/subscription_suite_test.go diff --git a/tests/e2e/velero_deployment_suite_test.go b/tests/e2e/suites/velero_deployment_suite_test.go similarity index 100% rename from tests/e2e/velero_deployment_suite_test.go rename to tests/e2e/suites/velero_deployment_suite_test.go diff --git a/tests/e2e/common.go b/tests/e2e/utils/common.go similarity index 100% rename from tests/e2e/common.go rename to tests/e2e/utils/common.go From 17c8dc23e63589bc13b7189a8997a113a48240e0 Mon Sep 17 00:00:00 2001 From: nitishSr Date: Wed, 2 Feb 2022 11:21:57 +0530 Subject: [PATCH 2/4] Refactored changes to accomdate package structuring --- .gitignore | 1 + go.mod | 1 + go.sum | 1 + .../{suites => }/backup_restore_suite_test.go | 79 +++++----- .../{suites => }/dpa_deployment_suite_test.go | 103 +++++++------ tests/e2e/e2e_suite_test.go | 26 ++-- tests/e2e/lib/apps.go | 77 +++++----- tests/e2e/lib/backup.go | 10 +- tests/e2e/lib/dpa_helpers.go | 145 +++++++++++++----- .../{utils/common.go => lib/kube_helpers.go} | 79 +++++++--- tests/e2e/lib/plugins_helpers.go | 10 +- tests/e2e/lib/registry_helpers.go | 4 +- tests/e2e/lib/restic_helpers.go | 18 +-- tests/e2e/lib/restore.go | 10 +- tests/e2e/lib/subscription_helpers.go | 8 +- .../{suites => }/subscription_suite_test.go | 24 +-- tests/e2e/templates/dpa_template.tmpl | 27 ++++ tests/e2e/utils/common_utils.go | 52 +++++++ 18 files changed, 433 insertions(+), 242 deletions(-) rename tests/e2e/{suites => }/backup_restore_suite_test.go (74%) rename tests/e2e/{suites => }/dpa_deployment_suite_test.go (89%) rename tests/e2e/{utils/common.go => lib/kube_helpers.go} (69%) rename tests/e2e/{suites => }/subscription_suite_test.go (87%) create mode 100644 tests/e2e/templates/dpa_template.tmpl create mode 100644 tests/e2e/utils/common_utils.go diff --git a/.gitignore b/.gitignore index 7ae2092bca..b973e853e0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ bin/ tests/e2e/e2e.test cover.out .DS_Store +tests/e2e/templates/*.yaml diff --git a/go.mod b/go.mod index 77a843d2fd..bd2607aa1c 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.16 require ( github.com/aws/aws-sdk-go v1.28.2 + github.com/ghodss/yaml v1.0.0 // indirect github.com/go-logr/logr v0.4.0 github.com/google/uuid v1.1.2 github.com/onsi/ginkgo v1.16.5 diff --git a/go.sum b/go.sum index b9550e2a44..cbd9eac599 100644 --- a/go.sum +++ b/go.sum @@ -223,6 +223,7 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= diff --git a/tests/e2e/suites/backup_restore_suite_test.go b/tests/e2e/backup_restore_suite_test.go similarity index 74% rename from tests/e2e/suites/backup_restore_suite_test.go rename to tests/e2e/backup_restore_suite_test.go index 0f8e9d9e82..ccdb573ac8 100755 --- a/tests/e2e/suites/backup_restore_suite_test.go +++ b/tests/e2e/backup_restore_suite_test.go @@ -1,4 +1,4 @@ -package e2e +package e2e_test import ( "errors" @@ -10,19 +10,22 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" + . "github.com/openshift/oadp-operator/tests/e2e/lib" + utils "github.com/openshift/oadp-operator/tests/e2e/utils" "sigs.k8s.io/controller-runtime/pkg/client" ) type VerificationFunction func(client.Client, string) error var _ = Describe("AWS backup restore tests", func() { + var _ = BeforeEach(func() { testSuiteInstanceName := "ts-" + instanceName dpaCR.Name = testSuiteInstanceName - credData, err := readFile(cloud) + credData, err := utils.ReadFile(cloud) Expect(err).NotTo(HaveOccurred()) - err = createCredentialsSecret(credData, namespace, getSecretRef(credSecretRef)) + err = CreateCredentialsSecret(credData, namespace, GetSecretRef(credSecretRef)) Expect(err).NotTo(HaveOccurred()) }) @@ -39,19 +42,19 @@ var _ = Describe("AWS backup restore tests", func() { BackupRestoreType BackupRestoreType PreBackupVerify VerificationFunction PostRestoreVerify VerificationFunction - MaxK8SVersion *k8sVersion - MinK8SVersion *k8sVersion + MaxK8SVersion *K8sVersion + MinK8SVersion *K8sVersion } parksAppReady := VerificationFunction(func(ocClient client.Client, namespace string) error { - Eventually(isDCReady(ocClient, "parks-app", "restify"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue()) + Eventually(IsDCReady(ocClient, "parks-app", "restify"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue()) return nil }) mssqlReady := VerificationFunction(func(ocClient client.Client, namespace string) error { // This test confirms that SCC restore logic in our plugin is working - Eventually(isDCReady(ocClient, "mssql-persistent", "mssql-deployment"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue()) - Eventually(isDeploymentReady(ocClient, "mssql-persistent", "mssql-app-deployment"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue()) - exists, err := doesSCCExist(ocClient, "mssql-persistent-scc") + Eventually(IsDCReady(ocClient, "mssql-persistent", "mssql-deployment"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue()) + Eventually(IsDeploymentReady(ocClient, "mssql-persistent", "mssql-app-deployment"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue()) + exists, err := DoesSCCExist(ocClient, "mssql-persistent-scc") if err != nil { return err } @@ -71,17 +74,17 @@ var _ = Describe("AWS backup restore tests", func() { Expect(err).NotTo(HaveOccurred()) log.Printf("Waiting for velero pod to be running") - Eventually(areVeleroPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(AreVeleroPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) - if brCase.BackupRestoreType == restic { + if brCase.BackupRestoreType == RESTIC { log.Printf("Waiting for restic pods to be running") - Eventually(areResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(AreResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } - if brCase.BackupRestoreType == csi { + if brCase.BackupRestoreType == CSI { if clusterProfile == "aws" { log.Printf("Creating VolumeSnapshot for CSI backuprestore of %s", brCase.Name) - err = installApplication(dpaCR.Client, "./sample-applications/gp2-csi/volumeSnapshotClass.yaml") + err = InstallApplication(dpaCR.Client, "./sample-applications/gp2-csi/volumeSnapshotClass.yaml") Expect(err).ToNot(HaveOccurred()) } else { Skip("CSI testing is not provided for this cluster provider.") @@ -90,7 +93,7 @@ var _ = Describe("AWS backup restore tests", func() { if dpaCR.CustomResource.Spec.BackupImages == nil || *dpaCR.CustomResource.Spec.BackupImages { log.Printf("Waiting for registry pods to be running") - Eventually(areRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(AreRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } if notVersionTarget, reason := NotServerVersionTarget(brCase.MinK8SVersion, brCase.MaxK8SVersion); notVersionTarget { Skip(reason) @@ -102,10 +105,10 @@ var _ = Describe("AWS backup restore tests", func() { // install app log.Printf("Installing application for case %s", brCase.Name) - err = installApplication(dpaCR.Client, brCase.ApplicationTemplate) + err = InstallApplication(dpaCR.Client, brCase.ApplicationTemplate) Expect(err).ToNot(HaveOccurred()) // wait for pods to be running - Eventually(areApplicationPodsRunning(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*9, time.Second*5).Should(BeTrue()) + Eventually(AreApplicationPodsRunning(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*9, time.Second*5).Should(BeTrue()) // Run optional custom verification log.Printf("Running pre-backup function for case %s", brCase.Name) @@ -114,41 +117,41 @@ var _ = Describe("AWS backup restore tests", func() { // create backup log.Printf("Creating backup %s for case %s", backupName, brCase.Name) - err = createBackupForNamespaces(dpaCR.Client, namespace, backupName, []string{brCase.ApplicationNamespace}) + err = CreateBackupForNamespaces(dpaCR.Client, namespace, backupName, []string{brCase.ApplicationNamespace}) Expect(err).ToNot(HaveOccurred()) // wait for backup to not be running - Eventually(isBackupDone(dpaCR.Client, namespace, backupName), timeoutMultiplier*time.Minute*4, time.Second*10).Should(BeTrue()) - Expect(getVeleroContainerFailureLogs(dpaCR.Namespace)).To(Equal([]string{})) + Eventually(IsBackupDone(dpaCR.Client, namespace, backupName), timeoutMultiplier*time.Minute*4, time.Second*10).Should(BeTrue()) + Expect(GetVeleroContainerFailureLogs(dpaCR.Namespace)).To(Equal([]string{})) // check if backup succeeded - succeeded, err := isBackupCompletedSuccessfully(dpaCR.Client, namespace, backupName) + succeeded, err := IsBackupCompletedSuccessfully(dpaCR.Client, namespace, backupName) Expect(err).ToNot(HaveOccurred()) Expect(succeeded).To(Equal(true)) log.Printf("Backup for case %s succeeded", brCase.Name) // uninstall app log.Printf("Uninstalling app for case %s", brCase.Name) - err = uninstallApplication(dpaCR.Client, brCase.ApplicationTemplate) + err = UninstallApplication(dpaCR.Client, brCase.ApplicationTemplate) Expect(err).ToNot(HaveOccurred()) // Wait for namespace to be deleted - Eventually(isNamespaceDeleted(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*2, time.Second*5).Should(BeTrue()) + Eventually(IsNamespaceDeleted(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*2, time.Second*5).Should(BeTrue()) // run restore log.Printf("Creating restore %s for case %s", restoreName, brCase.Name) - err = createRestoreFromBackup(dpaCR.Client, namespace, backupName, restoreName) + err = CreateRestoreFromBackup(dpaCR.Client, namespace, backupName, restoreName) Expect(err).ToNot(HaveOccurred()) - Eventually(isRestoreDone(dpaCR.Client, namespace, restoreName), timeoutMultiplier*time.Minute*4, time.Second*10).Should(BeTrue()) - Expect(getVeleroContainerFailureLogs(dpaCR.Namespace)).To(Equal([]string{})) + Eventually(IsRestoreDone(dpaCR.Client, namespace, restoreName), timeoutMultiplier*time.Minute*4, time.Second*10).Should(BeTrue()) + Expect(GetVeleroContainerFailureLogs(dpaCR.Namespace)).To(Equal([]string{})) // Check if restore succeeded - succeeded, err = isRestoreCompletedSuccessfully(dpaCR.Client, namespace, restoreName) + succeeded, err = IsRestoreCompletedSuccessfully(dpaCR.Client, namespace, restoreName) Expect(err).ToNot(HaveOccurred()) Expect(succeeded).To(Equal(true)) // verify app is running - Eventually(areApplicationPodsRunning(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*9, time.Second*5).Should(BeTrue()) + Eventually(AreApplicationPodsRunning(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*9, time.Second*5).Should(BeTrue()) // Run optional custom verification log.Printf("Running post-restore function for case %s", brCase.Name) @@ -157,15 +160,15 @@ var _ = Describe("AWS backup restore tests", func() { // Test is successful, clean up everything log.Printf("Uninstalling application for case %s", brCase.Name) - err = uninstallApplication(dpaCR.Client, brCase.ApplicationTemplate) + err = UninstallApplication(dpaCR.Client, brCase.ApplicationTemplate) Expect(err).ToNot(HaveOccurred()) // Wait for namespace to be deleted - Eventually(isNamespaceDeleted(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*2, time.Second*5).Should(BeTrue()) + Eventually(IsNamespaceDeleted(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*2, time.Second*5).Should(BeTrue()) - if brCase.BackupRestoreType == csi { + if brCase.BackupRestoreType == CSI { log.Printf("Deleting VolumeSnapshot for CSI backuprestore of %s", brCase.Name) - err = uninstallApplication(dpaCR.Client, "./sample-applications/gp2-csi/volumeSnapshotClass.yaml") + err = UninstallApplication(dpaCR.Client, "./sample-applications/gp2-csi/volumeSnapshotClass.yaml") Expect(err).ToNot(HaveOccurred()) } @@ -174,7 +177,7 @@ var _ = Describe("AWS backup restore tests", func() { ApplicationTemplate: "./sample-applications/mssql-persistent/mssql-persistent-csi-template.yaml", ApplicationNamespace: "mssql-persistent", Name: "mssql-e2e", - BackupRestoreType: csi, + BackupRestoreType: CSI, PreBackupVerify: mssqlReady, PostRestoreVerify: mssqlReady, }, nil), @@ -182,16 +185,16 @@ var _ = Describe("AWS backup restore tests", func() { ApplicationTemplate: "./sample-applications/parks-app/manifest.yaml", ApplicationNamespace: "parks-app", Name: "parks-e2e", - BackupRestoreType: restic, + BackupRestoreType: RESTIC, PreBackupVerify: parksAppReady, PostRestoreVerify: parksAppReady, - MaxK8SVersion: &k8sVersionOcp47, + MaxK8SVersion: &K8sVersionOcp47, }, nil), Entry("MSSQL application", BackupRestoreCase{ ApplicationTemplate: "./sample-applications/mssql-persistent/mssql-persistent-template.yaml", ApplicationNamespace: "mssql-persistent", Name: "mssql-e2e", - BackupRestoreType: restic, + BackupRestoreType: RESTIC, PreBackupVerify: mssqlReady, PostRestoreVerify: mssqlReady, }, nil), @@ -199,10 +202,10 @@ var _ = Describe("AWS backup restore tests", func() { ApplicationTemplate: "./sample-applications/parks-app/manifest4.8.yaml", ApplicationNamespace: "parks-app", Name: "parks-e2e", - BackupRestoreType: restic, + BackupRestoreType: RESTIC, PreBackupVerify: parksAppReady, PostRestoreVerify: parksAppReady, - MinK8SVersion: &k8sVersionOcp48, + MinK8SVersion: &K8sVersionOcp48, }, nil), ) }) diff --git a/tests/e2e/suites/dpa_deployment_suite_test.go b/tests/e2e/dpa_deployment_suite_test.go similarity index 89% rename from tests/e2e/suites/dpa_deployment_suite_test.go rename to tests/e2e/dpa_deployment_suite_test.go index 491ff02088..ed27ac0b66 100644 --- a/tests/e2e/suites/dpa_deployment_suite_test.go +++ b/tests/e2e/dpa_deployment_suite_test.go @@ -1,4 +1,4 @@ -package e2e +package e2e_test import ( "fmt" @@ -12,15 +12,16 @@ import ( . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1" + . "github.com/openshift/oadp-operator/tests/e2e/lib" velero "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" ) var _ = Describe("Configuration testing for DPA Custom Resource", func() { - provider := dpa.Spec.BackupLocations[0].Velero.Provider - bucket := dpa.Spec.BackupLocations[0].Velero.ObjectStorage.Bucket - bslConfig := dpa.Spec.BackupLocations[0].Velero.Config + provider := Dpa.Spec.BackupLocations[0].Velero.Provider + bucket := Dpa.Spec.BackupLocations[0].Velero.ObjectStorage.Bucket + bslConfig := Dpa.Spec.BackupLocations[0].Velero.Config type InstallCase struct { Name string @@ -49,54 +50,54 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { return } log.Printf("Waiting for velero pod to be running") - Eventually(areVeleroPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(AreVeleroPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) dpa, err := dpaCR.Get() Expect(err).NotTo(HaveOccurred()) if len(dpa.Spec.BackupLocations) > 0 { log.Printf("Checking for bsl spec") for _, bsl := range dpa.Spec.BackupLocations { // Check if bsl matches the spec - Eventually(doesBSLExist(namespace, *bsl.Velero, installCase.DpaSpec), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(DoesBSLExist(namespace, *bsl.Velero, installCase.DpaSpec), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } } if len(dpa.Spec.SnapshotLocations) > 0 { log.Printf("Checking for vsl spec") for _, vsl := range dpa.Spec.SnapshotLocations { - Eventually(doesVSLExist(namespace, *vsl.Velero, installCase.DpaSpec), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(DoesVSLExist(namespace, *vsl.Velero, installCase.DpaSpec), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } } // Check for velero tolerations if len(dpa.Spec.Configuration.Velero.PodConfig.Tolerations) > 0 { log.Printf("Checking for velero tolerations") - Eventually(verifyVeleroTolerations(namespace, dpa.Spec.Configuration.Velero.PodConfig.Tolerations), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(VerifyVeleroTolerations(namespace, dpa.Spec.Configuration.Velero.PodConfig.Tolerations), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } // check for velero resource allocations if dpa.Spec.Configuration.Velero.PodConfig.ResourceAllocations.Requests != nil { log.Printf("Checking for velero resource allocation requests") - Eventually(verifyVeleroResourceRequests(namespace, dpa.Spec.Configuration.Velero.PodConfig.ResourceAllocations.Requests), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(VerifyVeleroResourceRequests(namespace, dpa.Spec.Configuration.Velero.PodConfig.ResourceAllocations.Requests), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } if dpa.Spec.Configuration.Velero.PodConfig.ResourceAllocations.Limits != nil { log.Printf("Checking for velero resource allocation limits") - Eventually(verifyVeleroResourceLimits(namespace, dpa.Spec.Configuration.Velero.PodConfig.ResourceAllocations.Limits), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(VerifyVeleroResourceLimits(namespace, dpa.Spec.Configuration.Velero.PodConfig.ResourceAllocations.Limits), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } //restic installation if dpa.Spec.Configuration.Restic != nil && *dpa.Spec.Configuration.Restic.Enable { log.Printf("Waiting for restic pods to be running") - Eventually(areResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(AreResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } else { log.Printf("Waiting for restic daemonset to be deleted") - Eventually(isResticDaemonsetDeleted(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(IsResticDaemonsetDeleted(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } // check defaultplugins log.Printf("Waiting for velero deployment to have expected plugins") if len(dpa.Spec.Configuration.Velero.DefaultPlugins) > 0 { log.Printf("Checking for default plugins") for _, plugin := range dpa.Spec.Configuration.Velero.DefaultPlugins { - Eventually(doesPluginExist(namespace, plugin), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(DoesPluginExist(namespace, plugin), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } } @@ -105,29 +106,29 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { if len(dpa.Spec.Configuration.Velero.CustomPlugins) > 0 { log.Printf("Checking for custom plugins") for _, plugin := range dpa.Spec.Configuration.Velero.CustomPlugins { - Eventually(doesCustomPluginExist(namespace, plugin), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(DoesCustomPluginExist(namespace, plugin), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } } if dpa.Spec.Configuration.Restic != nil && dpa.Spec.Configuration.Restic.PodConfig != nil { for key, value := range dpa.Spec.Configuration.Restic.PodConfig.NodeSelector { log.Printf("Waiting for restic daemonset to get node selector") - Eventually(resticDaemonSetHasNodeSelector(namespace, key, value), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(ResticDaemonSetHasNodeSelector(namespace, key, value), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } } if dpa.Spec.BackupImages == nil || *installCase.DpaSpec.BackupImages { log.Printf("Waiting for registry pods to be running") - Eventually(areRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(AreRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } }, Entry("Default velero CR", InstallCase{ Name: "default-cr", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - DefaultPlugins: dpa.Spec.Configuration.Velero.DefaultPlugins, + DefaultPlugins: Dpa.Spec.Configuration.Velero.DefaultPlugins, PodConfig: &oadpv1alpha1.PodConfig{}, }, Restic: &oadpv1alpha1.ResticConfig{ @@ -144,7 +145,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -155,14 +156,14 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil), Entry("Adding Velero custom plugin", InstallCase{ Name: "default-cr-velero-custom-plugin", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, DefaultPlugins: append([]oadpv1alpha1.DefaultPlugin{ oadpv1alpha1.DefaultPluginCSI, - }, dpa.Spec.Configuration.Velero.DefaultPlugins...), + }, Dpa.Spec.Configuration.Velero.DefaultPlugins...), CustomPlugins: []oadpv1alpha1.CustomPlugin{ { Name: "encryption-plugin", @@ -185,7 +186,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -196,7 +197,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil), Entry("Adding Velero resource allocations", InstallCase{ Name: "default-cr-velero-resource-alloc", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ @@ -214,7 +215,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, DefaultPlugins: append([]oadpv1alpha1.DefaultPlugin{ oadpv1alpha1.DefaultPluginCSI, - }, dpa.Spec.Configuration.Velero.DefaultPlugins...), + }, Dpa.Spec.Configuration.Velero.DefaultPlugins...), }, Restic: &oadpv1alpha1.ResticConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, @@ -231,7 +232,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -242,7 +243,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil), Entry("Adding AWS plugin", InstallCase{ Name: "default-cr-aws-plugin", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ @@ -266,7 +267,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -277,19 +278,19 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil), Entry("DPA CR with bsl and vsl", InstallCase{ Name: "default-cr-bsl-vsl", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, - DefaultPlugins: dpa.Spec.Configuration.Velero.DefaultPlugins, + DefaultPlugins: Dpa.Spec.Configuration.Velero.DefaultPlugins, }, Restic: &oadpv1alpha1.ResticConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, Enable: pointer.Bool(true), }, }, - SnapshotLocations: dpa.Spec.SnapshotLocations, + SnapshotLocations: Dpa.Spec.SnapshotLocations, BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velero.BackupStorageLocationSpec{ @@ -299,7 +300,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -404,12 +405,12 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil),*/ Entry("Default velero CR with restic disabled", InstallCase{ Name: "default-cr-no-restic", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, - DefaultPlugins: dpa.Spec.Configuration.Velero.DefaultPlugins, + DefaultPlugins: Dpa.Spec.Configuration.Velero.DefaultPlugins, }, Restic: &oadpv1alpha1.ResticConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, @@ -425,7 +426,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -436,14 +437,14 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil), Entry("Adding CSI plugin", InstallCase{ Name: "default-cr-csi", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, DefaultPlugins: append([]oadpv1alpha1.DefaultPlugin{ oadpv1alpha1.DefaultPluginCSI, - }, dpa.Spec.Configuration.Velero.DefaultPlugins...), + }, Dpa.Spec.Configuration.Velero.DefaultPlugins...), }, Restic: &oadpv1alpha1.ResticConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, @@ -459,7 +460,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -470,7 +471,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil), Entry("Set restic node selector", InstallCase{ Name: "default-cr-node-selector", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ BackupLocations: []oadpv1alpha1.BackupLocation{ { @@ -481,7 +482,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -490,7 +491,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, - DefaultPlugins: dpa.Spec.Configuration.Velero.DefaultPlugins, + DefaultPlugins: Dpa.Spec.Configuration.Velero.DefaultPlugins, }, Restic: &oadpv1alpha1.ResticConfig{ PodConfig: &oadpv1alpha1.PodConfig{ @@ -506,7 +507,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil), Entry("Enable tolerations", InstallCase{ Name: "default-cr-tolerations", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ BackupLocations: []oadpv1alpha1.BackupLocation{ { @@ -517,7 +518,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -526,7 +527,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, - DefaultPlugins: dpa.Spec.Configuration.Velero.DefaultPlugins, + DefaultPlugins: Dpa.Spec.Configuration.Velero.DefaultPlugins, }, Restic: &oadpv1alpha1.ResticConfig{ PodConfig: &oadpv1alpha1.PodConfig{ @@ -547,13 +548,13 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil), Entry("NoDefaultBackupLocation", InstallCase{ Name: "default-cr-node-selector", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, NoDefaultBackupLocation: true, - DefaultPlugins: dpa.Spec.Configuration.Velero.DefaultPlugins, + DefaultPlugins: Dpa.Spec.Configuration.Velero.DefaultPlugins, }, Restic: &oadpv1alpha1.ResticConfig{ PodConfig: &oadpv1alpha1.PodConfig{}, @@ -565,7 +566,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil), Entry("AWS Without Region No S3ForcePathStyle with BackupImages false should succeed", InstallCase{ Name: "default-no-region-no-s3forcepathstyle", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ BackupImages: pointer.Bool(false), BackupLocations: []oadpv1alpha1.BackupLocation{ @@ -576,7 +577,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -596,7 +597,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil), Entry("AWS With Region And S3ForcePathStyle should succeed", InstallCase{ Name: "default-with-region-and-s3forcepathstyle", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ BackupLocations: []oadpv1alpha1.BackupLocation{ { @@ -610,7 +611,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -630,7 +631,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, nil), Entry("AWS Without Region And S3ForcePathStyle true should fail", InstallCase{ Name: "default-with-region-and-s3forcepathstyle", - BRestoreType: restic, + BRestoreType: RESTIC, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ BackupLocations: []oadpv1alpha1.BackupLocation{ { @@ -643,7 +644,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index db54d52f99..0facd7d351 100755 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -1,4 +1,4 @@ -package e2e +package e2e_test import ( "errors" @@ -9,6 +9,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + . "github.com/openshift/oadp-operator/tests/e2e/lib" + utils "github.com/openshift/oadp-operator/tests/e2e/utils" ) // Common vars obtained from flags passed in ginkgo. @@ -32,44 +34,44 @@ func init() { func TestOADPE2E(t *testing.T) { flag.Parse() - errString := loadDpaSettingsFromJson(settings) + errString := LoadDpaSettingsFromJson(settings) if errString != "" { t.Fatalf(errString) } - log.Println("Using velero prefix: " + veleroPrefix) + log.Println("Using velero prefix: " + VeleroPrefix) RegisterFailHandler(Fail) RunSpecs(t, "OADP E2E Suite") } -var dpaCR *dpaCustomResource +var dpaCR *DpaCustomResource var _ = BeforeSuite(func() { flag.Parse() - errString := loadDpaSettingsFromJson(settings) + errString := LoadDpaSettingsFromJson(settings) if errString != "" { Expect(errors.New(errString)).NotTo(HaveOccurred()) } - - credData, err := readFile(cloud) + + credData, err := utils.ReadFile(cloud) Expect(err).NotTo(HaveOccurred()) - err = createCredentialsSecret(credData, namespace, getSecretRef(credSecretRef)) + err = CreateCredentialsSecret(credData, namespace, GetSecretRef(credSecretRef)) Expect(err).NotTo(HaveOccurred()) - dpaCR = &dpaCustomResource{ + dpaCR = &DpaCustomResource{ Namespace: namespace, } - dpaCR.CustomResource = dpa + dpaCR.CustomResource = Dpa testSuiteInstanceName := "ts-" + instanceName dpaCR.Name = testSuiteInstanceName dpaCR.SetClient() - Expect(doesNamespaceExist(namespace)).Should(BeTrue()) + Expect(DoesNamespaceExist(namespace)).Should(BeTrue()) }) var _ = AfterSuite(func() { log.Printf("Deleting Velero CR") - errs := deleteSecret(namespace, getSecretRef(credSecretRef)) + errs := DeleteSecret(namespace, GetSecretRef(credSecretRef)) Expect(errs).ToNot(HaveOccurred()) err := dpaCR.Delete() Expect(err).ToNot(HaveOccurred()) diff --git a/tests/e2e/lib/apps.go b/tests/e2e/lib/apps.go index ab4508a624..927a4613f8 100755 --- a/tests/e2e/lib/apps.go +++ b/tests/e2e/lib/apps.go @@ -1,4 +1,4 @@ -package e2e +package lib import ( "context" @@ -8,19 +8,16 @@ import ( "github.com/onsi/ginkgo" ocpappsv1 "github.com/openshift/api/apps/v1" - appsv1 "k8s.io/api/apps/v1" - security "github.com/openshift/api/security/v1" - corev1 "k8s.io/api/core/v1" + appsv1 "k8s.io/api/apps/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/serializer/yaml" "k8s.io/apimachinery/pkg/util/wait" "sigs.k8s.io/controller-runtime/pkg/client" ) -func installApplication(ocClient client.Client, file string) error { +func InstallApplication(ocClient client.Client, file string) error { template, err := os.ReadFile(file) if err != nil { return err @@ -43,7 +40,7 @@ func installApplication(ocClient client.Client, file string) error { return nil } -func doesSCCExist(ocClient client.Client, sccName string) (bool, error) { +func DoesSCCExist(ocClient client.Client, sccName string) (bool, error) { scc := security.SecurityContextConstraints{} err := ocClient.Get(context.Background(), client.ObjectKey{ Name: sccName, @@ -55,7 +52,7 @@ func doesSCCExist(ocClient client.Client, sccName string) (bool, error) { } -func uninstallApplication(ocClient client.Client, file string) error { +func UninstallApplication(ocClient client.Client, file string) error { template, err := os.ReadFile(file) if err != nil { return err @@ -78,38 +75,38 @@ func uninstallApplication(ocClient client.Client, file string) error { return nil } -func areApplicationPodsRunning(namespace string) wait.ConditionFunc { - return func() (bool, error) { - clientset, err := setUpClient() - if err != nil { - return false, err - } - // select Velero pod with this label - veleroOptions := metav1.ListOptions{ - LabelSelector: "e2e-app=true", - } - // get pods in test namespace with labelSelector - podList, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), veleroOptions) - if err != nil { - return false, nil - } - if len(podList.Items) == 0 { - return false, nil - } - // get pod name and status with specified label selector - for _, podInfo := range podList.Items { - phase := podInfo.Status.Phase - if phase != corev1.PodRunning && phase != corev1.PodSucceeded { - ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("Pod %v not yet succeeded", podInfo.Name))) - ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("status: %v", podInfo.Status))) - return false, nil - } - } - return true, err - } -} +// func AreApplicationPodsRunning(namespace string) wait.ConditionFunc { +// return func() (bool, error) { +// clientset, err := setUpClient() +// if err != nil { +// return false, err +// } +// // select Velero pod with this label +// veleroOptions := metav1.ListOptions{ +// LabelSelector: "e2e-app=true", +// } +// // get pods in test namespace with labelSelector +// podList, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), veleroOptions) +// if err != nil { +// return false, nil +// } +// if len(podList.Items) == 0 { +// return false, nil +// } +// // get pod name and status with specified label selector +// for _, podInfo := range podList.Items { +// phase := podInfo.Status.Phase +// if phase != corev1.PodRunning && phase != corev1.PodSucceeded { +// ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("Pod %v not yet succeeded", podInfo.Name))) +// ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("status: %v", podInfo.Status))) +// return false, nil +// } +// } +// return true, err +// } +// } -func isDCReady(ocClient client.Client, namespace, dcName string) wait.ConditionFunc { +func IsDCReady(ocClient client.Client, namespace, dcName string) wait.ConditionFunc { return func() (bool, error) { dc := ocpappsv1.DeploymentConfig{} err := ocClient.Get(context.Background(), client.ObjectKey{ @@ -131,7 +128,7 @@ func isDCReady(ocClient client.Client, namespace, dcName string) wait.ConditionF } } -func isDeploymentReady(ocClient client.Client, namespace, dName string) wait.ConditionFunc { +func IsDeploymentReady(ocClient client.Client, namespace, dName string) wait.ConditionFunc { return func() (bool, error) { deployment := appsv1.Deployment{} err := ocClient.Get(context.Background(), client.ObjectKey{ diff --git a/tests/e2e/lib/backup.go b/tests/e2e/lib/backup.go index e62d952350..2f6e5a4b26 100755 --- a/tests/e2e/lib/backup.go +++ b/tests/e2e/lib/backup.go @@ -1,4 +1,4 @@ -package e2e +package lib import ( "context" @@ -11,7 +11,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func createBackupForNamespaces(ocClient client.Client, veleroNamespace, backupName string, namespaces []string) error { +func CreateBackupForNamespaces(ocClient client.Client, veleroNamespace, backupName string, namespaces []string) error { backup := velero.Backup{ ObjectMeta: metav1.ObjectMeta{ @@ -26,7 +26,7 @@ func createBackupForNamespaces(ocClient client.Client, veleroNamespace, backupNa return err } -func isBackupDone(ocClient client.Client, veleroNamespace, name string) wait.ConditionFunc { +func IsBackupDone(ocClient client.Client, veleroNamespace, name string) wait.ConditionFunc { return func() (bool, error) { backup := velero.Backup{} err := ocClient.Get(context.Background(), client.ObjectKey{ @@ -46,7 +46,7 @@ func isBackupDone(ocClient client.Client, veleroNamespace, name string) wait.Con } } -func isBackupCompletedSuccessfully(ocClient client.Client, veleroNamespace, name string) (bool, error) { +func IsBackupCompletedSuccessfully(ocClient client.Client, veleroNamespace, name string) (bool, error) { backup := velero.Backup{} err := ocClient.Get(context.Background(), client.ObjectKey{ Namespace: veleroNamespace, @@ -58,5 +58,5 @@ func isBackupCompletedSuccessfully(ocClient client.Client, veleroNamespace, name if backup.Status.Phase == velero.BackupPhaseCompleted { return true, nil } - return false, fmt.Errorf("backup phase is: %s; expected: %s\nvalidation errors: %v\nvelero failure logs: %v", backup.Status.Phase, velero.BackupPhaseCompleted, backup.Status.ValidationErrors, getVeleroContainerFailureLogs(veleroNamespace)) + return false, fmt.Errorf("backup phase is: %s; expected: %s\nvalidation errors: %v\nvelero failure logs: %v", backup.Status.Phase, velero.BackupPhaseCompleted, backup.Status.ValidationErrors, GetVeleroContainerFailureLogs(veleroNamespace)) } diff --git a/tests/e2e/lib/dpa_helpers.go b/tests/e2e/lib/dpa_helpers.go index 03547dc4d7..0ac5af5248 100755 --- a/tests/e2e/lib/dpa_helpers.go +++ b/tests/e2e/lib/dpa_helpers.go @@ -1,4 +1,4 @@ -package e2e +package lib import ( "bytes" @@ -11,8 +11,11 @@ import ( "reflect" "strings" + "github.com/ghodss/yaml" "github.com/openshift/oadp-operator/pkg/common" + utils "github.com/openshift/oadp-operator/tests/e2e/utils" + appsv1 "github.com/openshift/api/apps/v1" security "github.com/openshift/api/security/v1" oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1" @@ -31,11 +34,11 @@ import ( type BackupRestoreType string const ( - csi BackupRestoreType = "csi" - restic BackupRestoreType = "restic" + CSI BackupRestoreType = "csi" + RESTIC BackupRestoreType = "restic" ) -type dpaCustomResource struct { +type DpaCustomResource struct { Name string Namespace string SecretName string @@ -44,10 +47,10 @@ type dpaCustomResource struct { Client client.Client } -var veleroPrefix = "velero-e2e-" + string(uuid.NewUUID()) -var dpa *oadpv1alpha1.DataProtectionApplication +var VeleroPrefix = "velero-e2e-" + string(uuid.NewUUID()) +var Dpa *oadpv1alpha1.DataProtectionApplication -func (v *dpaCustomResource) Build(backupRestoreType BackupRestoreType) error { +func (v *DpaCustomResource) Build(backupRestoreType BackupRestoreType) error { // Velero Instance creation spec with backupstorage location default to AWS. Would need to parameterize this later on to support multiple plugins. dpaInstance := oadpv1alpha1.DataProtectionApplication{ ObjectMeta: metav1.ObjectMeta{ @@ -74,7 +77,7 @@ func (v *dpaCustomResource) Build(backupRestoreType BackupRestoreType) error { StorageType: velero.StorageType{ ObjectStorage: &velero.ObjectStorageLocation{ Bucket: v.CustomResource.Spec.BackupLocations[0].Velero.ObjectStorage.Bucket, - Prefix: veleroPrefix, + Prefix: VeleroPrefix, }, }, }, @@ -84,9 +87,9 @@ func (v *dpaCustomResource) Build(backupRestoreType BackupRestoreType) error { } v.backupRestoreType = backupRestoreType switch backupRestoreType { - case restic: + case RESTIC: dpaInstance.Spec.Configuration.Restic.Enable = pointer.Bool(true) - case csi: + case CSI: dpaInstance.Spec.Configuration.Restic.Enable = pointer.Bool(false) dpaInstance.Spec.Configuration.Velero.DefaultPlugins = append(dpaInstance.Spec.Configuration.Velero.DefaultPlugins, oadpv1alpha1.DefaultPluginCSI) dpaInstance.Spec.Configuration.Velero.FeatureFlags = append(dpaInstance.Spec.Configuration.Velero.FeatureFlags, "EnableCSI") @@ -95,7 +98,7 @@ func (v *dpaCustomResource) Build(backupRestoreType BackupRestoreType) error { return nil } -func (v *dpaCustomResource) Create() error { +func (v *DpaCustomResource) Create() error { err := v.SetClient() if err != nil { return err @@ -109,7 +112,7 @@ func (v *dpaCustomResource) Create() error { return nil } -func (v *dpaCustomResource) Get() (*oadpv1alpha1.DataProtectionApplication, error) { +func (v *DpaCustomResource) Get() (*oadpv1alpha1.DataProtectionApplication, error) { err := v.SetClient() if err != nil { return nil, err @@ -125,12 +128,12 @@ func (v *dpaCustomResource) Get() (*oadpv1alpha1.DataProtectionApplication, erro return &vel, nil } -func (v *dpaCustomResource) GetNoErr() *oadpv1alpha1.DataProtectionApplication { - dpa, _ := v.Get() - return dpa +func (v *DpaCustomResource) GetNoErr() *oadpv1alpha1.DataProtectionApplication { + Dpa, _ := v.Get() + return Dpa } -func (v *dpaCustomResource) CreateOrUpdate(spec *oadpv1alpha1.DataProtectionApplicationSpec) error { +func (v *DpaCustomResource) CreateOrUpdate(spec *oadpv1alpha1.DataProtectionApplicationSpec) error { cr, err := v.Get() if apierrors.IsNotFound(err) { v.Build(v.backupRestoreType) @@ -144,7 +147,7 @@ func (v *dpaCustomResource) CreateOrUpdate(spec *oadpv1alpha1.DataProtectionAppl return v.Client.Update(context.Background(), cr) } -func (v *dpaCustomResource) Delete() error { +func (v *DpaCustomResource) Delete() error { err := v.SetClient() if err != nil { return err @@ -156,7 +159,7 @@ func (v *dpaCustomResource) Delete() error { return err } -func (v *dpaCustomResource) SetClient() error { +func (v *DpaCustomResource) SetClient() error { client, err := client.New(config.GetConfigOrDie(), client.Options{}) if err != nil { return err @@ -171,7 +174,7 @@ func (v *dpaCustomResource) SetClient() error { return nil } -func getVeleroPods(namespace string) (*corev1.PodList, error) { +func GetVeleroPods(namespace string) (*corev1.PodList, error) { clientset, err := setUpClient() if err != nil { return nil, err @@ -188,9 +191,9 @@ func getVeleroPods(namespace string) (*corev1.PodList, error) { return podList, nil } -func areVeleroPodsRunning(namespace string) wait.ConditionFunc { +func AreVeleroPodsRunning(namespace string) wait.ConditionFunc { return func() (bool, error) { - podList, err := getVeleroPods(namespace) + podList, err := GetVeleroPods(namespace) if err != nil { return false, err } @@ -206,7 +209,7 @@ func areVeleroPodsRunning(namespace string) wait.ConditionFunc { // Returns logs from velero container on velero pod func getVeleroContainerLogs(namespace string) (string, error) { - podList, err := getVeleroPods(namespace) + podList, err := GetVeleroPods(namespace) if err != nil { return "", err } @@ -238,7 +241,7 @@ func getVeleroContainerLogs(namespace string) (string, error) { return logs, nil } -func getVeleroContainerFailureLogs(namespace string) []string { +func GetVeleroContainerFailureLogs(namespace string) []string { containerLogs, err := getVeleroContainerLogs(namespace) if err != nil { log.Printf("cannot get velero container logs") @@ -254,7 +257,7 @@ func getVeleroContainerFailureLogs(namespace string) []string { return failureArr } -func (v *dpaCustomResource) IsDeleted() wait.ConditionFunc { +func (v *DpaCustomResource) IsDeleted() wait.ConditionFunc { return func() (bool, error) { err := v.SetClient() if err != nil { @@ -274,7 +277,7 @@ func (v *dpaCustomResource) IsDeleted() wait.ConditionFunc { } //check if bsl matches the spec -func doesBSLExist(namespace string, bsl velero.BackupStorageLocationSpec, spec *oadpv1alpha1.DataProtectionApplicationSpec) wait.ConditionFunc { +func DoesBSLExist(namespace string, bsl velero.BackupStorageLocationSpec, spec *oadpv1alpha1.DataProtectionApplicationSpec) wait.ConditionFunc { return func() (bool, error) { if len(spec.BackupLocations) == 0 { return false, errors.New("no backup storage location configured. Expected BSL to be configured") @@ -291,7 +294,7 @@ func doesBSLExist(namespace string, bsl velero.BackupStorageLocationSpec, spec * } //check if vsl matches the spec -func doesVSLExist(namespace string, vslspec velero.VolumeSnapshotLocationSpec, spec *oadpv1alpha1.DataProtectionApplicationSpec) wait.ConditionFunc { +func DoesVSLExist(namespace string, vslspec velero.VolumeSnapshotLocationSpec, spec *oadpv1alpha1.DataProtectionApplicationSpec) wait.ConditionFunc { return func() (bool, error) { if len(spec.SnapshotLocations) == 0 { @@ -308,12 +311,13 @@ func doesVSLExist(namespace string, vslspec velero.VolumeSnapshotLocationSpec, s } //check velero tolerations -func verifyVeleroTolerations(namespace string, t []corev1.Toleration) wait.ConditionFunc { +func VerifyVeleroTolerations(namespace string, t []corev1.Toleration) wait.ConditionFunc { return func() (bool, error) { clientset, err := setUpClient() if err != nil { return false, err } + veldep, _ := clientset.AppsV1().Deployments(namespace).Get(context.Background(), "velero", metav1.GetOptions{}) if !reflect.DeepEqual(t, veldep.Spec.Template.Spec.Tolerations) { @@ -324,7 +328,7 @@ func verifyVeleroTolerations(namespace string, t []corev1.Toleration) wait.Condi } // check for velero resource requests -func verifyVeleroResourceRequests(namespace string, requests corev1.ResourceList) wait.ConditionFunc { +func VerifyVeleroResourceRequests(namespace string, requests corev1.ResourceList) wait.ConditionFunc { return func() (bool, error) { clientset, err := setUpClient() if err != nil { @@ -344,7 +348,7 @@ func verifyVeleroResourceRequests(namespace string, requests corev1.ResourceList } // check for velero resource limits -func verifyVeleroResourceLimits(namespace string, limits corev1.ResourceList) wait.ConditionFunc { +func VerifyVeleroResourceLimits(namespace string, limits corev1.ResourceList) wait.ConditionFunc { return func() (bool, error) { clientset, err := setUpClient() if err != nil { @@ -363,24 +367,93 @@ func verifyVeleroResourceLimits(namespace string, limits corev1.ResourceList) wa } } -func loadDpaSettingsFromJson(settings string) string { - file, err := readFile(settings) +func LoadDpaSettingsFromJson(settings string) string { + file, err := utils.ReadFile(settings) if err != nil { return fmt.Sprintf("Error decoding json file: %v", err) } - dpa = &oadpv1alpha1.DataProtectionApplication{} - err = json.Unmarshal(file, &dpa) + Dpa = &oadpv1alpha1.DataProtectionApplication{} + err = json.Unmarshal(file, &Dpa) if err != nil { return fmt.Sprintf("Error getting settings json file: %v", err) } return "" } -func getSecretRef(credSecretRef string) string { - if dpa.Spec.BackupLocations[0].Velero.Credential == nil { +func GetSecretRef(credSecretRef string) string { + if Dpa.Spec.BackupLocations[0].Velero.Credential == nil { return credSecretRef } else { - return dpa.Spec.BackupLocations[0].Velero.Credential.Name + return Dpa.Spec.BackupLocations[0].Velero.Credential.Name + } +} + +// // Parses a template file with the provided data and returns contents as byte array +// func parseTemplate(templateFile string, data interface{}) ([]byte, error) { +// // Parse the template file +// var tmpl *template.Template +// tmpl, err := template.ParseFiles(templateFile) +// if err != nil { +// return nil, err +// } + +// // Create a temporary file to be able to write parsed data +// tempYamlFile, err := os.CreateTemp("templates/", "temp*.yaml") +// if err != nil { +// return nil, err +// } + +// // Write data object values to temporary file +// err = tmpl.Execute(tempYamlFile, data) +// if err != nil { +// return nil, err +// } + +// // Read the temporary file as byte array +// parsedData, err := ioutil.ReadFile(tempYamlFile.Name()) +// if err != nil { +// return nil, err +// } + +// // Close and clean up temp resources +// tempYamlFile.Close() +// defer os.Remove(tempYamlFile.Name()) + +// return parsedData, nil +// } + +// Create DPA Custom Resource Definition from yaml +func (v *DpaCustomResource) CreateDpaFromYaml(yamlTemplatePath string, data interface{}) error { + // Define var for holding DPA type + dpaSpec := oadpv1alpha1.DataProtectionApplication{} + + // Parse and read data as bytes from template + dpaYamlData, err := utils.ParseTemplate(yamlTemplatePath, data) + if err != nil { + return err + } + + // Unmarshall data to type DPA + err = yaml.Unmarshal(dpaYamlData, &dpaSpec) + if err != nil { + return err } + + // Set client config to read/write resources through API + err = v.SetClient() + if err != nil { + return err + } + + v.CustomResource = &dpaSpec + + // Create custom resource + err = v.Client.Create(context.Background(), v.CustomResource) + if apierrors.IsAlreadyExists(err) { + return errors.New("found unexpected existing DPA") + } else if err != nil { + return err + } + return nil } diff --git a/tests/e2e/utils/common.go b/tests/e2e/lib/kube_helpers.go similarity index 69% rename from tests/e2e/utils/common.go rename to tests/e2e/lib/kube_helpers.go index 7d7519c37d..9025555d18 100755 --- a/tests/e2e/utils/common.go +++ b/tests/e2e/lib/kube_helpers.go @@ -1,11 +1,12 @@ -package e2e +package lib import ( "context" "encoding/json" - "io/ioutil" + "fmt" "log" + "github.com/onsi/ginkgo" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -16,25 +17,25 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/config" ) -type k8sVersion struct { +type K8sVersion struct { Major string Minor string } var ( // Version struct representing OCP 4.8.x https://docs.openshift.com/container-platform/4.8/release_notes/ocp-4-8-release-notes.html - k8sVersionOcp48 = k8sVersion{ + K8sVersionOcp48 = K8sVersion{ Major: "1", Minor: "21", } // https://docs.openshift.com/container-platform/4.7/release_notes/ocp-4-7-release-notes.html - k8sVersionOcp47 = k8sVersion{ + K8sVersionOcp47 = K8sVersion{ Major: "1", Minor: "20", } ) -func k8sVersionGreater(v1 *k8sVersion, v2 *k8sVersion) bool { +func k8sVersionGreater(v1 *K8sVersion, v2 *K8sVersion) bool { if v1.Major > v2.Major { return true } @@ -44,7 +45,7 @@ func k8sVersionGreater(v1 *k8sVersion, v2 *k8sVersion) bool { return false } -func k8sVersionLesser(v1 *k8sVersion, v2 *k8sVersion) bool { +func k8sVersionLesser(v1 *K8sVersion, v2 *K8sVersion) bool { if v1.Major < v2.Major { return true } @@ -54,15 +55,15 @@ func k8sVersionLesser(v1 *k8sVersion, v2 *k8sVersion) bool { return false } -func serverK8sVersion() *k8sVersion { +func serverK8sVersion() *K8sVersion { version, err := serverVersion() if err != nil { return nil } - return &k8sVersion{Major: version.Major, Minor: version.Minor} + return &K8sVersion{Major: version.Major, Minor: version.Minor} } -func NotServerVersionTarget(minVersion *k8sVersion, maxVersion *k8sVersion) (bool, string) { +func NotServerVersionTarget(minVersion *K8sVersion, maxVersion *K8sVersion) (bool, string) { serverVersion := serverK8sVersion() if maxVersion != nil && k8sVersionGreater(serverVersion, maxVersion) { return true, "Server Version is greater than max target version" @@ -130,7 +131,7 @@ func getKubeConfig() *rest.Config { } // FIXME: Remove -func doesNamespaceExist(namespace string) (bool, error) { +func DoesNamespaceExist(namespace string) (bool, error) { clientset, err := setUpClient() if err != nil { return false, err @@ -143,7 +144,7 @@ func doesNamespaceExist(namespace string) (bool, error) { } // Keeping it for now. -func isNamespaceDeleted(namespace string) wait.ConditionFunc { +func IsNamespaceDeleted(namespace string) wait.ConditionFunc { return func() (bool, error) { clientset, err := setUpClient() if err != nil { @@ -165,18 +166,18 @@ func serverVersion() (*version.Info, error) { return clientset.Discovery().ServerVersion() } -func readFile(path string) ([]byte, error) { - // pass in aws credentials by cli flag - // from cli: -cloud=<"filepath"> - // go run main.go -cloud="/Users/emilymcmullan/.aws/credentials" - // cloud := flag.String("cloud", "", "file path for aws credentials") - // flag.Parse() - // save passed in cred file as []byteq - file, err := ioutil.ReadFile(path) - return file, err -} +// func ReadFile(path string) ([]byte, error) { +// // pass in aws credentials by cli flag +// // from cli: -cloud=<"filepath"> +// // go run main.go -cloud="/Users/emilymcmullan/.aws/credentials" +// // cloud := flag.String("cloud", "", "file path for aws credentials") +// // flag.Parse() +// // save passed in cred file as []byteq +// file, err := ioutil.ReadFile(path) +// return file, err +// } -func createCredentialsSecret(data []byte, namespace string, credSecretRef string) error { +func CreateCredentialsSecret(data []byte, namespace string, credSecretRef string) error { clientset, err := setUpClient() if err != nil { return err @@ -202,7 +203,7 @@ func createCredentialsSecret(data []byte, namespace string, credSecretRef string return err } -func deleteSecret(namespace string, credSecretRef string) error { +func DeleteSecret(namespace string, credSecretRef string) error { clientset, err := setUpClient() if err != nil { return err @@ -230,3 +231,33 @@ func isCredentialsSecretDeleted(namespace string, credSecretRef string) wait.Con } } +func AreApplicationPodsRunning(namespace string) wait.ConditionFunc { + return func() (bool, error) { + clientset, err := setUpClient() + if err != nil { + return false, err + } + // select Velero pod with this label + veleroOptions := metav1.ListOptions{ + LabelSelector: "e2e-app=true", + } + // get pods in test namespace with labelSelector + podList, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), veleroOptions) + if err != nil { + return false, nil + } + if len(podList.Items) == 0 { + return false, nil + } + // get pod name and status with specified label selector + for _, podInfo := range podList.Items { + phase := podInfo.Status.Phase + if phase != corev1.PodRunning && phase != corev1.PodSucceeded { + ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("Pod %v not yet succeeded", podInfo.Name))) + ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("status: %v", podInfo.Status))) + return false, nil + } + } + return true, err + } +} diff --git a/tests/e2e/lib/plugins_helpers.go b/tests/e2e/lib/plugins_helpers.go index 85341169a0..23701cdc01 100755 --- a/tests/e2e/lib/plugins_helpers.go +++ b/tests/e2e/lib/plugins_helpers.go @@ -1,4 +1,4 @@ -package e2e +package lib import ( "context" @@ -11,7 +11,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func (d *dpaCustomResource) removeVeleroPlugin(namespace string, instanceName string, pluginValues []oadpv1alpha1.DefaultPlugin, removedPlugin string) error { +func (d *DpaCustomResource) RemoveVeleroPlugin(namespace string, instanceName string, pluginValues []oadpv1alpha1.DefaultPlugin, removedPlugin string) error { err := d.SetClient() if err != nil { return err @@ -35,7 +35,7 @@ func (d *dpaCustomResource) removeVeleroPlugin(namespace string, instanceName st return nil } -func doesPluginExist(namespace string, plugin oadpv1alpha1.DefaultPlugin) wait.ConditionFunc { +func DoesPluginExist(namespace string, plugin oadpv1alpha1.DefaultPlugin) wait.ConditionFunc { return func() (bool, error) { clientset, err := setUpClient() if err != nil { @@ -58,7 +58,7 @@ func doesPluginExist(namespace string, plugin oadpv1alpha1.DefaultPlugin) wait.C } } -func doesCustomPluginExist(namespace string, plugin oadpv1alpha1.CustomPlugin) wait.ConditionFunc { +func DoesCustomPluginExist(namespace string, plugin oadpv1alpha1.CustomPlugin) wait.ConditionFunc { return func() (bool, error) { clientset, err := setUpClient() if err != nil { @@ -79,7 +79,7 @@ func doesCustomPluginExist(namespace string, plugin oadpv1alpha1.CustomPlugin) w } } -func doesVeleroDeploymentExist(namespace string, deploymentName string) wait.ConditionFunc { +func DoesVeleroDeploymentExist(namespace string, deploymentName string) wait.ConditionFunc { log.Printf("Waiting for velero deployment to be created...") return func() (bool, error) { client, err := setUpClient() diff --git a/tests/e2e/lib/registry_helpers.go b/tests/e2e/lib/registry_helpers.go index 364b18b6f0..0a2c673b2f 100755 --- a/tests/e2e/lib/registry_helpers.go +++ b/tests/e2e/lib/registry_helpers.go @@ -1,4 +1,4 @@ -package e2e +package lib import ( "context" @@ -11,7 +11,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" ) -func areRegistryDeploymentsAvailable(namespace string) wait.ConditionFunc { +func AreRegistryDeploymentsAvailable(namespace string) wait.ConditionFunc { log.Printf("Checking for available registry deployments") return func() (bool, error) { client, err := setUpClient() diff --git a/tests/e2e/lib/restic_helpers.go b/tests/e2e/lib/restic_helpers.go index 9a552577ed..1c5967f20d 100755 --- a/tests/e2e/lib/restic_helpers.go +++ b/tests/e2e/lib/restic_helpers.go @@ -1,4 +1,4 @@ -package e2e +package lib import ( "context" @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func hasCorrectNumResticPods(namespace string) wait.ConditionFunc { +func HasCorrectNumResticPods(namespace string) wait.ConditionFunc { return func() (bool, error) { client, err := setUpClient() if err != nil { @@ -47,10 +47,10 @@ func hasCorrectNumResticPods(namespace string) wait.ConditionFunc { } func waitForDesiredResticPods(namespace string) error { - return wait.PollImmediate(time.Second*5, time.Minute*2, hasCorrectNumResticPods(namespace)) + return wait.PollImmediate(time.Second*5, time.Minute*2, HasCorrectNumResticPods(namespace)) } -func areResticPodsRunning(namespace string) wait.ConditionFunc { +func AreResticPodsRunning(namespace string) wait.ConditionFunc { log.Printf("Checking for correct number of running Restic pods...") return func() (bool, error) { err := waitForDesiredResticPods(namespace) @@ -79,7 +79,7 @@ func areResticPodsRunning(namespace string) wait.ConditionFunc { } } -func doesDaemonSetExists(namespace string, resticName string) wait.ConditionFunc { +func DoesDaemonSetExists(namespace string, resticName string) wait.ConditionFunc { log.Printf("Checking if restic daemonset exists...") return func() (bool, error) { clientset, err := setUpClient() @@ -95,7 +95,7 @@ func doesDaemonSetExists(namespace string, resticName string) wait.ConditionFunc } // keep for now -func isResticDaemonsetDeleted(namespace string) wait.ConditionFunc { +func IsResticDaemonsetDeleted(namespace string) wait.ConditionFunc { log.Printf("Checking if Restic daemonset has been deleted...") return func() (bool, error) { client, err := setUpClient() @@ -111,7 +111,7 @@ func isResticDaemonsetDeleted(namespace string) wait.ConditionFunc { } } -func (v *dpaCustomResource) disableRestic(namespace string, instanceName string) error { +func (v *DpaCustomResource) DisableRestic(namespace string, instanceName string) error { err := v.SetClient() if err != nil { return err @@ -134,7 +134,7 @@ func (v *dpaCustomResource) disableRestic(namespace string, instanceName string) return nil } -func (v *dpaCustomResource) enableResticNodeSelector(namespace string, s3Bucket string, credSecretRef string, instanceName string) error { +func (v *DpaCustomResource) EnableResticNodeSelector(namespace string, s3Bucket string, credSecretRef string, instanceName string) error { err := v.SetClient() if err != nil { return err @@ -158,7 +158,7 @@ func (v *dpaCustomResource) enableResticNodeSelector(namespace string, s3Bucket return nil } -func resticDaemonSetHasNodeSelector(namespace, key, value string) wait.ConditionFunc { +func ResticDaemonSetHasNodeSelector(namespace, key, value string) wait.ConditionFunc { return func() (bool, error) { client, err := setUpClient() if err != nil { diff --git a/tests/e2e/lib/restore.go b/tests/e2e/lib/restore.go index aa69e92d60..fcaba86cc7 100755 --- a/tests/e2e/lib/restore.go +++ b/tests/e2e/lib/restore.go @@ -1,4 +1,4 @@ -package e2e +package lib import ( "context" @@ -11,7 +11,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func createRestoreFromBackup(ocClient client.Client, veleroNamespace, backupName, restoreName string) error { +func CreateRestoreFromBackup(ocClient client.Client, veleroNamespace, backupName, restoreName string) error { restore := velero.Restore{ ObjectMeta: metav1.ObjectMeta{ Name: restoreName, @@ -25,7 +25,7 @@ func createRestoreFromBackup(ocClient client.Client, veleroNamespace, backupName return err } -func isRestoreDone(ocClient client.Client, veleroNamespace, name string) wait.ConditionFunc { +func IsRestoreDone(ocClient client.Client, veleroNamespace, name string) wait.ConditionFunc { return func() (bool, error) { restore := velero.Restore{} err := ocClient.Get(context.Background(), client.ObjectKey{ @@ -45,7 +45,7 @@ func isRestoreDone(ocClient client.Client, veleroNamespace, name string) wait.Co } } -func isRestoreCompletedSuccessfully(ocClient client.Client, veleroNamespace, name string) (bool, error) { +func IsRestoreCompletedSuccessfully(ocClient client.Client, veleroNamespace, name string) (bool, error) { restore := velero.Restore{} err := ocClient.Get(context.Background(), client.ObjectKey{ Namespace: veleroNamespace, @@ -57,5 +57,5 @@ func isRestoreCompletedSuccessfully(ocClient client.Client, veleroNamespace, nam if restore.Status.Phase == velero.RestorePhaseCompleted { return true, nil } - return false, fmt.Errorf("restore phase is: %s; expected: %s\nfailure reason: %s\nvalidation errors: %v\nvelero failure logs: %v", restore.Status.Phase, velero.RestorePhaseCompleted, restore.Status.FailureReason, restore.Status.ValidationErrors, getVeleroContainerFailureLogs(veleroNamespace)) + return false, fmt.Errorf("restore phase is: %s; expected: %s\nfailure reason: %s\nvalidation errors: %v\nvelero failure logs: %v", restore.Status.Phase, velero.RestorePhaseCompleted, restore.Status.FailureReason, restore.Status.ValidationErrors, GetVeleroContainerFailureLogs(veleroNamespace)) } diff --git a/tests/e2e/lib/subscription_helpers.go b/tests/e2e/lib/subscription_helpers.go index 0b669c0441..e9673e9532 100644 --- a/tests/e2e/lib/subscription_helpers.go +++ b/tests/e2e/lib/subscription_helpers.go @@ -1,4 +1,4 @@ -package e2e +package lib import ( "context" @@ -16,7 +16,7 @@ type Subscription struct { *operators.Subscription } -func (d *dpaCustomResource) getOperatorSubscription() (*Subscription, error) { +func (d *DpaCustomResource) GetOperatorSubscription() (*Subscription, error) { err := d.SetClient() if err != nil { return nil, err @@ -53,7 +53,7 @@ func (s *Subscription) getCSV() (*operators.ClusterServiceVersion, error) { return &csv, nil } -func (s *Subscription) csvIsReady() bool { +func (s *Subscription) CsvIsReady() bool { csv, err := s.getCSV() if err != nil { log.Printf("Error getting CSV: %v", err) @@ -61,7 +61,7 @@ func (s *Subscription) csvIsReady() bool { } return csv.Status.Phase == operators.CSVPhaseSucceeded } -func (s *Subscription) csvIsInstalling() bool { +func (s *Subscription) CsvIsInstalling() bool { csv, err := s.getCSV() if err != nil { log.Printf("Error getting CSV: %v", err) diff --git a/tests/e2e/suites/subscription_suite_test.go b/tests/e2e/subscription_suite_test.go similarity index 87% rename from tests/e2e/suites/subscription_suite_test.go rename to tests/e2e/subscription_suite_test.go index bd85dffdfe..f0a619e2ee 100644 --- a/tests/e2e/suites/subscription_suite_test.go +++ b/tests/e2e/subscription_suite_test.go @@ -1,4 +1,4 @@ -package e2e +package e2e_test import ( "context" @@ -9,6 +9,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" + . "github.com/openshift/oadp-operator/tests/e2e/lib" + utils "github.com/openshift/oadp-operator/tests/e2e/utils" operators "github.com/operator-framework/api/pkg/operators/v1alpha1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" @@ -17,7 +19,7 @@ import ( var _ = Describe("Subscription Config Suite Test", func() { var _ = BeforeEach(func() { log.Printf("Building dpaSpec") - err := dpaCR.Build(csi) + err := dpaCR.Build(CSI) Expect(err).NotTo(HaveOccurred()) //also test restic dpaCR.CustomResource.Spec.Configuration.Restic.Enable = pointer.BoolPtr(true) @@ -29,10 +31,10 @@ var _ = Describe("Subscription Config Suite Test", func() { testSuiteInstanceName := "ts-" + instanceName dpaCR.Name = testSuiteInstanceName - credData, err := readFile(cloud) + credData, err := utils.ReadFile(cloud) Expect(err).NotTo(HaveOccurred()) - err = createCredentialsSecret(credData, namespace, getSecretRef(credSecretRef)) + err = CreateCredentialsSecret(credData, namespace, GetSecretRef(credSecretRef)) Expect(err).NotTo(HaveOccurred()) }) @@ -47,7 +49,7 @@ var _ = Describe("Subscription Config Suite Test", func() { DescribeTable("Proxy test table", func(testCase SubscriptionConfigTestCase) { log.Printf("Getting Operator Subscription") - s, err := dpaCR.getOperatorSubscription() + s, err := dpaCR.GetOperatorSubscription() Expect(err).To(BeNil()) log.Printf("Setting test case subscription config") s.Spec.Config = &testCase.SubscriptionConfig @@ -58,9 +60,9 @@ var _ = Describe("Subscription Config Suite Test", func() { // get csv from installplan from subscription log.Printf("Wait for CSV to be succeeded") if testCase.failureExpected != nil && *testCase.failureExpected { - Consistently(s.csvIsReady, time.Minute*2).Should(BeFalse()) + Consistently(s.CsvIsReady, time.Minute*2).Should(BeFalse()) } else { - Eventually(s.csvIsReady, time.Minute*9).Should(BeTrue()) + Eventually(s.CsvIsReady, time.Minute*9).Should(BeTrue()) log.Printf("CreatingOrUpdate test Velero") err = dpaCR.CreateOrUpdate(&dpaCR.CustomResource.Spec) @@ -70,19 +72,19 @@ var _ = Describe("Subscription Config Suite Test", func() { velero, err := dpaCR.Get() Expect(err).NotTo(HaveOccurred()) log.Printf("Waiting for velero pod to be running") - Eventually(areVeleroPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(AreVeleroPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) if velero.Spec.Configuration.Restic.Enable != nil && *velero.Spec.Configuration.Restic.Enable { log.Printf("Waiting for restic pods to be running") - Eventually(areResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(AreResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } if velero.Spec.BackupImages == nil || *velero.Spec.BackupImages { log.Printf("Waiting for registry pods to be running") - Eventually(areRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) + Eventually(AreRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } if s.Spec.Config != nil && s.Spec.Config.Env != nil { // get pod env vars log.Printf("Getting velero pods") - podList, err := getVeleroPods(namespace) + podList, err := GetVeleroPods(namespace) Expect(err).NotTo(HaveOccurred()) log.Printf("Getting pods containers env vars") bl := dpaCR.CustomResource.Spec.BackupLocations[0] diff --git a/tests/e2e/templates/dpa_template.tmpl b/tests/e2e/templates/dpa_template.tmpl new file mode 100644 index 0000000000..26b83ea98d --- /dev/null +++ b/tests/e2e/templates/dpa_template.tmpl @@ -0,0 +1,27 @@ +apiVersion: oadp.openshift.io/v1alpha1 +kind: DataProtectionApplication +metadata: + namespace: {{ .Namespace }} + name: {{ .DpaName }} +spec: + configuration: + velero: + defaultPlugins: + - openshift + - aws + restic: + enable: true + backupLocations: + - name: default + velero: + provider: {{ .Provider }} + default: true + objectStorage: + bucket: {{ .BucketName }} + prefix: {{ .Prefix }} + config: + region: {{ .BslRegion }} + profile: {{ .ClusterProfile }} + credential: + name: {{ .CredentialsName }} + key: cloud \ No newline at end of file diff --git a/tests/e2e/utils/common_utils.go b/tests/e2e/utils/common_utils.go new file mode 100644 index 0000000000..5c5b79fb36 --- /dev/null +++ b/tests/e2e/utils/common_utils.go @@ -0,0 +1,52 @@ +package utils + +import ( + "io/ioutil" + "os" + "text/template" +) + +func ReadFile(path string) ([]byte, error) { + // pass in aws credentials by cli flag + // from cli: -cloud=<"filepath"> + // go run main.go -cloud="/Users/emilymcmullan/.aws/credentials" + // cloud := flag.String("cloud", "", "file path for aws credentials") + // flag.Parse() + // save passed in cred file as []byteq + file, err := ioutil.ReadFile(path) + return file, err +} + +// Parses a template file with the provided data and returns contents as byte array +func ParseTemplate(templateFile string, data interface{}) ([]byte, error) { + // Parse the template file + var tmpl *template.Template + tmpl, err := template.ParseFiles(templateFile) + if err != nil { + return nil, err + } + + // Create a temporary file to be able to write parsed data + tempYamlFile, err := os.CreateTemp("templates/", "temp*.yaml") + if err != nil { + return nil, err + } + + // Write data object values to temporary file + err = tmpl.Execute(tempYamlFile, data) + if err != nil { + return nil, err + } + + // Read the temporary file as byte array + parsedData, err := ioutil.ReadFile(tempYamlFile.Name()) + if err != nil { + return nil, err + } + + // Close and clean up temp resources + tempYamlFile.Close() + defer os.Remove(tempYamlFile.Name()) + + return parsedData, nil +} From 5c8dc34bd3c49664aff8f2e9b92f449fd619548d Mon Sep 17 00:00:00 2001 From: nitishSr Date: Wed, 2 Feb 2022 11:24:17 +0530 Subject: [PATCH 3/4] Removed commented code --- tests/e2e/lib/dpa_helpers.go | 34 ---------------------------------- tests/e2e/lib/kube_helpers.go | 11 ----------- 2 files changed, 45 deletions(-) diff --git a/tests/e2e/lib/dpa_helpers.go b/tests/e2e/lib/dpa_helpers.go index 0ac5af5248..df329d6245 100755 --- a/tests/e2e/lib/dpa_helpers.go +++ b/tests/e2e/lib/dpa_helpers.go @@ -389,40 +389,6 @@ func GetSecretRef(credSecretRef string) string { } } -// // Parses a template file with the provided data and returns contents as byte array -// func parseTemplate(templateFile string, data interface{}) ([]byte, error) { -// // Parse the template file -// var tmpl *template.Template -// tmpl, err := template.ParseFiles(templateFile) -// if err != nil { -// return nil, err -// } - -// // Create a temporary file to be able to write parsed data -// tempYamlFile, err := os.CreateTemp("templates/", "temp*.yaml") -// if err != nil { -// return nil, err -// } - -// // Write data object values to temporary file -// err = tmpl.Execute(tempYamlFile, data) -// if err != nil { -// return nil, err -// } - -// // Read the temporary file as byte array -// parsedData, err := ioutil.ReadFile(tempYamlFile.Name()) -// if err != nil { -// return nil, err -// } - -// // Close and clean up temp resources -// tempYamlFile.Close() -// defer os.Remove(tempYamlFile.Name()) - -// return parsedData, nil -// } - // Create DPA Custom Resource Definition from yaml func (v *DpaCustomResource) CreateDpaFromYaml(yamlTemplatePath string, data interface{}) error { // Define var for holding DPA type diff --git a/tests/e2e/lib/kube_helpers.go b/tests/e2e/lib/kube_helpers.go index 9025555d18..5ad693ec2d 100755 --- a/tests/e2e/lib/kube_helpers.go +++ b/tests/e2e/lib/kube_helpers.go @@ -166,17 +166,6 @@ func serverVersion() (*version.Info, error) { return clientset.Discovery().ServerVersion() } -// func ReadFile(path string) ([]byte, error) { -// // pass in aws credentials by cli flag -// // from cli: -cloud=<"filepath"> -// // go run main.go -cloud="/Users/emilymcmullan/.aws/credentials" -// // cloud := flag.String("cloud", "", "file path for aws credentials") -// // flag.Parse() -// // save passed in cred file as []byteq -// file, err := ioutil.ReadFile(path) -// return file, err -// } - func CreateCredentialsSecret(data []byte, namespace string, credSecretRef string) error { clientset, err := setUpClient() if err != nil { From a87edc104b077e0679203c4c3c108bcb32190709 Mon Sep 17 00:00:00 2001 From: nitishSr Date: Fri, 4 Feb 2022 19:41:58 +0530 Subject: [PATCH 4/4] Removed yaml templating changes and fixed ginkgo version2 errors for test run --- go.mod | 3 +-- go.sum | 4 +-- tests/e2e/lib/apps.go | 33 ++++++++++++++++++++++++ tests/e2e/lib/dpa_helpers.go | 36 --------------------------- tests/e2e/lib/kube_helpers.go | 33 ------------------------ tests/e2e/templates/dpa_template.tmpl | 27 -------------------- tests/e2e/utils/common_utils.go | 36 --------------------------- 7 files changed, 35 insertions(+), 137 deletions(-) delete mode 100644 tests/e2e/templates/dpa_template.tmpl diff --git a/go.mod b/go.mod index 9e0a165cd2..aabb0a25ca 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,9 @@ go 1.16 require ( github.com/aws/aws-sdk-go v1.28.2 - github.com/ghodss/yaml v1.0.0 github.com/go-logr/logr v0.4.0 github.com/google/uuid v1.1.2 - github.com/onsi/ginkgo v1.16.5 + github.com/onsi/ginkgo v1.16.4 github.com/onsi/ginkgo/v2 v2.1.1 github.com/onsi/gomega v1.17.0 github.com/openshift/api v0.0.0-20210805075156-d8fab4513288 diff --git a/go.sum b/go.sum index 184364cc12..fd61c19243 100644 --- a/go.sum +++ b/go.sum @@ -223,7 +223,6 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= @@ -571,9 +570,8 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108 github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= +github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.1.1 h1:LCnPB85AvFNr91s0B2aDzEiiIg6MUwLYbryC1NSlWi8= github.com/onsi/ginkgo/v2 v2.1.1/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= diff --git a/tests/e2e/lib/apps.go b/tests/e2e/lib/apps.go index ffb419b0e1..36478a5d12 100755 --- a/tests/e2e/lib/apps.go +++ b/tests/e2e/lib/apps.go @@ -10,7 +10,9 @@ import ( ocpappsv1 "github.com/openshift/api/apps/v1" security "github.com/openshift/api/security/v1" appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/serializer/yaml" "k8s.io/apimachinery/pkg/util/wait" @@ -149,3 +151,34 @@ func IsDeploymentReady(ocClient client.Client, namespace, dName string) wait.Con return true, nil } } + +func AreApplicationPodsRunning(namespace string) wait.ConditionFunc { + return func() (bool, error) { + clientset, err := setUpClient() + if err != nil { + return false, err + } + // select Velero pod with this label + veleroOptions := metav1.ListOptions{ + LabelSelector: "e2e-app=true", + } + // get pods in test namespace with labelSelector + podList, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), veleroOptions) + if err != nil { + return false, nil + } + if len(podList.Items) == 0 { + return false, nil + } + // get pod name and status with specified label selector + for _, podInfo := range podList.Items { + phase := podInfo.Status.Phase + if phase != corev1.PodRunning && phase != corev1.PodSucceeded { + ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("Pod %v not yet succeeded", podInfo.Name))) + ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("status: %v", podInfo.Status))) + return false, nil + } + } + return true, err + } +} diff --git a/tests/e2e/lib/dpa_helpers.go b/tests/e2e/lib/dpa_helpers.go index df329d6245..13325879a8 100755 --- a/tests/e2e/lib/dpa_helpers.go +++ b/tests/e2e/lib/dpa_helpers.go @@ -11,7 +11,6 @@ import ( "reflect" "strings" - "github.com/ghodss/yaml" "github.com/openshift/oadp-operator/pkg/common" utils "github.com/openshift/oadp-operator/tests/e2e/utils" @@ -388,38 +387,3 @@ func GetSecretRef(credSecretRef string) string { return Dpa.Spec.BackupLocations[0].Velero.Credential.Name } } - -// Create DPA Custom Resource Definition from yaml -func (v *DpaCustomResource) CreateDpaFromYaml(yamlTemplatePath string, data interface{}) error { - // Define var for holding DPA type - dpaSpec := oadpv1alpha1.DataProtectionApplication{} - - // Parse and read data as bytes from template - dpaYamlData, err := utils.ParseTemplate(yamlTemplatePath, data) - if err != nil { - return err - } - - // Unmarshall data to type DPA - err = yaml.Unmarshal(dpaYamlData, &dpaSpec) - if err != nil { - return err - } - - // Set client config to read/write resources through API - err = v.SetClient() - if err != nil { - return err - } - - v.CustomResource = &dpaSpec - - // Create custom resource - err = v.Client.Create(context.Background(), v.CustomResource) - if apierrors.IsAlreadyExists(err) { - return errors.New("found unexpected existing DPA") - } else if err != nil { - return err - } - return nil -} diff --git a/tests/e2e/lib/kube_helpers.go b/tests/e2e/lib/kube_helpers.go index 5ad693ec2d..2f69a0306b 100755 --- a/tests/e2e/lib/kube_helpers.go +++ b/tests/e2e/lib/kube_helpers.go @@ -3,10 +3,8 @@ package lib import ( "context" "encoding/json" - "fmt" "log" - "github.com/onsi/ginkgo" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -219,34 +217,3 @@ func isCredentialsSecretDeleted(namespace string, credSecretRef string) wait.Con return false, err } } - -func AreApplicationPodsRunning(namespace string) wait.ConditionFunc { - return func() (bool, error) { - clientset, err := setUpClient() - if err != nil { - return false, err - } - // select Velero pod with this label - veleroOptions := metav1.ListOptions{ - LabelSelector: "e2e-app=true", - } - // get pods in test namespace with labelSelector - podList, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), veleroOptions) - if err != nil { - return false, nil - } - if len(podList.Items) == 0 { - return false, nil - } - // get pod name and status with specified label selector - for _, podInfo := range podList.Items { - phase := podInfo.Status.Phase - if phase != corev1.PodRunning && phase != corev1.PodSucceeded { - ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("Pod %v not yet succeeded", podInfo.Name))) - ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("status: %v", podInfo.Status))) - return false, nil - } - } - return true, err - } -} diff --git a/tests/e2e/templates/dpa_template.tmpl b/tests/e2e/templates/dpa_template.tmpl deleted file mode 100644 index 26b83ea98d..0000000000 --- a/tests/e2e/templates/dpa_template.tmpl +++ /dev/null @@ -1,27 +0,0 @@ -apiVersion: oadp.openshift.io/v1alpha1 -kind: DataProtectionApplication -metadata: - namespace: {{ .Namespace }} - name: {{ .DpaName }} -spec: - configuration: - velero: - defaultPlugins: - - openshift - - aws - restic: - enable: true - backupLocations: - - name: default - velero: - provider: {{ .Provider }} - default: true - objectStorage: - bucket: {{ .BucketName }} - prefix: {{ .Prefix }} - config: - region: {{ .BslRegion }} - profile: {{ .ClusterProfile }} - credential: - name: {{ .CredentialsName }} - key: cloud \ No newline at end of file diff --git a/tests/e2e/utils/common_utils.go b/tests/e2e/utils/common_utils.go index 5c5b79fb36..d60e1f9ba0 100644 --- a/tests/e2e/utils/common_utils.go +++ b/tests/e2e/utils/common_utils.go @@ -2,8 +2,6 @@ package utils import ( "io/ioutil" - "os" - "text/template" ) func ReadFile(path string) ([]byte, error) { @@ -16,37 +14,3 @@ func ReadFile(path string) ([]byte, error) { file, err := ioutil.ReadFile(path) return file, err } - -// Parses a template file with the provided data and returns contents as byte array -func ParseTemplate(templateFile string, data interface{}) ([]byte, error) { - // Parse the template file - var tmpl *template.Template - tmpl, err := template.ParseFiles(templateFile) - if err != nil { - return nil, err - } - - // Create a temporary file to be able to write parsed data - tempYamlFile, err := os.CreateTemp("templates/", "temp*.yaml") - if err != nil { - return nil, err - } - - // Write data object values to temporary file - err = tmpl.Execute(tempYamlFile, data) - if err != nil { - return nil, err - } - - // Read the temporary file as byte array - parsedData, err := ioutil.ReadFile(tempYamlFile.Name()) - if err != nil { - return nil, err - } - - // Close and clean up temp resources - tempYamlFile.Close() - defer os.Remove(tempYamlFile.Name()) - - return parsedData, nil -}