From 98c7bd05c78a4e635a910047a198e905d214c078 Mon Sep 17 00:00:00 2001 From: Nitish Srivastava <43022982+nitishSr@users.noreply.github.com> Date: Mon, 7 Feb 2022 18:41:31 +0530 Subject: [PATCH 01/10] Replace carriage return when getting provider secrets for registry + E2E changes (#652) * Replace carriage return when getting provider secrets for registry Co-authored-by: GitHub Co-pilot * add tests * replaceCarriageReturn unit test * Registry credentials can use other secret names Co-authored-by: GitHub Co-pilot --- .gitignore | 1 + tests/e2e/backup_restore_suite_test.go | 87 ++++++++------- tests/e2e/dpa_deployment_suite_test.go | 103 +++++++++--------- tests/e2e/e2e_suite_test.go | 24 +++-- tests/e2e/{ => lib}/apps.go | 106 ++++++++++++------- tests/e2e/{ => lib}/backup.go | 10 +- tests/e2e/{ => lib}/dpa_helpers.go | 75 ++++++------- tests/e2e/{common.go => lib/kube_helpers.go} | 38 +++---- 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 +- tests/e2e/subscription_suite_test.go | 24 +++-- tests/e2e/utils/common_utils.go | 16 +++ 15 files changed, 288 insertions(+), 246 deletions(-) rename tests/e2e/{ => lib}/apps.go (72%) rename tests/e2e/{ => lib}/backup.go (86%) rename tests/e2e/{ => lib}/dpa_helpers.go (84%) rename tests/e2e/{common.go => lib/kube_helpers.go} (81%) rename tests/e2e/{ => lib}/plugins_helpers.go (90%) rename tests/e2e/{ => lib}/registry_helpers.go (94%) rename tests/e2e/{ => lib}/restic_helpers.go (89%) rename tests/e2e/{ => lib}/restore.go (86%) rename tests/e2e/{ => lib}/subscription_helpers.go (93%) create mode 100644 tests/e2e/utils/common_utils.go diff --git a/.gitignore b/.gitignore index 7ae2092bcab..b973e853e0a 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/tests/e2e/backup_restore_suite_test.go b/tests/e2e/backup_restore_suite_test.go index 0f8e9d9e827..6e7cde5fd24 100755 --- a/tests/e2e/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,26 +74,22 @@ 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 clusterProfile == "aws" { - log.Printf("Creating VolumeSnapshot for CSI backuprestore of %s", brCase.Name) - 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.") - } + if brCase.BackupRestoreType == CSI { + log.Printf("Creating VolumeSnapshot for CSI backuprestore of %s", brCase.Name) + err = InstallApplication(dpaCR.Client, "./sample-applications/gp2-csi/volumeSnapshotClass.yaml") + Expect(err).ToNot(HaveOccurred()) } 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 +101,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 +113,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 +156,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 +173,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 +181,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 +198,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/dpa_deployment_suite_test.go b/tests/e2e/dpa_deployment_suite_test.go index 491ff020880..ed27ac0b66d 100644 --- a/tests/e2e/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 3bf6b8676ee..0facd7d3517 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/apps.go b/tests/e2e/lib/apps.go similarity index 72% rename from tests/e2e/apps.go rename to tests/e2e/lib/apps.go index ab4508a6241..01d00d9d57f 100755 --- a/tests/e2e/apps.go +++ b/tests/e2e/lib/apps.go @@ -1,4 +1,4 @@ -package e2e +package lib import ( "context" @@ -8,9 +8,8 @@ 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" + 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" @@ -20,7 +19,7 @@ import ( "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 +42,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 +54,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 +77,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 +130,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{ @@ -152,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/backup.go b/tests/e2e/lib/backup.go similarity index 86% rename from tests/e2e/backup.go rename to tests/e2e/lib/backup.go index e62d952350f..2f6e5a4b26c 100755 --- a/tests/e2e/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/dpa_helpers.go b/tests/e2e/lib/dpa_helpers.go similarity index 84% rename from tests/e2e/dpa_helpers.go rename to tests/e2e/lib/dpa_helpers.go index 03547dc4d7b..13325879a83 100755 --- a/tests/e2e/dpa_helpers.go +++ b/tests/e2e/lib/dpa_helpers.go @@ -1,4 +1,4 @@ -package e2e +package lib import ( "bytes" @@ -13,6 +13,8 @@ import ( "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 +33,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 +46,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 +76,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 +86,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 +97,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 +111,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 +127,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 +146,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 +158,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 +173,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 +190,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 +208,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 +240,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 +256,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 +276,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 +293,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 +310,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 +327,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 +347,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 +366,24 @@ 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 } } diff --git a/tests/e2e/common.go b/tests/e2e/lib/kube_helpers.go similarity index 81% rename from tests/e2e/common.go rename to tests/e2e/lib/kube_helpers.go index cb204998659..2f69a0306b9 100755 --- a/tests/e2e/common.go +++ b/tests/e2e/lib/kube_helpers.go @@ -1,9 +1,8 @@ -package e2e +package lib import ( "context" "encoding/json" - "io/ioutil" "log" corev1 "k8s.io/api/core/v1" @@ -16,25 +15,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 +43,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 +53,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 +129,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 +142,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 +164,7 @@ 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 { +func CreateCredentialsSecret(data []byte, namespace string, credSecretRef string) error { clientset, err := setUpClient() if err != nil { return err @@ -202,7 +190,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 diff --git a/tests/e2e/plugins_helpers.go b/tests/e2e/lib/plugins_helpers.go similarity index 90% rename from tests/e2e/plugins_helpers.go rename to tests/e2e/lib/plugins_helpers.go index 85341169a08..23701cdc012 100755 --- a/tests/e2e/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/registry_helpers.go b/tests/e2e/lib/registry_helpers.go similarity index 94% rename from tests/e2e/registry_helpers.go rename to tests/e2e/lib/registry_helpers.go index 364b18b6f02..0a2c673b2fa 100755 --- a/tests/e2e/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/restic_helpers.go b/tests/e2e/lib/restic_helpers.go similarity index 89% rename from tests/e2e/restic_helpers.go rename to tests/e2e/lib/restic_helpers.go index 9a552577ede..1c5967f20d4 100755 --- a/tests/e2e/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/restore.go b/tests/e2e/lib/restore.go similarity index 86% rename from tests/e2e/restore.go rename to tests/e2e/lib/restore.go index aa69e92d60f..fcaba86cc78 100755 --- a/tests/e2e/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/subscription_helpers.go b/tests/e2e/lib/subscription_helpers.go similarity index 93% rename from tests/e2e/subscription_helpers.go rename to tests/e2e/lib/subscription_helpers.go index 0b669c04412..e9673e9532d 100644 --- a/tests/e2e/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/subscription_suite_test.go b/tests/e2e/subscription_suite_test.go index bd85dffdfe1..f0a619e2ee1 100644 --- a/tests/e2e/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/utils/common_utils.go b/tests/e2e/utils/common_utils.go new file mode 100644 index 00000000000..d60e1f9ba03 --- /dev/null +++ b/tests/e2e/utils/common_utils.go @@ -0,0 +1,16 @@ +package utils + +import ( + "io/ioutil" +) + +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 +} From 1212d1c04e71035f950457fc8fd409d5cf5740e6 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Mon, 14 Feb 2022 09:30:58 -0500 Subject: [PATCH 02/10] Multi cloud E2E Updates (#568) * Adding changes from ci-multi-cloud branch * Updating flags in makefile * Updating flags in makefile * Updating flags in makefile * Update defaults * Fix helpers * Cleaning up makefile * Update makefile * Update kustomization * Cleaning up Makefile * Adding changes for AWS CredentialFile * Handling no default backuplocations * Removing comments * Adding config check in helpers * Fix AWS Test case * Fix basic review comments --- Makefile | 69 +++++- controllers/bsl.go | 2 +- controllers/registry.go | 45 +++- pkg/credentials/credentials.go | 49 ++++ tests/e2e/backup_restore_suite_test.go | 2 +- tests/e2e/dpa_deployment_suite_test.go | 318 ++++++++++--------------- tests/e2e/e2e_suite_test.go | 76 +++++- tests/e2e/lib/dpa_helpers.go | 81 +++++++ tests/e2e/lib/kube_helpers.go | 40 +++- tests/e2e/scripts/aws_settings.sh | 40 ++-- tests/e2e/scripts/azure_setting.sh | 49 ++++ tests/e2e/scripts/gcp_settings.sh | 43 ++++ tests/e2e/subscription_suite_test.go | 2 +- tests/e2e/utils/common_utils.go | 23 ++ 14 files changed, 587 insertions(+), 252 deletions(-) create mode 100644 tests/e2e/scripts/azure_setting.sh create mode 100644 tests/e2e/scripts/gcp_settings.sh diff --git a/Makefile b/Makefile index a8ad66dc3cc..6f4dd1c3989 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,48 @@ OADP_TEST_NAMESPACE ?= openshift-adp -REGION ?= us-east-1 -PROVIDER ?= aws -CLUSTER_PROFILE ?= aws +CLUSTER_TYPE ?= aws + +# CONFIGS FOR CLOUD +# bsl / blob storage cred dir +OADP_CRED_DIR ?= /var/run/oadp-credentials +# vsl / volume/cluster cred dir +CLUSTER_PROFILE_DIR ?= /Users/drajds/.aws + +# bsl cred file +OADP_CRED_FILE ?= ${OADP_CRED_DIR}/new-aws-credentials +# vsl cred file +CI_CRED_FILE ?= ${CLUSTER_PROFILE_DIR}/.awscred + +# aws configs - default +BSL_REGION ?= us-east-1 +VSL_REGION ?= ${LEASED_RESOURCE} +# BSL_AWS_PROFILE ?= default +BSL_AWS_PROFILE ?= migration-engineering + +# vsl secret CREDS_SECRET_REF ?= cloud-credentials -OADP_AWS_CRED_FILE ?= /var/run/oadp-credentials/aws-credentials -OADP_S3_BUCKET ?= /var/run/oadp-credentials/velero-bucket-name +# bucket file +OADP_BUCKET_FILE ?= ${OADP_CRED_DIR}/new-velero-bucket-name +# azure cluster resource file - only in CI +AZURE_RESOURCE_FILE ?= /var/run/secrets/ci.openshift.io/multi-stage/metadata.json + +# Misc +OPENSHIFT_CI ?= true VELERO_INSTANCE_NAME ?= velero-sample E2E_TIMEOUT_MULTIPLIER ?= 1 +ifeq ($(CLUSTER_TYPE), gcp) + CI_CRED_FILE = ${CLUSTER_PROFILE_DIR}/gce.json + OADP_CRED_FILE = ${OADP_CRED_DIR}/gcp-credentials + CREDS_SECRET_REF = cloud-credentials-gcp + OADP_BUCKET_FILE = ${OADP_CRED_DIR}/gcp-velero-bucket-name +else ifeq ($(CLUSTER_TYPE), azure4) + CLUSTER_TYPE = azure + CI_CRED_FILE = ${CLUSTER_PROFILE_DIR}/osServicePrincipal.json + OADP_CRED_FILE = ${OADP_CRED_DIR}/azure-credentials + CREDS_SECRET_REF = cloud-credentials-azure + OADP_BUCKET_FILE = ${OADP_CRED_DIR}/azure-velero-bucket-name +endif + # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.21 @@ -290,16 +325,28 @@ catalog-build: opm ## Build a catalog image. catalog-push: ## Push a catalog image. $(MAKE) docker-push IMG=$(CATALOG_IMG) -S3_BUCKET := $(shell cat $(OADP_S3_BUCKET) | awk '/velero-bucket-name/ {gsub(/"/, "", $$2);gsub(/}/,""); print $$2}') +OADP_BUCKET := $(shell cat $(OADP_BUCKET_FILE)) +TEST_FILTER := $(shell echo '! aws && ! gcp && ! azure' | sed -r "s/[&]* [!] $(CLUSTER_TYPE)|[!] $(CLUSTER_TYPE) [&]*//") SETTINGS_TMP=/tmp/test-settings -test-e2e: + +test-e2e-setup: mkdir -p $(SETTINGS_TMP) - PROVIDER="$(PROVIDER)" BUCKET="$(S3_BUCKET)" REGION="$(REGION)" SECRET="$(CREDS_SECRET_REF)" TMP_DIR=$(SETTINGS_TMP) /bin/bash tests/e2e/scripts/aws_settings.sh - ginkgo -mod=mod tests/e2e/ -- -cloud=$(OADP_AWS_CRED_FILE) \ + PROVIDER="$(CLUSTER_TYPE)" BUCKET="$(OADP_BUCKET)" BSL_REGION="$(BSL_REGION)" SECRET="$(CREDS_SECRET_REF)" TMP_DIR=$(SETTINGS_TMP) \ + VSL_REGION="$(VSL_REGION)" BSL_AWS_PROFILE="$(BSL_AWS_PROFILE)" BSL_REGION="$(BSL_REGION)" /bin/bash "tests/e2e/scripts/$(CLUSTER_TYPE)_settings.sh" + +test-e2e: test-e2e-setup + ginkgo run -mod=mod tests/e2e/ -- -credentials=$(OADP_CRED_FILE) \ -velero_namespace=$(OADP_TEST_NAMESPACE) \ - -settings=$(SETTINGS_TMP)/awscreds \ + -settings=$(SETTINGS_TMP)/oadpcreds \ -velero_instance_name=$(VELERO_INSTANCE_NAME) \ -timeout_multiplier=$(E2E_TIMEOUT_MULTIPLIER) \ - -cluster_profile=$(CLUSTER_PROFILE) + -cluster_profile=$(CLUSTER_TYPE) \ + --ginkgo.label-filter="$(TEST_FILTER)" \ + -openshift_ci=$(OPENSHIFT_CI) \ + -ci_cred_file=$(CI_CRED_FILE) \ + -azure_resource_file=$(AZURE_RESOURCE_FILE) \ + -provider=$(CLUSTER_TYPE) \ + -creds_secret_ref=$(CREDS_SECRET_REF) + test-e2e-cleanup: rm -rf $(SETTINGS_TMP) diff --git a/controllers/bsl.go b/controllers/bsl.go index fb1b92b9cc7..05b0c69d2f4 100644 --- a/controllers/bsl.go +++ b/controllers/bsl.go @@ -302,7 +302,7 @@ func (r *DPAReconciler) validateProviderPluginAndSecret(bslSpec velerov1.BackupS r.Log.Info(fmt.Sprintf("%s backupstoragelocation is configured but velero plugin for %s is not present", bslSpec.Provider, bslSpec.Provider)) //TODO: set warning condition on Velero CR } - secretName, _ := r.getSecretNameAndKey(bslSpec.Credential, oadpv1alpha1.DefaultPlugin(bslSpec.Provider)) + secretName, _ := r.getSecretNameAndKey(&bslSpec, oadpv1alpha1.DefaultPlugin(bslSpec.Provider)) _, err := r.getProviderSecret(secretName) diff --git a/controllers/registry.go b/controllers/registry.go index 9491806f493..db66b4fe191 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -283,16 +283,29 @@ func (r *DPAReconciler) buildRegistryDeployment(registryDeployment *appsv1.Deplo }, } - // attach gcp secret volume if provider is gcp - if bsl.Spec.Provider == GCPProvider { - // check for secret name - secretName, _ := r.getSecretNameAndKey(bsl.Spec.Credential, oadpv1alpha1.DefaultPluginGCP) + // attach secret volume for cloud providers + if _, ok := bsl.Spec.Config["credentialsFile"]; ok { + if cloudProviderMap, bslCredOk := credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)]; bslCredOk { + registryDeployment.Spec.Template.Spec.Volumes = append( + registryDeployment.Spec.Template.Spec.Volumes, + corev1.Volume{ + Name: cloudProviderMap.SecretName, + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: cloudProviderMap.BslSecretName, + }, + }, + }, + ) + } + } else if bsl.Spec.Provider == GCPProvider { + cloudProviderMap := credentials.PluginSpecificFields[oadpv1alpha1.DefaultPluginGCP] registryDeployment.Spec.Template.Spec.Volumes = []corev1.Volume{ { - Name: secretName, + Name: cloudProviderMap.SecretName, VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: secretName, + SecretName: cloudProviderMap.SecretName, }, }, }, @@ -375,7 +388,7 @@ func (r *DPAReconciler) buildRegistryContainer(bsl *velerov1.BackupStorageLocati // append secret volumes if the BSL provider is GCP if bsl.Spec.Provider == GCPProvider { // check for secret name - secretName, _ := r.getSecretNameAndKey(bsl.Spec.Credential, oadpv1alpha1.DefaultPluginGCP) + secretName, _ := r.getSecretNameAndKey(&bsl.Spec, oadpv1alpha1.DefaultPluginGCP) containers[0].VolumeMounts = []corev1.VolumeMount{ { Name: secretName, @@ -512,7 +525,7 @@ func (r *DPAReconciler) getGCPRegistryEnvVars(bsl *velerov1.BackupStorageLocatio if gcpEnvVars[i].Name == RegistryStorageGCSKeyfile { // check for secret key - _, secretKey := r.getSecretNameAndKey(bsl.Spec.Credential, oadpv1alpha1.DefaultPluginGCP) + _, secretKey := r.getSecretNameAndKey(&bsl.Spec, oadpv1alpha1.DefaultPluginGCP) gcpEnvVars[i].Value = credentials.PluginSpecificFields[oadpv1alpha1.DefaultPluginGCP].MountPath + "/" + secretKey } } @@ -542,18 +555,24 @@ func (r *DPAReconciler) getSecretNameAndKeyforBackupLocation(bslspec oadpv1alpha } } if bslspec.Velero != nil { - return r.getSecretNameAndKey(bslspec.Velero.Credential, oadpv1alpha1.DefaultPlugin(bslspec.Velero.Provider)) + return r.getSecretNameAndKey(bslspec.Velero, oadpv1alpha1.DefaultPlugin(bslspec.Velero.Provider)) } return "", "" } -func (r *DPAReconciler) getSecretNameAndKey(credential *corev1.SecretKeySelector, plugin oadpv1alpha1.DefaultPlugin) (string, string) { +func (r *DPAReconciler) getSecretNameAndKey(bslSpec *velerov1.BackupStorageLocationSpec, plugin oadpv1alpha1.DefaultPlugin) (string, string) { // Assume default values unless user has overriden them secretName := credentials.PluginSpecificFields[plugin].SecretName secretKey := credentials.PluginSpecificFields[plugin].PluginSecretKey - + if _, ok := bslSpec.Config["credentialsFile"]; ok { + secretName = credentials.PluginSpecificFields[plugin].BslSecretName + secretKey = credentials.PluginSpecificFields[plugin].PluginSecretKey + } + r.Log.Info(fmt.Sprintf("secret: %s", secretName)) + r.Log.Info(fmt.Sprintf("key: %s", secretKey)) // check if user specified the Credential Name and Key + credential := bslSpec.Credential if credential != nil { if len(credential.Name) > 0 { secretName = credential.Name @@ -1148,7 +1167,7 @@ func (r *DPAReconciler) updateRegistrySecret(secret *corev1.Secret, bsl *velerov func (r *DPAReconciler) populateAWSRegistrySecret(bsl *velerov1.BackupStorageLocation, registrySecret *corev1.Secret) error { // Check for secret name - secretName, secretKey := r.getSecretNameAndKey(bsl.Spec.Credential, oadpv1alpha1.DefaultPluginAWS) + secretName, secretKey := r.getSecretNameAndKey(&bsl.Spec, oadpv1alpha1.DefaultPluginAWS) // fetch secret and error secret, err := r.getProviderSecret(secretName) @@ -1177,7 +1196,7 @@ func (r *DPAReconciler) populateAWSRegistrySecret(bsl *velerov1.BackupStorageLoc func (r *DPAReconciler) populateAzureRegistrySecret(bsl *velerov1.BackupStorageLocation, registrySecret *corev1.Secret) error { // Check for secret name - secretName, secretKey := r.getSecretNameAndKey(bsl.Spec.Credential, oadpv1alpha1.DefaultPluginMicrosoftAzure) + secretName, secretKey := r.getSecretNameAndKey(&bsl.Spec, oadpv1alpha1.DefaultPluginMicrosoftAzure) r.Log.Info(fmt.Sprintf("Azure secret name: %s and secret key: %s", secretName, secretKey)) // fetch secret and error diff --git a/pkg/credentials/credentials.go b/pkg/credentials/credentials.go index 992ad5aa756..2e108cbcb88 100644 --- a/pkg/credentials/credentials.go +++ b/pkg/credentials/credentials.go @@ -15,6 +15,8 @@ type DefaultPluginFields struct { IsCloudProvider bool SecretName string MountPath string + BslSecretName string + BSlMountPath string EnvCredentialsFile string PluginImage string PluginSecretKey string @@ -31,6 +33,8 @@ var ( IsCloudProvider: true, SecretName: "cloud-credentials", MountPath: "/credentials", + BslSecretName: "bsl-cloud-credentials-aws", + BSlMountPath: "/bsl-cloud-credentials-aws", EnvCredentialsFile: common.AWSSharedCredentialsFileEnvKey, PluginName: common.VeleroPluginForAWS, PluginSecretKey: "cloud", @@ -39,6 +43,8 @@ var ( IsCloudProvider: true, SecretName: "cloud-credentials-gcp", MountPath: "/credentials-gcp", + BslSecretName: "bsl-cloud-credentials-gcp", + BSlMountPath: "/bsl-cloud-credentials-gcp", EnvCredentialsFile: common.GCPCredentialsEnvKey, PluginName: common.VeleroPluginForGCP, PluginSecretKey: "cloud", @@ -47,6 +53,8 @@ var ( IsCloudProvider: true, SecretName: "cloud-credentials-azure", MountPath: "/credentials-azure", + BslSecretName: "bsl-cloud-credentials-azure", + BSlMountPath: "/bsl-cloud-credentials-azure", EnvCredentialsFile: common.AzureCredentialsFileEnvKey, PluginName: common.VeleroPluginForAzure, PluginSecretKey: "cloud", @@ -215,6 +223,23 @@ func AppendCloudProviderVolumes(dpa *oadpv1alpha1.DataProtectionApplication, ds } } + for _, bslSpec := range dpa.Spec.BackupLocations { + if _, ok := bslSpec.Velero.Config["credentialsFile"]; ok { + if cloudProviderMap, bslCredOk := PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bslSpec.Velero.Provider)]; bslCredOk { + ds.Spec.Template.Spec.Volumes = append( + ds.Spec.Template.Spec.Volumes, + corev1.Volume{ + Name: cloudProviderMap.BslSecretName, + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: cloudProviderMap.BslSecretName, + }, + }, + }, + ) + } + } + } return nil } @@ -280,6 +305,30 @@ func AppendPluginSpecificSpecs(dpa *oadpv1alpha1.DataProtectionApplication, vele }, }) + // append bsl volume secret + for _, bslSpec := range dpa.Spec.BackupLocations { + if _, ok := bslSpec.Velero.Config["credentialsFile"]; ok { + if cloudProviderMap, bslCredOk := PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bslSpec.Velero.Provider)]; bslCredOk { + veleroContainer.VolumeMounts = append( + veleroContainer.VolumeMounts, + corev1.VolumeMount{ + Name: cloudProviderMap.BslSecretName, + MountPath: pluginSpecificMap.BSlMountPath, + }) + veleroDeployment.Spec.Template.Spec.Volumes = append( + veleroDeployment.Spec.Template.Spec.Volumes, + corev1.Volume{ + Name: cloudProviderMap.BslSecretName, + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: cloudProviderMap.BslSecretName, + }, + }, + }, + ) + } + } + } } } // append custom plugin init containers diff --git a/tests/e2e/backup_restore_suite_test.go b/tests/e2e/backup_restore_suite_test.go index 6e7cde5fd24..19d75c34c50 100755 --- a/tests/e2e/backup_restore_suite_test.go +++ b/tests/e2e/backup_restore_suite_test.go @@ -23,7 +23,7 @@ var _ = Describe("AWS backup restore tests", func() { testSuiteInstanceName := "ts-" + instanceName dpaCR.Name = testSuiteInstanceName - credData, err := utils.ReadFile(cloud) + credData, err := utils.ReadFile(credFile) Expect(err).NotTo(HaveOccurred()) err = CreateCredentialsSecret(credData, namespace, GetSecretRef(credSecretRef)) Expect(err).NotTo(HaveOccurred()) diff --git a/tests/e2e/dpa_deployment_suite_test.go b/tests/e2e/dpa_deployment_suite_test.go index ed27ac0b66d..495144847b1 100644 --- a/tests/e2e/dpa_deployment_suite_test.go +++ b/tests/e2e/dpa_deployment_suite_test.go @@ -30,98 +30,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { WantError bool } - DescribeTable("Updating custom resource with new configuration", - - func(installCase InstallCase, expectedErr error) { - //TODO: Calling dpaCR.build() is the old pattern. - //Change it later to make sure all the spec values are passed for every test case, - // instead of assigning the values in advance to the DPA CR - err := dpaCR.Build(installCase.BRestoreType) - Expect(err).NotTo(HaveOccurred()) - err = dpaCR.CreateOrUpdate(installCase.DpaSpec) - Expect(err).ToNot(HaveOccurred()) - if installCase.WantError { - // Eventually() - log.Printf("Test case expected to error. Waiting for the error to show in DPA Status") - Eventually(dpaCR.GetNoErr().Status.Conditions[0].Type, timeoutMultiplier*time.Minute*3, time.Second*5).Should(Equal("Reconciled")) - Eventually(dpaCR.GetNoErr().Status.Conditions[0].Status, timeoutMultiplier*time.Minute*3, time.Second*5).Should(Equal(metav1.ConditionFalse)) - Eventually(dpaCR.GetNoErr().Status.Conditions[0].Reason, timeoutMultiplier*time.Minute*3, time.Second*5).Should(Equal("Error")) - Eventually(dpaCR.GetNoErr().Status.Conditions[0].Message, timeoutMultiplier*time.Minute*3, time.Second*5).Should(Equal(expectedErr.Error())) - return - } - log.Printf("Waiting for velero pod to be running") - 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()) - } - } - 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()) - } - } - - // 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()) - } - - // 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()) - } - - 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()) - } - - //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()) - } else { - log.Printf("Waiting for restic daemonset to be deleted") - 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()) - } - } - - // check customplugins - log.Printf("Waiting for velero deployment to have expected custom plugins") - 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()) - } - } - - 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()) - } - } - 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()) - } - - }, + genericTests := []TableEntry{ Entry("Default velero CR", InstallCase{ Name: "default-cr", BRestoreType: RESTIC, @@ -309,100 +218,6 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, WantError: false, }, nil), - /*Entry("DPA CR with bsl and multiple vsl", InstallCase{ - Name: "default-cr-bsl-vsl", - BRestoreType: restic, - DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ - Configuration: &oadpv1alpha1.ApplicationConfig{ - Velero: &oadpv1alpha1.VeleroConfig{ - PodConfig: &oadpv1alpha1.PodConfig{}, - DefaultPlugins: []oadpv1alpha1.DefaultPlugin{ - oadpv1alpha1.DefaultPluginOpenShift, - oadpv1alpha1.DefaultPluginAWS, - }, - }, - Restic: &oadpv1alpha1.ResticConfig{ - PodConfig: &oadpv1alpha1.PodConfig{}, - Enable: pointer.Bool(true), - }, - }, - SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ - { - Velero: &velero.VolumeSnapshotLocationSpec{ - Provider: "aws", - Config: map[string]string{ - "region": "us-east-1", - }, - }, - }, - { - Velero: &velero.VolumeSnapshotLocationSpec{ - Provider: "aws", - Config: map[string]string{ - "region": "us-east-2", - }, - }, - }, - }, - BackupLocations: []oadpv1alpha1.BackupLocation{ - { - Velero: &velero.BackupStorageLocationSpec{ - Provider: provider, - Config: map[string]string{ - "region": region, - }, - Default: true, - StorageType: velero.StorageType{ - ObjectStorage: &velero.ObjectStorageLocation{ - Bucket: s3Bucket, - Prefix: veleroPrefix, - }, - }, - }, - }, - }, - }, - WantError: false, - }, nil),*/ - /*Entry("DPA CR with no bsl and multiple vsl", InstallCase{ - Name: "default-cr-multiple-vsl", - BRestoreType: restic, - DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ - Configuration: &oadpv1alpha1.ApplicationConfig{ - Velero: &oadpv1alpha1.VeleroConfig{ - PodConfig: &oadpv1alpha1.PodConfig{}, - DefaultPlugins: []oadpv1alpha1.DefaultPlugin{ - oadpv1alpha1.DefaultPluginOpenShift, - oadpv1alpha1.DefaultPluginAWS, - }, - NoDefaultBackupLocation: true, - }, - Restic: &oadpv1alpha1.ResticConfig{ - PodConfig: &oadpv1alpha1.PodConfig{}, - Enable: pointer.Bool(true), - }, - }, - SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ - { - Velero: &velero.VolumeSnapshotLocationSpec{ - Provider: "aws", - Config: map[string]string{ - "region": "us-east-1", - }, - }, - }, - { - Velero: &velero.VolumeSnapshotLocationSpec{ - Provider: "aws", - Config: map[string]string{ - "region": "us-east-2", - }, - }, - }, - }, - }, - WantError: false, - }, nil),*/ Entry("Default velero CR with restic disabled", InstallCase{ Name: "default-cr-no-restic", BRestoreType: RESTIC, @@ -564,6 +379,9 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, WantError: false, }, nil), + } + + awsTests := []TableEntry{ Entry("AWS Without Region No S3ForcePathStyle with BackupImages false should succeed", InstallCase{ Name: "default-no-region-no-s3forcepathstyle", BRestoreType: RESTIC, @@ -606,6 +424,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { Config: map[string]string{ "region": bslConfig["region"], "s3ForcePathStyle": "true", + "profile": bslConfig["profile"], }, Default: true, StorageType: velero.StorageType{ @@ -662,5 +481,132 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, WantError: true, }, fmt.Errorf("region for AWS backupstoragelocation cannot be empty when s3ForcePathStyle is true or when backing up images")), + } + + if provider == "aws" { + genericTests = append(genericTests, awsTests...) + } + DescribeTable("Updating custom resource with new configuration", + + func(installCase InstallCase, expectedErr error) { + //TODO: Calling dpaCR.build() is the old pattern. + //Change it later to make sure all the spec values are passed for every test case, + // instead of assigning the values in advance to the DPA CR + err := dpaCR.Build(installCase.BRestoreType) + Expect(err).NotTo(HaveOccurred()) + if len(installCase.DpaSpec.BackupLocations) > 0 { + switch dpaCR.Provider { + case "aws": + if installCase.DpaSpec.BackupLocations[0].Velero.Config != nil { + installCase.DpaSpec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-aws/cloud" + } + case "gcp": + if installCase.DpaSpec.BackupLocations[0].Velero.Config != nil { + installCase.DpaSpec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-gcp/cloud" + } + case "azure": + installCase.DpaSpec.BackupLocations[0].Velero.Config = map[string]string{ + "credentialsFile": "bsl-cloud-credentials-azure/cloud", + "subscriptionId": dpaCR.DpaAzureConfig.BslSubscriptionId, + "storageAccount": dpaCR.DpaAzureConfig.BslStorageAccount, + "resourceGroup": dpaCR.DpaAzureConfig.BslResourceGroup, + "storageAccountKeyEnvVar": dpaCR.DpaAzureConfig.BslStorageAccountKeyEnvVar, + } + installCase.DpaSpec.SnapshotLocations = []oadpv1alpha1.SnapshotLocation{ + { + Velero: &velero.VolumeSnapshotLocationSpec{ + Provider: dpaCR.Provider, + Config: map[string]string{ + "subscriptionId": dpaCR.DpaAzureConfig.VslSubscriptionId, + }, + }, + }, + } + } + } + err = dpaCR.CreateOrUpdate(installCase.DpaSpec) + Expect(err).ToNot(HaveOccurred()) + if installCase.WantError { + // Eventually() + log.Printf("Test case expected to error. Waiting for the error to show in DPA Status") + Eventually(dpaCR.GetNoErr().Status.Conditions[0].Type, timeoutMultiplier*time.Minute*3, time.Second*5).Should(Equal("Reconciled")) + Eventually(dpaCR.GetNoErr().Status.Conditions[0].Status, timeoutMultiplier*time.Minute*3, time.Second*5).Should(Equal(metav1.ConditionFalse)) + Eventually(dpaCR.GetNoErr().Status.Conditions[0].Reason, timeoutMultiplier*time.Minute*3, time.Second*5).Should(Equal("Error")) + Eventually(dpaCR.GetNoErr().Status.Conditions[0].Message, timeoutMultiplier*time.Minute*3, time.Second*5).Should(Equal(expectedErr.Error())) + return + } + log.Printf("Waiting for velero pod to be running") + 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()) + } + } + 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()) + } + } + + // 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()) + } + + // 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()) + } + + 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()) + } + + //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()) + } else { + log.Printf("Waiting for restic daemonset to be deleted") + 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()) + } + } + + // check customplugins + log.Printf("Waiting for velero deployment to have expected custom plugins") + 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()) + } + } + + 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()) + } + } + 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()) + } + + }, genericTests, ) }) diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index 0facd7d3517..981435ec6a8 100755 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -3,27 +3,33 @@ package e2e_test import ( "errors" "flag" + "fmt" "log" + "strconv" "testing" "time" . "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" + "github.com/openshift/oadp-operator/tests/e2e/utils" ) // Common vars obtained from flags passed in ginkgo. -var namespace, instanceName, settings, cloud, clusterProfile, credSecretRef string +var credFile, namespace, credSecretRef, instanceName, provider, azure_resource_file, openshift_ci, ci_cred_file, settings, bsl_profile string var timeoutMultiplier time.Duration func init() { - flag.StringVar(&cloud, "cloud", "", "Cloud Credentials file path location") + flag.StringVar(&credFile, "credentials", "", "Cloud Credentials file path location") flag.StringVar(&namespace, "velero_namespace", "velero", "Velero Namespace") flag.StringVar(&settings, "settings", "./templates/default_settings.json", "Settings of the velero instance") flag.StringVar(&instanceName, "velero_instance_name", "example-velero", "Velero Instance Name") - flag.StringVar(&clusterProfile, "cluster_profile", "aws", "Cluster profile") + flag.StringVar(&bsl_profile, "cluster_profile", "aws", "Cluster profile") flag.StringVar(&credSecretRef, "creds_secret_ref", "cloud-credentials", "Credential secret ref for backup storage location") + flag.StringVar(&provider, "provider", "aws", "BSL provider") + flag.StringVar(&azure_resource_file, "azure_resource_file", "azure resource file", "Resource Group Dir for azure") + flag.StringVar(&ci_cred_file, "ci_cred_file", credFile, "CI Cloud Cred File") + flag.StringVar(&openshift_ci, "openshift_ci", "false", "ENV for tests") timeoutMultiplierInput := flag.Int64("timeout_multiplier", 1, "Customize timeout multiplier from default (1)") timeoutMultiplier = 1 @@ -53,18 +59,68 @@ var _ = BeforeSuite(func() { Expect(errors.New(errString)).NotTo(HaveOccurred()) } - credData, err := utils.ReadFile(cloud) - Expect(err).NotTo(HaveOccurred()) - err = CreateCredentialsSecret(credData, namespace, GetSecretRef(credSecretRef)) - Expect(err).NotTo(HaveOccurred()) - dpaCR = &DpaCustomResource{ - Namespace: namespace, + Namespace: namespace, + Credentials: credFile, + CredSecretRef: credSecretRef, + Provider: provider, } dpaCR.CustomResource = Dpa testSuiteInstanceName := "ts-" + instanceName dpaCR.Name = testSuiteInstanceName + openshift_ci_bool, _ := strconv.ParseBool(openshift_ci) + dpaCR.OpenshiftCi = openshift_ci_bool + + if openshift_ci_bool == true { + switch dpaCR.Provider { + case "aws": + cloudCredData, err := utils.ReadFile(dpaCR.Credentials) + Expect(err).NotTo(HaveOccurred()) + err = CreateCredentialsSecret(cloudCredData, namespace, "bsl-cloud-credentials-aws") + Expect(err).NotTo(HaveOccurred()) + dpaCR.Credentials = ci_cred_file + case "gcp": + cloudCredData, err := utils.ReadFile(dpaCR.Credentials) + Expect(err).NotTo(HaveOccurred()) + err = CreateCredentialsSecret(cloudCredData, namespace, "bsl-cloud-credentials-gcp") + Expect(err).NotTo(HaveOccurred()) + dpaCR.Credentials = ci_cred_file + case "azure": + cloudCredData, err := utils.GetJsonData(dpaCR.Credentials) // azure credentials need to be in json - can be changed + Expect(err).NotTo(HaveOccurred()) + dpaCR.DpaAzureConfig = DpaAzureConfig{ + BslSubscriptionId: fmt.Sprintf("%v", cloudCredData["subscriptionId"]), + BslResourceGroup: fmt.Sprintf("%v", cloudCredData["resourceGroup"]), + BslStorageAccount: fmt.Sprintf("%v", cloudCredData["storageAccount"]), + BslStorageAccountKeyEnvVar: "AZURE_STORAGE_ACCOUNT_ACCESS_KEY", + VslSubscriptionId: fmt.Sprintf("%v", cloudCredData["subscriptionId"]), + VslResourceGroup: fmt.Sprintf("%v", cloudCredData["resourceGroup"]), + } + // bsl cloud + cloudCreds := GetAzureCreds(cloudCredData) + err = CreateCredentialsSecret(cloudCreds, namespace, "bsl-cloud-credentials-azure") + Expect(err).NotTo(HaveOccurred()) + // ci cloud + ciJsonData, err := utils.GetJsonData(ci_cred_file) + Expect(err).NotTo(HaveOccurred()) + if _, ok := ciJsonData["resourceGroup"]; !ok { + resourceGroup, err := GetAzureResource(azure_resource_file) + Expect(err).NotTo(HaveOccurred()) + ciJsonData["resourceGroup"] = resourceGroup + } + dpaCR.DpaAzureConfig.VslSubscriptionId = fmt.Sprintf("%v", ciJsonData["subscriptionId"]) + dpaCR.DpaAzureConfig.VslResourceGroup = fmt.Sprintf("%v", ciJsonData["resourceGroup"]) + ciCreds := GetAzureCreds(ciJsonData) + dpaCR.Credentials = "/tmp/azure-credentials" + err = utils.WriteFile(dpaCR.Credentials, ciCreds) + Expect(err).NotTo(HaveOccurred()) + } + } + credData, err := utils.ReadFile(dpaCR.Credentials) + Expect(err).NotTo(HaveOccurred()) + err = CreateCredentialsSecret(credData, namespace, credSecretRef) + Expect(err).NotTo(HaveOccurred()) dpaCR.SetClient() Expect(DoesNamespaceExist(namespace)).Should(BeTrue()) }) diff --git a/tests/e2e/lib/dpa_helpers.go b/tests/e2e/lib/dpa_helpers.go index 13325879a83..caa82529cb4 100755 --- a/tests/e2e/lib/dpa_helpers.go +++ b/tests/e2e/lib/dpa_helpers.go @@ -37,6 +37,15 @@ const ( RESTIC BackupRestoreType = "restic" ) +type DpaAzureConfig struct { + VslSubscriptionId string + VslResourceGroup string + BslSubscriptionId string + BslResourceGroup string + BslStorageAccount string + BslStorageAccountKeyEnvVar string +} + type DpaCustomResource struct { Name string Namespace string @@ -44,6 +53,11 @@ type DpaCustomResource struct { backupRestoreType BackupRestoreType CustomResource *oadpv1alpha1.DataProtectionApplication Client client.Client + DpaAzureConfig DpaAzureConfig + Credentials string + CredSecretRef string + Provider string + OpenshiftCi bool } var VeleroPrefix = "velero-e2e-" + string(uuid.NewUUID()) @@ -84,6 +98,73 @@ func (v *DpaCustomResource) Build(backupRestoreType BackupRestoreType) error { }, }, } + switch v.Provider { + case "aws": + if v.OpenshiftCi { + if dpaInstance.Spec.BackupLocations[0].Velero.Config != nil { + dpaInstance.Spec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-aws/cloud" + } + } else { + dpaInstance.Spec.BackupLocations[0].Velero.Credential = &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: v.CredSecretRef, + }, + Key: "cloud", + } + } + case "gcp": + if v.OpenshiftCi { + if dpaInstance.Spec.BackupLocations[0].Velero.Config != nil { + dpaInstance.Spec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-gcp/cloud" + } + } else { + dpaInstance.Spec.BackupLocations[0].Velero.Credential = &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: v.CredSecretRef, + }, + Key: "cloud", + } + } + // dpaInstance.Spec.Configuration.Velero.DefaultPlugins = append(dpaInstance.Spec.Configuration.Velero.DefaultPlugins, oadpv1alpha1.DefaultPluginGCP) + // dpaInstance.Spec.SnapshotLocations = []oadpv1alpha1.SnapshotLocation{ + // { + // Velero: &velero.VolumeSnapshotLocationSpec{ + // Provider: v.Provider, + // Config: map[string]string{ + // "snapshotLocation": v.gcpConfig.VslRegion, + // }, + // }, + // }, + // } + case "azure": + dpaInstance.Spec.BackupLocations[0].Velero.Config = map[string]string{ + "subscriptionId": v.DpaAzureConfig.BslSubscriptionId, + "storageAccount": v.DpaAzureConfig.BslStorageAccount, + "resourceGroup": v.DpaAzureConfig.BslResourceGroup, + "storageAccountKeyEnvVar": v.DpaAzureConfig.BslStorageAccountKeyEnvVar, + } + if v.OpenshiftCi { + dpaInstance.Spec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-azure/cloud" // / + } else { + dpaInstance.Spec.BackupLocations[0].Velero.Credential = &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: v.CredSecretRef, + }, + Key: "cloud", + } + } + dpaInstance.Spec.SnapshotLocations = []oadpv1alpha1.SnapshotLocation{ + { + Velero: &velero.VolumeSnapshotLocationSpec{ + Provider: v.Provider, + Config: map[string]string{ + "subscriptionId": v.DpaAzureConfig.VslSubscriptionId, + "resourceGroup": v.DpaAzureConfig.VslResourceGroup, + }, + }, + }, + } + } v.backupRestoreType = backupRestoreType switch backupRestoreType { case RESTIC: diff --git a/tests/e2e/lib/kube_helpers.go b/tests/e2e/lib/kube_helpers.go index 2f69a0306b9..9f58647a93d 100755 --- a/tests/e2e/lib/kube_helpers.go +++ b/tests/e2e/lib/kube_helpers.go @@ -2,9 +2,10 @@ package lib import ( "context" - "encoding/json" + "fmt" "log" + utils "github.com/openshift/oadp-operator/tests/e2e/utils" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -82,14 +83,6 @@ func setUpClient() (*kubernetes.Clientset, error) { return clientset, nil } -func decodeJson(data []byte) (map[string]interface{}, error) { - // Return JSON from buffer data - var jsonData map[string]interface{} - - err := json.Unmarshal(data, &jsonData) - return jsonData, err -} - // FIXME: Remove func createOADPTestNamespace(namespace string) error { // default OADP Namespace @@ -217,3 +210,32 @@ func isCredentialsSecretDeleted(namespace string, credSecretRef string) wait.Con return false, err } } + +func GetAzureCreds(ciCred map[string]interface{}) []byte { + azureCreds := string("AZURE_CLOUD_NAME=AzurePublicCloud") + + for k, v := range ciCred { + switch k { + case "subscriptionId": + azureCreds += "\n" + "AZURE_SUBSCRIPTION_ID=" + fmt.Sprintf("%v", v) + case "clientId": + azureCreds += "\n" + "AZURE_CLIENT_ID=" + fmt.Sprintf("%v", v) + case "clientSecret": + azureCreds += "\n" + "AZURE_CLIENT_SECRET=" + fmt.Sprintf("%v", v) + case "tenantId": + azureCreds += "\n" + "AZURE_TENANT_ID=" + fmt.Sprintf("%v", v) + case "storageAccountAccessKey": + azureCreds += "\n" + "AZURE_STORAGE_ACCOUNT_ACCESS_KEY=" + fmt.Sprintf("%v", v) + case "resourceGroup": + azureCreds += "\n" + "AZURE_RESOURCE_GROUP=" + fmt.Sprintf("%v", v) + } + } + + return []byte(azureCreds) +} + +func GetAzureResource(path string) (string, error) { + azure_config, err := utils.GetJsonData(path) + resourceGroup := fmt.Sprintf("%v", azure_config["infraID"]) + "-rg" + return resourceGroup, err +} diff --git a/tests/e2e/scripts/aws_settings.sh b/tests/e2e/scripts/aws_settings.sh index 5182e1b9c54..f8101f767b4 100644 --- a/tests/e2e/scripts/aws_settings.sh +++ b/tests/e2e/scripts/aws_settings.sh @@ -1,6 +1,6 @@ #!/bin/bash -cat > $TMP_DIR/awscreds < $TMP_DIR/oadpcreds < $TMP_DIR/awscreds < $TMP_DIR/awscreds +x=$(cat $TMP_DIR/oadpcreds); echo "$x" | grep -o '^[^#]*' > $TMP_DIR/oadpcreds diff --git a/tests/e2e/scripts/azure_setting.sh b/tests/e2e/scripts/azure_setting.sh new file mode 100644 index 00000000000..e7436fb0817 --- /dev/null +++ b/tests/e2e/scripts/azure_setting.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +cat > $TMP_DIR/oadpcreds < $TMP_DIR/oadpcreds diff --git a/tests/e2e/scripts/gcp_settings.sh b/tests/e2e/scripts/gcp_settings.sh new file mode 100644 index 00000000000..de55c824053 --- /dev/null +++ b/tests/e2e/scripts/gcp_settings.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +cat > $TMP_DIR/oadpcreds < $TMP_DIR/oadpcreds diff --git a/tests/e2e/subscription_suite_test.go b/tests/e2e/subscription_suite_test.go index f0a619e2ee1..4449bd00850 100644 --- a/tests/e2e/subscription_suite_test.go +++ b/tests/e2e/subscription_suite_test.go @@ -31,7 +31,7 @@ var _ = Describe("Subscription Config Suite Test", func() { testSuiteInstanceName := "ts-" + instanceName dpaCR.Name = testSuiteInstanceName - credData, err := utils.ReadFile(cloud) + credData, err := utils.ReadFile(credFile) Expect(err).NotTo(HaveOccurred()) err = CreateCredentialsSecret(credData, namespace, GetSecretRef(credSecretRef)) diff --git a/tests/e2e/utils/common_utils.go b/tests/e2e/utils/common_utils.go index d60e1f9ba03..3d67d58c9be 100644 --- a/tests/e2e/utils/common_utils.go +++ b/tests/e2e/utils/common_utils.go @@ -1,6 +1,7 @@ package utils import ( + "encoding/json" "io/ioutil" ) @@ -14,3 +15,25 @@ func ReadFile(path string) ([]byte, error) { file, err := ioutil.ReadFile(path) return file, err } + +func decodeJson(data []byte) (map[string]interface{}, error) { + // Return JSON from buffer data + var jsonData map[string]interface{} + + err := json.Unmarshal(data, &jsonData) + return jsonData, err +} + +func GetJsonData(path string) (map[string]interface{}, error) { + // Return buffer data for json + jsonData, err := ioutil.ReadFile(path) + if err != nil { + return nil, err + } + return decodeJson(jsonData) +} + +func WriteFile(credFile string, data []byte) error { + err := ioutil.WriteFile(credFile, data, 0644) + return err +} From 69ee1eda2506cde45948754367e1148f3f42486f Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Mon, 9 May 2022 13:30:40 -0400 Subject: [PATCH 03/10] genericTests... --- tests/e2e/dpa_deployment_suite_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/dpa_deployment_suite_test.go b/tests/e2e/dpa_deployment_suite_test.go index 495144847b1..6918067a975 100644 --- a/tests/e2e/dpa_deployment_suite_test.go +++ b/tests/e2e/dpa_deployment_suite_test.go @@ -607,6 +607,6 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { Eventually(AreRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } - }, genericTests, + }, genericTests..., ) }) From 1d39a95565a2d525f91c082e8094150dfb65dcc6 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Thu, 14 Apr 2022 09:32:38 -0400 Subject: [PATCH 04/10] Changing Credentials Mount Name for BSL when CredentialsFile key is used in Config - Fixes CI (#637) * Changing Credentials Mount Name for BSL for GCP * Fix DefaultPlugin for credentialsFile --- controllers/registry.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/controllers/registry.go b/controllers/registry.go index db66b4fe191..e992f5b1299 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -289,7 +289,7 @@ func (r *DPAReconciler) buildRegistryDeployment(registryDeployment *appsv1.Deplo registryDeployment.Spec.Template.Spec.Volumes = append( registryDeployment.Spec.Template.Spec.Volumes, corev1.Volume{ - Name: cloudProviderMap.SecretName, + Name: cloudProviderMap.BslSecretName, VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ SecretName: cloudProviderMap.BslSecretName, @@ -385,9 +385,17 @@ func (r *DPAReconciler) buildRegistryContainer(bsl *velerov1.BackupStorageLocati }, } - // append secret volumes if the BSL provider is GCP - if bsl.Spec.Provider == GCPProvider { - // check for secret name + // check for secret name + if _, ok := bsl.Spec.Config["credentialsFile"]; ok { // If credentialsFile config is used, then mount the bsl secret + if _, bslCredOk := credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)]; bslCredOk { + containers[0].VolumeMounts = []corev1.VolumeMount{ + { + Name: credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)].BslSecretName, + MountPath: credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)].BSlMountPath, + }, + } + } + } else if bsl.Spec.Provider == GCPProvider { // append secret volumes if the BSL provider is GCP secretName, _ := r.getSecretNameAndKey(&bsl.Spec, oadpv1alpha1.DefaultPluginGCP) containers[0].VolumeMounts = []corev1.VolumeMount{ { @@ -526,7 +534,11 @@ func (r *DPAReconciler) getGCPRegistryEnvVars(bsl *velerov1.BackupStorageLocatio if gcpEnvVars[i].Name == RegistryStorageGCSKeyfile { // check for secret key _, secretKey := r.getSecretNameAndKey(&bsl.Spec, oadpv1alpha1.DefaultPluginGCP) - gcpEnvVars[i].Value = credentials.PluginSpecificFields[oadpv1alpha1.DefaultPluginGCP].MountPath + "/" + secretKey + if _, ok := bsl.Spec.Config["credentialsFile"]; ok { + gcpEnvVars[i].Value = credentials.PluginSpecificFields[oadpv1alpha1.DefaultPluginGCP].BSlMountPath + "/" + secretKey + } else { + gcpEnvVars[i].Value = credentials.PluginSpecificFields[oadpv1alpha1.DefaultPluginGCP].MountPath + "/" + secretKey + } } } return gcpEnvVars, nil From a560811e595f9964480eaf924647529f2565c7e9 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Mon, 21 Feb 2022 11:02:21 -0500 Subject: [PATCH 05/10] E2E Tests: Fix azure templating name. (#573) * Fixing Azure to run locally * Aligning json --- tests/e2e/e2e_suite_test.go | 18 ++++++++++++++++++ .../{azure_setting.sh => azure_settings.sh} | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) rename tests/e2e/scripts/{azure_setting.sh => azure_settings.sh} (92%) diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index 981435ec6a8..4fa33f543ba 100755 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -104,6 +104,7 @@ var _ = BeforeSuite(func() { // ci cloud ciJsonData, err := utils.GetJsonData(ci_cred_file) Expect(err).NotTo(HaveOccurred()) + if _, ok := ciJsonData["resourceGroup"]; !ok { resourceGroup, err := GetAzureResource(azure_resource_file) Expect(err).NotTo(HaveOccurred()) @@ -116,6 +117,23 @@ var _ = BeforeSuite(func() { err = utils.WriteFile(dpaCR.Credentials, ciCreds) Expect(err).NotTo(HaveOccurred()) } + } else { + if dpaCR.Provider == "azure" { + cloudCredData, err := utils.GetJsonData(dpaCR.Credentials) // azure credentials need to be in json - can be changed + Expect(err).NotTo(HaveOccurred()) + dpaCR.DpaAzureConfig = DpaAzureConfig{ + BslSubscriptionId: fmt.Sprintf("%v", cloudCredData["subscriptionId"]), + BslResourceGroup: fmt.Sprintf("%v", cloudCredData["resourceGroup"]), + BslStorageAccount: fmt.Sprintf("%v", cloudCredData["storageAccount"]), + BslStorageAccountKeyEnvVar: "AZURE_STORAGE_ACCOUNT_ACCESS_KEY", + VslSubscriptionId: fmt.Sprintf("%v", cloudCredData["subscriptionId"]), + VslResourceGroup: fmt.Sprintf("%v", cloudCredData["resourceGroup"]), + } + ciCreds := GetAzureCreds(cloudCredData) + dpaCR.Credentials = "/tmp/azure-credentials" + err = utils.WriteFile(dpaCR.Credentials, ciCreds) + Expect(err).NotTo(HaveOccurred()) + } } credData, err := utils.ReadFile(dpaCR.Credentials) Expect(err).NotTo(HaveOccurred()) diff --git a/tests/e2e/scripts/azure_setting.sh b/tests/e2e/scripts/azure_settings.sh similarity index 92% rename from tests/e2e/scripts/azure_setting.sh rename to tests/e2e/scripts/azure_settings.sh index e7436fb0817..43b191f9eff 100644 --- a/tests/e2e/scripts/azure_setting.sh +++ b/tests/e2e/scripts/azure_settings.sh @@ -18,7 +18,7 @@ cat > $TMP_DIR/oadpcreds < $TMP_DIR/oadpcreds < Date: Fri, 29 Apr 2022 10:27:13 +0530 Subject: [PATCH 06/10] Handling Azure Parameters in CI Env using templates. (#582) * Adding azure parameters * Adding Openshift CI params * Update Test Suite and Helpers * Adding cred ref * Adding cred ref * Changing azure oadp cred dir to tmp * Fixing duplicate error * Removing OpenShift CI * Changing test instance name * Changing the AWS BSL Profile to default * Changing BslMountPath variable in registry controller --- Makefile | 17 +++--- controllers/registry.go | 4 +- pkg/credentials/credentials.go | 10 ++-- tests/e2e/dpa_deployment_suite_test.go | 29 +-------- tests/e2e/e2e_suite_test.go | 81 +++----------------------- tests/e2e/lib/dpa_helpers.go | 79 +------------------------ tests/e2e/lib/kube_helpers.go | 31 ---------- tests/e2e/scripts/azure_settings.sh | 50 +++++++++++++--- tests/e2e/utils/common_utils.go | 23 -------- 9 files changed, 72 insertions(+), 252 deletions(-) diff --git a/Makefile b/Makefile index 6f4dd1c3989..7c6177de54b 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,8 @@ CI_CRED_FILE ?= ${CLUSTER_PROFILE_DIR}/.awscred # aws configs - default BSL_REGION ?= us-east-1 VSL_REGION ?= ${LEASED_RESOURCE} -# BSL_AWS_PROFILE ?= default -BSL_AWS_PROFILE ?= migration-engineering +BSL_AWS_PROFILE ?= default +# BSL_AWS_PROFILE ?= migration-engineering # vsl secret CREDS_SECRET_REF ?= cloud-credentials @@ -24,10 +24,12 @@ CREDS_SECRET_REF ?= cloud-credentials OADP_BUCKET_FILE ?= ${OADP_CRED_DIR}/new-velero-bucket-name # azure cluster resource file - only in CI AZURE_RESOURCE_FILE ?= /var/run/secrets/ci.openshift.io/multi-stage/metadata.json +AZURE_CI_JSON_CRED_FILE ?= ${CLUSTER_PROFILE_DIR}/osServicePrincipal.json +AZURE_OADP_JSON_CRED_FILE ?= ${OADP_CRED_DIR}/azure-credentials # Misc OPENSHIFT_CI ?= true -VELERO_INSTANCE_NAME ?= velero-sample +VELERO_INSTANCE_NAME ?= velero-test E2E_TIMEOUT_MULTIPLIER ?= 1 ifeq ($(CLUSTER_TYPE), gcp) @@ -37,8 +39,8 @@ ifeq ($(CLUSTER_TYPE), gcp) OADP_BUCKET_FILE = ${OADP_CRED_DIR}/gcp-velero-bucket-name else ifeq ($(CLUSTER_TYPE), azure4) CLUSTER_TYPE = azure - CI_CRED_FILE = ${CLUSTER_PROFILE_DIR}/osServicePrincipal.json - OADP_CRED_FILE = ${OADP_CRED_DIR}/azure-credentials + CI_CRED_FILE = /tmp/ci-azure-credentials + OADP_CRED_FILE = /tmp/oadp-azure-credentials CREDS_SECRET_REF = cloud-credentials-azure OADP_BUCKET_FILE = ${OADP_CRED_DIR}/azure-velero-bucket-name endif @@ -331,6 +333,8 @@ SETTINGS_TMP=/tmp/test-settings test-e2e-setup: mkdir -p $(SETTINGS_TMP) + TARGET_CI_CRED_FILE="$(CI_CRED_FILE)" AZURE_RESOURCE_FILE="$(AZURE_RESOURCE_FILE)" CI_JSON_CRED_FILE="$(AZURE_CI_JSON_CRED_FILE)" \ + OADP_JSON_CRED_FILE="$(AZURE_OADP_JSON_CRED_FILE)" OADP_CRED_FILE="$(OADP_CRED_FILE)" OPENSHIFT_CI="$(OPENSHIFT_CI)" \ PROVIDER="$(CLUSTER_TYPE)" BUCKET="$(OADP_BUCKET)" BSL_REGION="$(BSL_REGION)" SECRET="$(CREDS_SECRET_REF)" TMP_DIR=$(SETTINGS_TMP) \ VSL_REGION="$(VSL_REGION)" BSL_AWS_PROFILE="$(BSL_AWS_PROFILE)" BSL_REGION="$(BSL_REGION)" /bin/bash "tests/e2e/scripts/$(CLUSTER_TYPE)_settings.sh" @@ -340,11 +344,8 @@ test-e2e: test-e2e-setup -settings=$(SETTINGS_TMP)/oadpcreds \ -velero_instance_name=$(VELERO_INSTANCE_NAME) \ -timeout_multiplier=$(E2E_TIMEOUT_MULTIPLIER) \ - -cluster_profile=$(CLUSTER_TYPE) \ --ginkgo.label-filter="$(TEST_FILTER)" \ - -openshift_ci=$(OPENSHIFT_CI) \ -ci_cred_file=$(CI_CRED_FILE) \ - -azure_resource_file=$(AZURE_RESOURCE_FILE) \ -provider=$(CLUSTER_TYPE) \ -creds_secret_ref=$(CREDS_SECRET_REF) diff --git a/controllers/registry.go b/controllers/registry.go index e992f5b1299..381d0cbb622 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -391,7 +391,7 @@ func (r *DPAReconciler) buildRegistryContainer(bsl *velerov1.BackupStorageLocati containers[0].VolumeMounts = []corev1.VolumeMount{ { Name: credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)].BslSecretName, - MountPath: credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)].BSlMountPath, + MountPath: credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)].BslMountPath, }, } } @@ -535,7 +535,7 @@ func (r *DPAReconciler) getGCPRegistryEnvVars(bsl *velerov1.BackupStorageLocatio // check for secret key _, secretKey := r.getSecretNameAndKey(&bsl.Spec, oadpv1alpha1.DefaultPluginGCP) if _, ok := bsl.Spec.Config["credentialsFile"]; ok { - gcpEnvVars[i].Value = credentials.PluginSpecificFields[oadpv1alpha1.DefaultPluginGCP].BSlMountPath + "/" + secretKey + gcpEnvVars[i].Value = credentials.PluginSpecificFields[oadpv1alpha1.DefaultPluginGCP].BslMountPath + "/" + secretKey } else { gcpEnvVars[i].Value = credentials.PluginSpecificFields[oadpv1alpha1.DefaultPluginGCP].MountPath + "/" + secretKey } diff --git a/pkg/credentials/credentials.go b/pkg/credentials/credentials.go index 2e108cbcb88..0ef4664d958 100644 --- a/pkg/credentials/credentials.go +++ b/pkg/credentials/credentials.go @@ -16,7 +16,7 @@ type DefaultPluginFields struct { SecretName string MountPath string BslSecretName string - BSlMountPath string + BslMountPath string EnvCredentialsFile string PluginImage string PluginSecretKey string @@ -34,7 +34,7 @@ var ( SecretName: "cloud-credentials", MountPath: "/credentials", BslSecretName: "bsl-cloud-credentials-aws", - BSlMountPath: "/bsl-cloud-credentials-aws", + BslMountPath: "/bsl-cloud-credentials-aws", EnvCredentialsFile: common.AWSSharedCredentialsFileEnvKey, PluginName: common.VeleroPluginForAWS, PluginSecretKey: "cloud", @@ -44,7 +44,7 @@ var ( SecretName: "cloud-credentials-gcp", MountPath: "/credentials-gcp", BslSecretName: "bsl-cloud-credentials-gcp", - BSlMountPath: "/bsl-cloud-credentials-gcp", + BslMountPath: "/bsl-cloud-credentials-gcp", EnvCredentialsFile: common.GCPCredentialsEnvKey, PluginName: common.VeleroPluginForGCP, PluginSecretKey: "cloud", @@ -54,7 +54,7 @@ var ( SecretName: "cloud-credentials-azure", MountPath: "/credentials-azure", BslSecretName: "bsl-cloud-credentials-azure", - BSlMountPath: "/bsl-cloud-credentials-azure", + BslMountPath: "/bsl-cloud-credentials-azure", EnvCredentialsFile: common.AzureCredentialsFileEnvKey, PluginName: common.VeleroPluginForAzure, PluginSecretKey: "cloud", @@ -313,7 +313,7 @@ func AppendPluginSpecificSpecs(dpa *oadpv1alpha1.DataProtectionApplication, vele veleroContainer.VolumeMounts, corev1.VolumeMount{ Name: cloudProviderMap.BslSecretName, - MountPath: pluginSpecificMap.BSlMountPath, + MountPath: pluginSpecificMap.BslMountPath, }) veleroDeployment.Spec.Template.Spec.Volumes = append( veleroDeployment.Spec.Template.Spec.Volumes, diff --git a/tests/e2e/dpa_deployment_suite_test.go b/tests/e2e/dpa_deployment_suite_test.go index 6918067a975..b65334a1c65 100644 --- a/tests/e2e/dpa_deployment_suite_test.go +++ b/tests/e2e/dpa_deployment_suite_test.go @@ -495,33 +495,8 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { err := dpaCR.Build(installCase.BRestoreType) Expect(err).NotTo(HaveOccurred()) if len(installCase.DpaSpec.BackupLocations) > 0 { - switch dpaCR.Provider { - case "aws": - if installCase.DpaSpec.BackupLocations[0].Velero.Config != nil { - installCase.DpaSpec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-aws/cloud" - } - case "gcp": - if installCase.DpaSpec.BackupLocations[0].Velero.Config != nil { - installCase.DpaSpec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-gcp/cloud" - } - case "azure": - installCase.DpaSpec.BackupLocations[0].Velero.Config = map[string]string{ - "credentialsFile": "bsl-cloud-credentials-azure/cloud", - "subscriptionId": dpaCR.DpaAzureConfig.BslSubscriptionId, - "storageAccount": dpaCR.DpaAzureConfig.BslStorageAccount, - "resourceGroup": dpaCR.DpaAzureConfig.BslResourceGroup, - "storageAccountKeyEnvVar": dpaCR.DpaAzureConfig.BslStorageAccountKeyEnvVar, - } - installCase.DpaSpec.SnapshotLocations = []oadpv1alpha1.SnapshotLocation{ - { - Velero: &velero.VolumeSnapshotLocationSpec{ - Provider: dpaCR.Provider, - Config: map[string]string{ - "subscriptionId": dpaCR.DpaAzureConfig.VslSubscriptionId, - }, - }, - }, - } + if installCase.DpaSpec.BackupLocations[0].Velero.Config != nil { + installCase.DpaSpec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-" + dpaCR.Provider + "/cloud" } } err = dpaCR.CreateOrUpdate(installCase.DpaSpec) diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index 4fa33f543ba..4a3d8f356b9 100755 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -3,9 +3,7 @@ package e2e_test import ( "errors" "flag" - "fmt" "log" - "strconv" "testing" "time" @@ -16,7 +14,7 @@ import ( ) // Common vars obtained from flags passed in ginkgo. -var credFile, namespace, credSecretRef, instanceName, provider, azure_resource_file, openshift_ci, ci_cred_file, settings, bsl_profile string +var credFile, namespace, credSecretRef, instanceName, provider, ci_cred_file, settings, artifact_dir, oc_cli string var timeoutMultiplier time.Duration func init() { @@ -24,12 +22,11 @@ func init() { flag.StringVar(&namespace, "velero_namespace", "velero", "Velero Namespace") flag.StringVar(&settings, "settings", "./templates/default_settings.json", "Settings of the velero instance") flag.StringVar(&instanceName, "velero_instance_name", "example-velero", "Velero Instance Name") - flag.StringVar(&bsl_profile, "cluster_profile", "aws", "Cluster profile") flag.StringVar(&credSecretRef, "creds_secret_ref", "cloud-credentials", "Credential secret ref for backup storage location") - flag.StringVar(&provider, "provider", "aws", "BSL provider") - flag.StringVar(&azure_resource_file, "azure_resource_file", "azure resource file", "Resource Group Dir for azure") + flag.StringVar(&provider, "provider", "aws", "Cloud provider") flag.StringVar(&ci_cred_file, "ci_cred_file", credFile, "CI Cloud Cred File") - flag.StringVar(&openshift_ci, "openshift_ci", "false", "ENV for tests") + flag.StringVar(&artifact_dir, "artifact_dir", "/tmp", "Directory for storing must gather") + flag.StringVar(&oc_cli, "oc_cli", "oc", "OC CLI Client") timeoutMultiplierInput := flag.Int64("timeout_multiplier", 1, "Customize timeout multiplier from default (1)") timeoutMultiplier = 1 @@ -68,73 +65,13 @@ var _ = BeforeSuite(func() { dpaCR.CustomResource = Dpa testSuiteInstanceName := "ts-" + instanceName dpaCR.Name = testSuiteInstanceName - openshift_ci_bool, _ := strconv.ParseBool(openshift_ci) - dpaCR.OpenshiftCi = openshift_ci_bool - if openshift_ci_bool == true { - switch dpaCR.Provider { - case "aws": - cloudCredData, err := utils.ReadFile(dpaCR.Credentials) - Expect(err).NotTo(HaveOccurred()) - err = CreateCredentialsSecret(cloudCredData, namespace, "bsl-cloud-credentials-aws") - Expect(err).NotTo(HaveOccurred()) - dpaCR.Credentials = ci_cred_file - case "gcp": - cloudCredData, err := utils.ReadFile(dpaCR.Credentials) - Expect(err).NotTo(HaveOccurred()) - err = CreateCredentialsSecret(cloudCredData, namespace, "bsl-cloud-credentials-gcp") - Expect(err).NotTo(HaveOccurred()) - dpaCR.Credentials = ci_cred_file - case "azure": - cloudCredData, err := utils.GetJsonData(dpaCR.Credentials) // azure credentials need to be in json - can be changed - Expect(err).NotTo(HaveOccurred()) - dpaCR.DpaAzureConfig = DpaAzureConfig{ - BslSubscriptionId: fmt.Sprintf("%v", cloudCredData["subscriptionId"]), - BslResourceGroup: fmt.Sprintf("%v", cloudCredData["resourceGroup"]), - BslStorageAccount: fmt.Sprintf("%v", cloudCredData["storageAccount"]), - BslStorageAccountKeyEnvVar: "AZURE_STORAGE_ACCOUNT_ACCESS_KEY", - VslSubscriptionId: fmt.Sprintf("%v", cloudCredData["subscriptionId"]), - VslResourceGroup: fmt.Sprintf("%v", cloudCredData["resourceGroup"]), - } - - // bsl cloud - cloudCreds := GetAzureCreds(cloudCredData) - err = CreateCredentialsSecret(cloudCreds, namespace, "bsl-cloud-credentials-azure") - Expect(err).NotTo(HaveOccurred()) - // ci cloud - ciJsonData, err := utils.GetJsonData(ci_cred_file) - Expect(err).NotTo(HaveOccurred()) + cloudCredData, err := utils.ReadFile(dpaCR.Credentials) + Expect(err).NotTo(HaveOccurred()) + err = CreateCredentialsSecret(cloudCredData, namespace, "bsl-cloud-credentials-"+provider) + Expect(err).NotTo(HaveOccurred()) + dpaCR.Credentials = ci_cred_file - if _, ok := ciJsonData["resourceGroup"]; !ok { - resourceGroup, err := GetAzureResource(azure_resource_file) - Expect(err).NotTo(HaveOccurred()) - ciJsonData["resourceGroup"] = resourceGroup - } - dpaCR.DpaAzureConfig.VslSubscriptionId = fmt.Sprintf("%v", ciJsonData["subscriptionId"]) - dpaCR.DpaAzureConfig.VslResourceGroup = fmt.Sprintf("%v", ciJsonData["resourceGroup"]) - ciCreds := GetAzureCreds(ciJsonData) - dpaCR.Credentials = "/tmp/azure-credentials" - err = utils.WriteFile(dpaCR.Credentials, ciCreds) - Expect(err).NotTo(HaveOccurred()) - } - } else { - if dpaCR.Provider == "azure" { - cloudCredData, err := utils.GetJsonData(dpaCR.Credentials) // azure credentials need to be in json - can be changed - Expect(err).NotTo(HaveOccurred()) - dpaCR.DpaAzureConfig = DpaAzureConfig{ - BslSubscriptionId: fmt.Sprintf("%v", cloudCredData["subscriptionId"]), - BslResourceGroup: fmt.Sprintf("%v", cloudCredData["resourceGroup"]), - BslStorageAccount: fmt.Sprintf("%v", cloudCredData["storageAccount"]), - BslStorageAccountKeyEnvVar: "AZURE_STORAGE_ACCOUNT_ACCESS_KEY", - VslSubscriptionId: fmt.Sprintf("%v", cloudCredData["subscriptionId"]), - VslResourceGroup: fmt.Sprintf("%v", cloudCredData["resourceGroup"]), - } - ciCreds := GetAzureCreds(cloudCredData) - dpaCR.Credentials = "/tmp/azure-credentials" - err = utils.WriteFile(dpaCR.Credentials, ciCreds) - Expect(err).NotTo(HaveOccurred()) - } - } credData, err := utils.ReadFile(dpaCR.Credentials) Expect(err).NotTo(HaveOccurred()) err = CreateCredentialsSecret(credData, namespace, credSecretRef) diff --git a/tests/e2e/lib/dpa_helpers.go b/tests/e2e/lib/dpa_helpers.go index caa82529cb4..6f0c690fde7 100755 --- a/tests/e2e/lib/dpa_helpers.go +++ b/tests/e2e/lib/dpa_helpers.go @@ -37,15 +37,6 @@ const ( RESTIC BackupRestoreType = "restic" ) -type DpaAzureConfig struct { - VslSubscriptionId string - VslResourceGroup string - BslSubscriptionId string - BslResourceGroup string - BslStorageAccount string - BslStorageAccountKeyEnvVar string -} - type DpaCustomResource struct { Name string Namespace string @@ -53,11 +44,9 @@ type DpaCustomResource struct { backupRestoreType BackupRestoreType CustomResource *oadpv1alpha1.DataProtectionApplication Client client.Client - DpaAzureConfig DpaAzureConfig Credentials string CredSecretRef string Provider string - OpenshiftCi bool } var VeleroPrefix = "velero-e2e-" + string(uuid.NewUUID()) @@ -98,72 +87,8 @@ func (v *DpaCustomResource) Build(backupRestoreType BackupRestoreType) error { }, }, } - switch v.Provider { - case "aws": - if v.OpenshiftCi { - if dpaInstance.Spec.BackupLocations[0].Velero.Config != nil { - dpaInstance.Spec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-aws/cloud" - } - } else { - dpaInstance.Spec.BackupLocations[0].Velero.Credential = &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: v.CredSecretRef, - }, - Key: "cloud", - } - } - case "gcp": - if v.OpenshiftCi { - if dpaInstance.Spec.BackupLocations[0].Velero.Config != nil { - dpaInstance.Spec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-gcp/cloud" - } - } else { - dpaInstance.Spec.BackupLocations[0].Velero.Credential = &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: v.CredSecretRef, - }, - Key: "cloud", - } - } - // dpaInstance.Spec.Configuration.Velero.DefaultPlugins = append(dpaInstance.Spec.Configuration.Velero.DefaultPlugins, oadpv1alpha1.DefaultPluginGCP) - // dpaInstance.Spec.SnapshotLocations = []oadpv1alpha1.SnapshotLocation{ - // { - // Velero: &velero.VolumeSnapshotLocationSpec{ - // Provider: v.Provider, - // Config: map[string]string{ - // "snapshotLocation": v.gcpConfig.VslRegion, - // }, - // }, - // }, - // } - case "azure": - dpaInstance.Spec.BackupLocations[0].Velero.Config = map[string]string{ - "subscriptionId": v.DpaAzureConfig.BslSubscriptionId, - "storageAccount": v.DpaAzureConfig.BslStorageAccount, - "resourceGroup": v.DpaAzureConfig.BslResourceGroup, - "storageAccountKeyEnvVar": v.DpaAzureConfig.BslStorageAccountKeyEnvVar, - } - if v.OpenshiftCi { - dpaInstance.Spec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-azure/cloud" // / - } else { - dpaInstance.Spec.BackupLocations[0].Velero.Credential = &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: v.CredSecretRef, - }, - Key: "cloud", - } - } - dpaInstance.Spec.SnapshotLocations = []oadpv1alpha1.SnapshotLocation{ - { - Velero: &velero.VolumeSnapshotLocationSpec{ - Provider: v.Provider, - Config: map[string]string{ - "subscriptionId": v.DpaAzureConfig.VslSubscriptionId, - "resourceGroup": v.DpaAzureConfig.VslResourceGroup, - }, - }, - }, - } + if dpaInstance.Spec.BackupLocations[0].Velero.Config != nil { + dpaInstance.Spec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-" + v.Provider + "/cloud" } v.backupRestoreType = backupRestoreType switch backupRestoreType { diff --git a/tests/e2e/lib/kube_helpers.go b/tests/e2e/lib/kube_helpers.go index 9f58647a93d..2e3333dbc90 100755 --- a/tests/e2e/lib/kube_helpers.go +++ b/tests/e2e/lib/kube_helpers.go @@ -2,10 +2,8 @@ package lib import ( "context" - "fmt" "log" - utils "github.com/openshift/oadp-operator/tests/e2e/utils" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -210,32 +208,3 @@ func isCredentialsSecretDeleted(namespace string, credSecretRef string) wait.Con return false, err } } - -func GetAzureCreds(ciCred map[string]interface{}) []byte { - azureCreds := string("AZURE_CLOUD_NAME=AzurePublicCloud") - - for k, v := range ciCred { - switch k { - case "subscriptionId": - azureCreds += "\n" + "AZURE_SUBSCRIPTION_ID=" + fmt.Sprintf("%v", v) - case "clientId": - azureCreds += "\n" + "AZURE_CLIENT_ID=" + fmt.Sprintf("%v", v) - case "clientSecret": - azureCreds += "\n" + "AZURE_CLIENT_SECRET=" + fmt.Sprintf("%v", v) - case "tenantId": - azureCreds += "\n" + "AZURE_TENANT_ID=" + fmt.Sprintf("%v", v) - case "storageAccountAccessKey": - azureCreds += "\n" + "AZURE_STORAGE_ACCOUNT_ACCESS_KEY=" + fmt.Sprintf("%v", v) - case "resourceGroup": - azureCreds += "\n" + "AZURE_RESOURCE_GROUP=" + fmt.Sprintf("%v", v) - } - } - - return []byte(azureCreds) -} - -func GetAzureResource(path string) (string, error) { - azure_config, err := utils.GetJsonData(path) - resourceGroup := fmt.Sprintf("%v", azure_config["infraID"]) + "-rg" - return resourceGroup, err -} diff --git a/tests/e2e/scripts/azure_settings.sh b/tests/e2e/scripts/azure_settings.sh index 43b191f9eff..3bcb31bc092 100644 --- a/tests/e2e/scripts/azure_settings.sh +++ b/tests/e2e/scripts/azure_settings.sh @@ -1,5 +1,42 @@ #!/bin/bash +CI_AZURE_SUBSCRIPTION_ID=$(cat $CI_JSON_CRED_FILE | awk '/subscriptionId/ { gsub(/["]|,.*/,""); print $2}') +CI_AZURE_CLIENT_ID=$(cat $CI_JSON_CRED_FILE | awk '/clientId/ { gsub(/["]|,.*/,""); print $2}') +CI_AZURE_CLIENT_SECRET=$(cat $CI_JSON_CRED_FILE | awk '/clientSecret/ { gsub(/["]|,.*/,""); print $2}') +CI_AZURE_TENANT_ID=$(cat $CI_JSON_CRED_FILE | awk '/tenantId/ { gsub(/["]|,.*/,""); print $2}') +CI_AZURE_RESOURCE_GROUP=$(cat $AZURE_RESOURCE_FILE | awk '/infraID/ { gsub(/["]|,.*/,""); print $2}') + +if [ "$OPENSHIFT_CI" == "true" ]; then\ + CI_AZURE_RESOURCE_GROUP="${CI_AZURE_RESOURCE_GROUP}-rg"; \ +fi + +cat > $TARGET_CI_CRED_FILE < $OADP_CRED_FILE < $TMP_DIR/oadpcreds < $TMP_DIR/oadpcreds < $TMP_DIR/oadpcreds < Date: Tue, 3 May 2022 10:18:26 -0400 Subject: [PATCH 07/10] Replace carriage return when getting provider secrets for registry + E2E changes (#652) * Replace carriage return when getting provider secrets for registry Co-authored-by: GitHub Co-pilot * add tests * replaceCarriageReturn unit test * Registry credentials can use other secret names Co-authored-by: GitHub Co-pilot --- controllers/registry.go | 43 ++++++--- controllers/registry_test.go | 123 ++++++++++++++++++++++--- pkg/credentials/credentials.go | 37 +++++--- tests/e2e/dpa_deployment_suite_test.go | 37 ++++++++ tests/e2e/e2e_suite_test.go | 2 + tests/e2e/utils/common_utils.go | 7 ++ 6 files changed, 214 insertions(+), 35 deletions(-) diff --git a/controllers/registry.go b/controllers/registry.go index 381d0cbb622..3c978d6ae99 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -285,14 +285,14 @@ func (r *DPAReconciler) buildRegistryDeployment(registryDeployment *appsv1.Deplo // attach secret volume for cloud providers if _, ok := bsl.Spec.Config["credentialsFile"]; ok { - if cloudProviderMap, bslCredOk := credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)]; bslCredOk { + if secretName, err := credentials.GetSecretNameFromCredentialsFileConfigString(bsl.Spec.Config["credentialsFile"]); err == nil { registryDeployment.Spec.Template.Spec.Volumes = append( registryDeployment.Spec.Template.Spec.Volumes, corev1.Volume{ - Name: cloudProviderMap.BslSecretName, + Name: secretName, VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: cloudProviderMap.BslSecretName, + SecretName: secretName, }, }, }, @@ -387,12 +387,14 @@ func (r *DPAReconciler) buildRegistryContainer(bsl *velerov1.BackupStorageLocati // check for secret name if _, ok := bsl.Spec.Config["credentialsFile"]; ok { // If credentialsFile config is used, then mount the bsl secret - if _, bslCredOk := credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)]; bslCredOk { - containers[0].VolumeMounts = []corev1.VolumeMount{ - { - Name: credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)].BslSecretName, - MountPath: credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)].BslMountPath, - }, + if secretName, err := credentials.GetSecretNameFromCredentialsFileConfigString(bsl.Spec.Config["credentialsFile"]); err == nil { + if _, bslCredOk := credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)]; bslCredOk { + containers[0].VolumeMounts = []corev1.VolumeMount{ + { + Name: secretName, + MountPath: credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)].BslMountPath, + }, + } } } } else if bsl.Spec.Provider == GCPProvider { // append secret volumes if the BSL provider is GCP @@ -557,8 +559,22 @@ func (r *DPAReconciler) getProviderSecret(secretName string) (corev1.Secret, err return secret, err } r.Log.Info(fmt.Sprintf("got provider secret name: %s", secret.Name)) + // replace carriage return with new line + secret.Data = replaceCarriageReturn(secret.Data, r.Log) return secret, nil } + +func replaceCarriageReturn(data map[string][]byte, logger logr.Logger) map[string][]byte { + for k, v := range data { + // report if carriage return is found + if strings.Contains(string(v), "\r\n") { + logger.Info("carriage return replaced") + data[k] = []byte(strings.ReplaceAll(string(v), "\r\n", "\n")) + } + } + return data +} + func (r *DPAReconciler) getSecretNameAndKeyforBackupLocation(bslspec oadpv1alpha1.BackupLocation) (string, string) { if bslspec.CloudStorage != nil { @@ -578,11 +594,12 @@ func (r *DPAReconciler) getSecretNameAndKey(bslSpec *velerov1.BackupStorageLocat secretName := credentials.PluginSpecificFields[plugin].SecretName secretKey := credentials.PluginSpecificFields[plugin].PluginSecretKey if _, ok := bslSpec.Config["credentialsFile"]; ok { - secretName = credentials.PluginSpecificFields[plugin].BslSecretName - secretKey = credentials.PluginSpecificFields[plugin].PluginSecretKey + if secretName, secretKey, err := + credentials.GetSecretNameKeyFromCredentialsFileConfigString(bslSpec.Config["credentialsFile"]); err == nil { + r.Log.Info(fmt.Sprintf("credentialsFile secret: %s, key: %s", secretName, secretKey)) + return secretName, secretKey + } } - r.Log.Info(fmt.Sprintf("secret: %s", secretName)) - r.Log.Info(fmt.Sprintf("key: %s", secretKey)) // check if user specified the Credential Name and Key credential := bslSpec.Credential if credential != nil { diff --git a/controllers/registry_test.go b/controllers/registry_test.go index cc5b8bed26c..9b06ea36cf5 100644 --- a/controllers/registry_test.go +++ b/controllers/registry_test.go @@ -1,28 +1,26 @@ package controllers import ( - "github.com/go-logr/logr" - routev1 "github.com/openshift/api/route/v1" - oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - - //"k8s.io/apimachinery/pkg/types" + "context" "reflect" "testing" - "k8s.io/client-go/tools/record" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/client/fake" - + "github.com/go-logr/logr" + routev1 "github.com/openshift/api/route/v1" + oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1" "github.com/openshift/oadp-operator/pkg/common" velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/tools/record" "k8s.io/utils/pointer" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/fake" ) func getSchemeForFakeClientForRegistry() (*runtime.Scheme, error) { @@ -91,6 +89,19 @@ var ( "aws_secret_access_key=" + testSecretAccessKey + "=" + testSecretAccessKey, ), } + secretDataWithCarriageReturnInSecret = map[string][]byte{ + "cloud": []byte( + "\n[" + testBslProfile + "]\r\n" + + "aws_access_key_id=" + testBslAccessKey + "\n" + + "aws_secret_access_key=" + testBslSecretAccessKey + "=" + testBslSecretAccessKey + + "\n[default]" + "\n" + + "aws_access_key_id=" + testAccessKey + "\n" + + "aws_secret_access_key=" + testSecretAccessKey + "=" + testSecretAccessKey + + "\r\n[test-profile]\n" + + "aws_access_key_id=" + testAccessKey + "\r\n" + + "aws_secret_access_key=" + testSecretAccessKey + "=" + testSecretAccessKey, + ), + } secretDataWithMixedQuotesAndSpacesInSecret = map[string][]byte{ "cloud": []byte( "\n[" + testBslProfile + "]\n" + @@ -261,6 +272,56 @@ func TestDPAReconciler_buildRegistryDeployment(t *testing.T) { }, dpa: &oadpv1alpha1.DataProtectionApplication{}, }, + { + name: "given a valid bsl with carriageReturn in secret val get appropriate registry deployment", + registryDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-registry", + Namespace: "test-ns", + }, + Spec: appsv1.DeploymentSpec{ + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "component": "oadp-" + "test-bsl" + "-" + "aws" + "-registry", + }, + }, + }, + }, + bsl: &velerov1.BackupStorageLocation{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-bsl", + Namespace: "test-ns", + }, + Spec: velerov1.BackupStorageLocationSpec{ + Provider: AWSProvider, + StorageType: velerov1.StorageType{ + ObjectStorage: &velerov1.ObjectStorageLocation{ + Bucket: "aws-bucket", + }, + }, + Config: map[string]string{ + Region: "aws-region", + S3URL: "https://sr-url-aws-domain.com", + InsecureSkipTLSVerify: "false", + }, + }, + }, + secret: &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cloud-credentials", + Namespace: "test-ns", + }, + Data: secretDataWithCarriageReturnInSecret, + }, + registrySecret: &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "oadp-test-bsl-aws-registry-secret", + Namespace: "test-ns", + }, + Data: secretDataWithCarriageReturnInSecret, + }, + dpa: &oadpv1alpha1.DataProtectionApplication{}, + }, { name: "given a valid bsl with use of quotes in secret val get appropriate registry deployment", registryDeployment: &appsv1.Deployment{ @@ -1851,3 +1912,43 @@ func TestDPAReconciler_populateAzureRegistrySecret(t *testing.T) { }) } } + +func Test_replaceCarriageReturn(t *testing.T) { + type args struct { + data map[string][]byte + logger logr.Logger + } + tests := []struct { + name string + args args + want map[string][]byte + }{ + { + name: "Given a map with carriage return, carriage return is replaced with new line", + args: args{ + data: map[string][]byte{ + "test": []byte("test\r\n"), + }, + logger: logr.FromContextOrDiscard(context.TODO()), + }, + want: map[string][]byte{ + "test": []byte("test\n"), + }, + }, + { + name: "Given secret data with carriage return, carriage return is replaced with new line", + args: args{ + data: secretDataWithCarriageReturnInSecret, + logger: logr.FromContextOrDiscard(context.TODO()), + }, + want: secretDataWithEqualInSecret, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := replaceCarriageReturn(tt.args.data, tt.args.logger); !reflect.DeepEqual(got, tt.want) { + t.Errorf("replaceCarriageReturn() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/credentials/credentials.go b/pkg/credentials/credentials.go index 0ef4664d958..0b3a4cd5bba 100644 --- a/pkg/credentials/credentials.go +++ b/pkg/credentials/credentials.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "strings" oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1" "github.com/openshift/oadp-operator/pkg/common" @@ -15,7 +16,6 @@ type DefaultPluginFields struct { IsCloudProvider bool SecretName string MountPath string - BslSecretName string BslMountPath string EnvCredentialsFile string PluginImage string @@ -33,7 +33,6 @@ var ( IsCloudProvider: true, SecretName: "cloud-credentials", MountPath: "/credentials", - BslSecretName: "bsl-cloud-credentials-aws", BslMountPath: "/bsl-cloud-credentials-aws", EnvCredentialsFile: common.AWSSharedCredentialsFileEnvKey, PluginName: common.VeleroPluginForAWS, @@ -43,7 +42,6 @@ var ( IsCloudProvider: true, SecretName: "cloud-credentials-gcp", MountPath: "/credentials-gcp", - BslSecretName: "bsl-cloud-credentials-gcp", BslMountPath: "/bsl-cloud-credentials-gcp", EnvCredentialsFile: common.GCPCredentialsEnvKey, PluginName: common.VeleroPluginForGCP, @@ -53,7 +51,6 @@ var ( IsCloudProvider: true, SecretName: "cloud-credentials-azure", MountPath: "/credentials-azure", - BslSecretName: "bsl-cloud-credentials-azure", BslMountPath: "/bsl-cloud-credentials-azure", EnvCredentialsFile: common.AzureCredentialsFileEnvKey, PluginName: common.VeleroPluginForAzure, @@ -75,6 +72,24 @@ var ( } ) +// Get secretName and secretKey from "secretName/secretKey" +func GetSecretNameKeyFromCredentialsFileConfigString(credentialsFile string) (string, string, error) { + credentialsFile = strings.TrimSpace(credentialsFile) + if credentialsFile == "" { + return "", "", nil + } + nameKeyArray := strings.Split(credentialsFile, "/") + if len(nameKeyArray) != 2 { + return "", "", errors.New("credentials file is not supported") + } + return nameKeyArray[0], nameKeyArray[1], nil +} + +func GetSecretNameFromCredentialsFileConfigString(credentialsFile string) (string, error) { + name, _, err := GetSecretNameKeyFromCredentialsFileConfigString(credentialsFile) + return name, err +} + func getAWSPluginImage(dpa *oadpv1alpha1.DataProtectionApplication) string { if dpa.Spec.UnsupportedOverrides[oadpv1alpha1.AWSPluginImageKey] != "" { return dpa.Spec.UnsupportedOverrides[oadpv1alpha1.AWSPluginImageKey] @@ -225,14 +240,14 @@ func AppendCloudProviderVolumes(dpa *oadpv1alpha1.DataProtectionApplication, ds } for _, bslSpec := range dpa.Spec.BackupLocations { if _, ok := bslSpec.Velero.Config["credentialsFile"]; ok { - if cloudProviderMap, bslCredOk := PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bslSpec.Velero.Provider)]; bslCredOk { + if secretName, err := GetSecretNameFromCredentialsFileConfigString(bslSpec.Velero.Config["credentialsFile"]); err == nil { ds.Spec.Template.Spec.Volumes = append( ds.Spec.Template.Spec.Volumes, corev1.Volume{ - Name: cloudProviderMap.BslSecretName, + Name: secretName, VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: cloudProviderMap.BslSecretName, + SecretName: secretName, }, }, }, @@ -308,20 +323,20 @@ func AppendPluginSpecificSpecs(dpa *oadpv1alpha1.DataProtectionApplication, vele // append bsl volume secret for _, bslSpec := range dpa.Spec.BackupLocations { if _, ok := bslSpec.Velero.Config["credentialsFile"]; ok { - if cloudProviderMap, bslCredOk := PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bslSpec.Velero.Provider)]; bslCredOk { + if secretName, err := GetSecretNameFromCredentialsFileConfigString(bslSpec.Velero.Config["credentialsFile"]); err == nil { veleroContainer.VolumeMounts = append( veleroContainer.VolumeMounts, corev1.VolumeMount{ - Name: cloudProviderMap.BslSecretName, + Name: secretName, MountPath: pluginSpecificMap.BslMountPath, }) veleroDeployment.Spec.Template.Spec.Volumes = append( veleroDeployment.Spec.Template.Spec.Volumes, corev1.Volume{ - Name: cloudProviderMap.BslSecretName, + Name: secretName, VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: cloudProviderMap.BslSecretName, + SecretName: secretName, }, }, }, diff --git a/tests/e2e/dpa_deployment_suite_test.go b/tests/e2e/dpa_deployment_suite_test.go index b65334a1c65..3e713c76699 100644 --- a/tests/e2e/dpa_deployment_suite_test.go +++ b/tests/e2e/dpa_deployment_suite_test.go @@ -27,6 +27,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { Name string BRestoreType BackupRestoreType DpaSpec *oadpv1alpha1.DataProtectionApplicationSpec + TestCarriageReturn bool WantError bool } @@ -63,6 +64,39 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { }, WantError: false, }, nil), + Entry("Default velero CR, test carriage return", InstallCase{ + Name: "default-cr", + BRestoreType: RESTIC, + TestCarriageReturn: true, + DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ + Configuration: &oadpv1alpha1.ApplicationConfig{ + Velero: &oadpv1alpha1.VeleroConfig{ + DefaultPlugins: Dpa.Spec.Configuration.Velero.DefaultPlugins, + PodConfig: &oadpv1alpha1.PodConfig{}, + }, + Restic: &oadpv1alpha1.ResticConfig{ + PodConfig: &oadpv1alpha1.PodConfig{}, + Enable: pointer.Bool(true), + }, + }, + BackupLocations: []oadpv1alpha1.BackupLocation{ + { + Velero: &velero.BackupStorageLocationSpec{ + Provider: provider, + Config: bslConfig, + Default: true, + StorageType: velero.StorageType{ + ObjectStorage: &velero.ObjectStorageLocation{ + Bucket: bucket, + Prefix: VeleroPrefix, + }, + }, + }, + }, + }, + }, + WantError: false, + }, nil), Entry("Adding Velero custom plugin", InstallCase{ Name: "default-cr-velero-custom-plugin", BRestoreType: RESTIC, @@ -497,6 +531,9 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { if len(installCase.DpaSpec.BackupLocations) > 0 { if installCase.DpaSpec.BackupLocations[0].Velero.Config != nil { installCase.DpaSpec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-" + dpaCR.Provider + "/cloud" + if installCase.TestCarriageReturn { + installCase.DpaSpec.BackupLocations[0].Velero.Config["credentialsFile"] = "bsl-cloud-credentials-" + dpaCR.Provider + "-with-carriage-return/cloud" + } } } err = dpaCR.CreateOrUpdate(installCase.DpaSpec) diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index 4a3d8f356b9..99fbb9ef2f2 100755 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -70,6 +70,8 @@ var _ = BeforeSuite(func() { Expect(err).NotTo(HaveOccurred()) err = CreateCredentialsSecret(cloudCredData, namespace, "bsl-cloud-credentials-"+provider) Expect(err).NotTo(HaveOccurred()) + err = CreateCredentialsSecret(utils.ReplaceSecretDataNewLineWithCarriageReturn(cloudCredData), namespace, "bsl-cloud-credentials-"+provider+"-with-carriage-return") + Expect(err).NotTo(HaveOccurred()) dpaCR.Credentials = ci_cred_file credData, err := utils.ReadFile(dpaCR.Credentials) diff --git a/tests/e2e/utils/common_utils.go b/tests/e2e/utils/common_utils.go index d60e1f9ba03..281194d882e 100644 --- a/tests/e2e/utils/common_utils.go +++ b/tests/e2e/utils/common_utils.go @@ -2,6 +2,7 @@ package utils import ( "io/ioutil" + "strings" ) func ReadFile(path string) ([]byte, error) { @@ -14,3 +15,9 @@ func ReadFile(path string) ([]byte, error) { file, err := ioutil.ReadFile(path) return file, err } + +func ReplaceSecretDataNewLineWithCarriageReturn(data []byte) []byte { + // Replace new line with carriage return + data = []byte(strings.ReplaceAll(string(data), "\n", "\r\n")) + return data +} From 20a487f83d866f9c854519c51f059b0d07af2f2c Mon Sep 17 00:00:00 2001 From: Shubham Pampattiwar Date: Mon, 9 May 2022 13:04:20 -0400 Subject: [PATCH 08/10] fix missing err return for updateRegistrySecret function --- controllers/registry.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/controllers/registry.go b/controllers/registry.go index 3c978d6ae99..dd7aa63aef5 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -1191,6 +1191,10 @@ func (r *DPAReconciler) updateRegistrySecret(secret *corev1.Secret, bsl *velerov err = r.populateAzureRegistrySecret(bsl, secret) } + if err != nil { + return err + } + return nil } From f6eae3326c27fc0827c5904fd14d0d189a434d11 Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Mon, 9 May 2022 14:32:27 -0400 Subject: [PATCH 09/10] go fmt --- controllers/registry_test.go | 2 +- tests/e2e/dpa_deployment_suite_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/controllers/registry_test.go b/controllers/registry_test.go index 9b06ea36cf5..7939cfa6d09 100644 --- a/controllers/registry_test.go +++ b/controllers/registry_test.go @@ -1938,7 +1938,7 @@ func Test_replaceCarriageReturn(t *testing.T) { { name: "Given secret data with carriage return, carriage return is replaced with new line", args: args{ - data: secretDataWithCarriageReturnInSecret, + data: secretDataWithCarriageReturnInSecret, logger: logr.FromContextOrDiscard(context.TODO()), }, want: secretDataWithEqualInSecret, diff --git a/tests/e2e/dpa_deployment_suite_test.go b/tests/e2e/dpa_deployment_suite_test.go index 3e713c76699..eedc284c6e5 100644 --- a/tests/e2e/dpa_deployment_suite_test.go +++ b/tests/e2e/dpa_deployment_suite_test.go @@ -24,11 +24,11 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { bslConfig := Dpa.Spec.BackupLocations[0].Velero.Config type InstallCase struct { - Name string - BRestoreType BackupRestoreType - DpaSpec *oadpv1alpha1.DataProtectionApplicationSpec + Name string + BRestoreType BackupRestoreType + DpaSpec *oadpv1alpha1.DataProtectionApplicationSpec TestCarriageReturn bool - WantError bool + WantError bool } genericTests := []TableEntry{ @@ -65,8 +65,8 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { WantError: false, }, nil), Entry("Default velero CR, test carriage return", InstallCase{ - Name: "default-cr", - BRestoreType: RESTIC, + Name: "default-cr", + BRestoreType: RESTIC, TestCarriageReturn: true, DpaSpec: &oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ From 3daf03074a66f9d1db137735166eb0fc1cf24117 Mon Sep 17 00:00:00 2001 From: Maya Peretz Date: Thu, 3 Feb 2022 20:01:50 +0200 Subject: [PATCH 10/10] upgraded ginkgo on tests to ginkgo 2.0 (#560) --- build/ci-Dockerfile | 3 ++- build/custom-ci-Dockerfile | 3 ++- docs/developer/TESTING.md | 2 +- go.mod | 3 ++- go.sum | 7 +++++-- tests/e2e/backup_restore_suite_test.go | 5 ++--- tests/e2e/dpa_deployment_suite_test.go | 5 ++--- tests/e2e/e2e_suite_test.go | 2 +- tests/e2e/lib/apps.go | 2 +- tests/e2e/lib/backup.go | 2 +- tests/e2e/lib/restore.go | 2 +- tests/e2e/subscription_suite_test.go | 3 +-- 12 files changed, 21 insertions(+), 18 deletions(-) diff --git a/build/ci-Dockerfile b/build/ci-Dockerfile index 85e8bca1b7f..049773267aa 100644 --- a/build/ci-Dockerfile +++ b/build/ci-Dockerfile @@ -2,7 +2,8 @@ # TODO! Find a real ubi8 image for golang 1.16 FROM quay.io/app-sre/boilerplate:image-v2.1.0 as builder -RUN go get -u github.com/onsi/ginkgo/ginkgo +RUN go get -u github.com/onsi/ginkgo/ginkgo && \ + go get -u github.com/onsi/ginkgo/v2/ginkgo RUN go get github.com/onsi/gomega/... WORKDIR /go/src/github.com/openshift/oadp-operator diff --git a/build/custom-ci-Dockerfile b/build/custom-ci-Dockerfile index 8e982891f7a..3106d326a9f 100644 --- a/build/custom-ci-Dockerfile +++ b/build/custom-ci-Dockerfile @@ -1,7 +1,8 @@ FROM openshift/origin-release:golang-1.16 RUN yum -y install epel-release --disablerepo=epel && yum clean all RUN yum -y install make -RUN go get -u github.com/onsi/ginkgo/ginkgo +RUN go get -u github.com/onsi/ginkgo/ginkgo && \ + go get -u github.com/onsi/ginkgo/v2/ginkgo RUN go get github.com/onsi/gomega/... RUN chmod g+rw /etc/passwd ENV LC_ALL=en_US.utf-8 LANG=en_US.utf-8 \ No newline at end of file diff --git a/docs/developer/TESTING.md b/docs/developer/TESTING.md index fda7ea0f006..1156152e401 100644 --- a/docs/developer/TESTING.md +++ b/docs/developer/TESTING.md @@ -4,7 +4,7 @@ ### Install Ginkgo ```bash -$ go get -u github.com/onsi/ginkgo/ginkgo +$ go get -u github.com/onsi/ginkgo/v2/ginkgo ``` ### Setup backup storage configuration diff --git a/go.mod b/go.mod index e56f043e892..28a7e7369de 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,8 @@ require ( 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/v2 v2.1.1 + 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 diff --git a/go.sum b/go.sum index 0360f3c2bea..fd61c192436 100644 --- a/go.sum +++ b/go.sum @@ -383,6 +383,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -571,6 +572,8 @@ github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k 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/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= 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 +583,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= diff --git a/tests/e2e/backup_restore_suite_test.go b/tests/e2e/backup_restore_suite_test.go index 19d75c34c50..25292eea094 100755 --- a/tests/e2e/backup_restore_suite_test.go +++ b/tests/e2e/backup_restore_suite_test.go @@ -7,8 +7,7 @@ import ( "time" "github.com/google/uuid" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/openshift/oadp-operator/tests/e2e/lib" utils "github.com/openshift/oadp-operator/tests/e2e/utils" @@ -169,7 +168,7 @@ var _ = Describe("AWS backup restore tests", func() { } }, - Entry("MSSQL application CSI", BackupRestoreCase{ + Entry("MSSQL application CSI", Label("aws"), BackupRestoreCase{ ApplicationTemplate: "./sample-applications/mssql-persistent/mssql-persistent-csi-template.yaml", ApplicationNamespace: "mssql-persistent", Name: "mssql-e2e", diff --git a/tests/e2e/dpa_deployment_suite_test.go b/tests/e2e/dpa_deployment_suite_test.go index eedc284c6e5..1107a6d0ba3 100644 --- a/tests/e2e/dpa_deployment_suite_test.go +++ b/tests/e2e/dpa_deployment_suite_test.go @@ -8,8 +8,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1" . "github.com/openshift/oadp-operator/tests/e2e/lib" @@ -619,6 +618,6 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() { Eventually(AreRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue()) } - }, genericTests..., + }, genericTests, ) }) diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index 99fbb9ef2f2..1e5173814ba 100755 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/openshift/oadp-operator/tests/e2e/lib" "github.com/openshift/oadp-operator/tests/e2e/utils" diff --git a/tests/e2e/lib/apps.go b/tests/e2e/lib/apps.go index 01d00d9d57f..36478a5d127 100755 --- a/tests/e2e/lib/apps.go +++ b/tests/e2e/lib/apps.go @@ -6,7 +6,7 @@ import ( "fmt" "os" - "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/v2" ocpappsv1 "github.com/openshift/api/apps/v1" security "github.com/openshift/api/security/v1" appsv1 "k8s.io/api/apps/v1" diff --git a/tests/e2e/lib/backup.go b/tests/e2e/lib/backup.go index 2f6e5a4b26c..44b8756a0f4 100755 --- a/tests/e2e/lib/backup.go +++ b/tests/e2e/lib/backup.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/v2" velero "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" diff --git a/tests/e2e/lib/restore.go b/tests/e2e/lib/restore.go index fcaba86cc78..6f945973ab9 100755 --- a/tests/e2e/lib/restore.go +++ b/tests/e2e/lib/restore.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/v2" velero "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" diff --git a/tests/e2e/subscription_suite_test.go b/tests/e2e/subscription_suite_test.go index 4449bd00850..268ae1eee56 100644 --- a/tests/e2e/subscription_suite_test.go +++ b/tests/e2e/subscription_suite_test.go @@ -6,8 +6,7 @@ import ( "log" "time" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/openshift/oadp-operator/tests/e2e/lib" utils "github.com/openshift/oadp-operator/tests/e2e/utils"