From 825ba39098998539f17d79accff3cae19076cb91 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Mon, 14 Feb 2022 09:30:58 -0500 Subject: [PATCH] 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 ddd2792ec04..5ad44bda2a2 100644 --- a/controllers/bsl.go +++ b/controllers/bsl.go @@ -301,7 +301,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 6b37c3828cb..de1505645ab 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, }, }, }, @@ -379,7 +392,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, @@ -516,7 +529,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 } } @@ -546,18 +559,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 @@ -1152,7 +1171,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) @@ -1181,7 +1200,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 +}