From 0f1ea5334ef686c9bbed2306aa85de12198d78eb Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Mon, 8 Nov 2021 12:00:21 -0500 Subject: [PATCH 01/10] Adding profile support for registry --- controllers/registry.go | 82 ++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/controllers/registry.go b/controllers/registry.go index e49e93bbf0..26e3f46fab 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -60,6 +60,7 @@ const ( AzureProvider = "azure" GCPProvider = "gcp" Region = "region" + Profile = "profile" S3URL = "s3Url" InsecureSkipTLSVerify = "insecureSkipTLSVerify" StorageAccount = "storageAccount" @@ -383,9 +384,12 @@ func (r *VeleroReconciler) getAWSRegistryEnvVars(bsl *velerov1.BackupStorageLoca r.Log.Info(fmt.Sprintf("Error fetching provider secret %s for backupstoragelocation %s/%s", secretName, bsl.Namespace, bsl.Name)) return nil, err } - + awsProfile := "default" + if value, exists := bsl.Spec.Config[Profile]; exists { + awsProfile = value + } // parse the secret and get aws access_key and aws secret_key - AWSAccessKey, AWSSecretKey, err := r.parseAWSSecret(secret, secretKey) + AWSAccessKey, AWSSecretKey, err := r.parseAWSSecret(secret, secretKey, awsProfile) if err != nil { r.Log.Info(fmt.Sprintf("Error parsing provider secret %s for backupstoragelocation %s/%s", secretName, bsl.Namespace, bsl.Name)) return nil, err @@ -502,7 +506,7 @@ func (r *VeleroReconciler) getSecretNameAndKey(credential *corev1.SecretKeySelec return secretName, secretKey } -func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string) (string, string, error) { +func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string, awsProfile string) (string, string, error) { AWSAccessKey, AWSSecretKey := "", "" // this logic only supports single profile presence in the aws credentials file @@ -519,44 +523,56 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string if err != nil { return AWSAccessKey, AWSSecretKey, errors.New("parseAWSSecret faulty regex: awsSecretKeyRegex") } - for _, line := range splitString { + for index, line := range splitString { if line == "" { continue } if keyNameRegex.MatchString(line) { - continue - } - // check for access key - matchedAccessKey := awsAccessKeyRegex.MatchString(line) - - if err != nil { - r.Log.Info("Error finding access key id for the supplied AWS credential") - return AWSAccessKey, AWSSecretKey, err - } - - if matchedAccessKey { - cleanedLine := strings.ReplaceAll(line, " ", "") - splitLine := strings.Split(cleanedLine, "=") - if len(splitLine) != 2 { - r.Log.Info("Could not parse secret for AWS Access key") - return AWSAccessKey, AWSSecretKey, errors.New("secret parsing error") + awsProfileRegex, err := regexp.Compile(`\[|\]`) + if err != nil { + return AWSAccessKey, AWSSecretKey, errors.New("parseAWSSecret faulty regex: keyNameRegex") } - AWSAccessKey = splitLine[1] - continue - } + cleanedLine := strings.ReplaceAll(line, " ", "") + parsedProfile := awsProfileRegex.ReplaceAllString(cleanedLine, "") + if parsedProfile == awsProfile { + // check for access key + for _, profLine := range splitString[index+1:] { + if profLine == "" { + continue + } + matchedAccessKey := awsAccessKeyRegex.MatchString(profLine) - // check for secret key - matchedSecretKey := awsSecretKeyRegex.MatchString(line) + if err != nil { + r.Log.Info("Error finding access key id for the supplied AWS credential") + return AWSAccessKey, AWSSecretKey, err + } - if matchedSecretKey { - cleanedLine := strings.ReplaceAll(line, " ", "") - splitLine := strings.Split(cleanedLine, "=") - if len(splitLine) != 2 { - r.Log.Info("Could not parse secret for AWS Secret key") - return AWSAccessKey, AWSSecretKey, errors.New("secret parsing error") + if matchedAccessKey { + cleanedLine := strings.ReplaceAll(profLine, " ", "") + splitLine := strings.Split(cleanedLine, "=") + if len(splitLine) != 2 { + r.Log.Info("Could not parse secret for AWS Access key") + return AWSAccessKey, AWSSecretKey, errors.New("secret parsing error") + } + AWSAccessKey = splitLine[1] + continue + } + + // check for secret key + matchedSecretKey := awsSecretKeyRegex.MatchString(profLine) + + if matchedSecretKey { + cleanedLine := strings.ReplaceAll(profLine, " ", "") + splitLine := strings.Split(cleanedLine, "=") + if len(splitLine) != 2 { + r.Log.Info("Could not parse secret for AWS Secret key") + return AWSAccessKey, AWSSecretKey, errors.New("secret parsing error") + } + AWSSecretKey = splitLine[1] + continue + } + } } - AWSSecretKey = splitLine[1] - continue } } if AWSAccessKey == "" { From 0accdad8ac78969770d1efe26df05193f8e16997 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Mon, 8 Nov 2021 12:25:06 -0500 Subject: [PATCH 02/10] Checking index for profile --- controllers/registry.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controllers/registry.go b/controllers/registry.go index 26e3f46fab..0e06b0de61 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -536,6 +536,9 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string parsedProfile := awsProfileRegex.ReplaceAllString(cleanedLine, "") if parsedProfile == awsProfile { // check for access key + if index+1 >= len(splitString) { + break + } for _, profLine := range splitString[index+1:] { if profLine == "" { continue From 20924ef5d9755730bfa46131cc5b44eacb400ed3 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Mon, 8 Nov 2021 12:40:31 -0500 Subject: [PATCH 03/10] Updating comments --- config/manager/kustomization.yaml | 4 ++-- controllers/registry.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 3a9e916204..ee94c7d92f 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -12,5 +12,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: controller - newName: quay.io/konveyor/oadp-operator - newTag: latest + newName: quay.io/deepakraj1997/oadp-operator + newTag: 0.4.1 diff --git a/controllers/registry.go b/controllers/registry.go index 0e06b0de61..c48d46ca4a 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -535,7 +535,7 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string cleanedLine := strings.ReplaceAll(line, " ", "") parsedProfile := awsProfileRegex.ReplaceAllString(cleanedLine, "") if parsedProfile == awsProfile { - // check for access key + // check for end of arr if index+1 >= len(splitString) { break } @@ -549,7 +549,7 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string r.Log.Info("Error finding access key id for the supplied AWS credential") return AWSAccessKey, AWSSecretKey, err } - + // check for access key if matchedAccessKey { cleanedLine := strings.ReplaceAll(profLine, " ", "") splitLine := strings.Split(cleanedLine, "=") From b2ce608a1f08947ded4eb6f4c484025b2c665054 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Mon, 8 Nov 2021 12:41:30 -0500 Subject: [PATCH 04/10] Rebasing with upstream --- config/manager/kustomization.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index ee94c7d92f..3a9e916204 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -12,5 +12,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: controller - newName: quay.io/deepakraj1997/oadp-operator - newTag: 0.4.1 + newName: quay.io/konveyor/oadp-operator + newTag: latest From 131eadc167e34ceef35d91298e2769070f3374b3 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Mon, 8 Nov 2021 12:49:24 -0500 Subject: [PATCH 05/10] Adding registry envs. --- controllers/registry.go | 13 +++++++++++++ controllers/registry_test.go | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/controllers/registry.go b/controllers/registry.go index c48d46ca4a..061bf0c7b0 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -37,6 +37,7 @@ const ( RegistryStorageS3AccesskeyEnvVarKey = "REGISTRY_STORAGE_S3_ACCESSKEY" RegistryStorageS3BucketEnvVarKey = "REGISTRY_STORAGE_S3_BUCKET" RegistryStorageS3RegionEnvVarKey = "REGISTRY_STORAGE_S3_REGION" + RegistryStorageS3ProfileEnvVarKey = "REGISTRY_STORAGE_S3_PROFILE" RegistryStorageS3SecretkeyEnvVarKey = "REGISTRY_STORAGE_S3_SECRETKEY" RegistryStorageS3RegionendpointEnvVarKey = "REGISTRY_STORAGE_S3_REGIONENDPOINT" RegistryStorageS3RootdirectoryEnvVarKey = "REGISTRY_STORAGE_S3_ROOTDIRECTORY" @@ -86,6 +87,10 @@ var cloudProviderEnvVarMap = map[string][]corev1.EnvVar{ Name: RegistryStorageS3RegionEnvVarKey, Value: "", }, + { + Name: RegistryStorageS3ProfileEnvVarKey, + Value: "", + }, { Name: RegistryStorageS3SecretkeyEnvVarKey, Value: "", @@ -408,6 +413,14 @@ func (r *VeleroReconciler) getAWSRegistryEnvVars(bsl *velerov1.BackupStorageLoca awsEnvVars[i].Value = bsl.Spec.Config[Region] } + if awsEnvVars[i].Name == RegistryStorageS3ProfileEnvVarKey { + if value, exists := bsl.Spec.Config[Profile]; exists { + awsEnvVars[i].Value = value + } else { + awsEnvVars[i].Value = "default" + } + } + if awsEnvVars[i].Name == RegistryStorageS3SecretkeyEnvVarKey { awsEnvVars[i].Value = AWSSecretKey } diff --git a/controllers/registry_test.go b/controllers/registry_test.go index bbf171aeb1..8631e8f091 100644 --- a/controllers/registry_test.go +++ b/controllers/registry_test.go @@ -319,6 +319,10 @@ func TestVeleroReconciler_buildRegistryDeployment(t *testing.T) { Name: RegistryStorageS3RegionEnvVarKey, Value: "aws-region", }, + { + Name: RegistryStorageS3ProfileEnvVarKey, + Value: "default", + }, { Name: RegistryStorageS3SecretkeyEnvVarKey, Value: testSecretAccessKey, @@ -500,6 +504,7 @@ func TestVeleroReconciler_getAWSRegistryEnvVars(t *testing.T) { Region: "aws-region", S3URL: "https://sr-url-aws-domain.com", InsecureSkipTLSVerify: "false", + Profile: "test-profile", }, }, }, @@ -546,6 +551,10 @@ func TestVeleroReconciler_getAWSRegistryEnvVars(t *testing.T) { Name: RegistryStorageS3RegionEnvVarKey, Value: "aws-region", }, + { + Name: RegistryStorageS3ProfileEnvVarKey, + Value: "default", + }, { Name: RegistryStorageS3SecretkeyEnvVarKey, Value: testSecretAccessKey, From fae562cbfc932c065cbab2eeff0b274419c602ed Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Mon, 8 Nov 2021 14:25:42 -0500 Subject: [PATCH 06/10] Update test cases --- controllers/registry.go | 2 ++ controllers/registry_test.go | 11 +++++++++-- tests/e2e/apps.go | 2 +- tests/e2e/registry_helpers.go | 10 +++++----- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/controllers/registry.go b/controllers/registry.go index 061bf0c7b0..0975cd64ca 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -547,6 +547,7 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string } cleanedLine := strings.ReplaceAll(line, " ", "") parsedProfile := awsProfileRegex.ReplaceAllString(cleanedLine, "") + fmt.Println(parsedProfile, awsProfile, parsedProfile == awsProfile) if parsedProfile == awsProfile { // check for end of arr if index+1 >= len(splitString) { @@ -556,6 +557,7 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string if profLine == "" { continue } + fmt.Println(profLine) matchedAccessKey := awsAccessKeyRegex.MatchString(profLine) if err != nil { diff --git a/controllers/registry_test.go b/controllers/registry_test.go index 8631e8f091..f28acac4f0 100644 --- a/controllers/registry_test.go +++ b/controllers/registry_test.go @@ -49,6 +49,7 @@ func getFakeClientFromObjectsForRegistry(objs ...client.Object) (client.WithWatc } const ( + testProfile = "someProfile" testAccessKey = "someAccessKey" testSecretAccessKey = "someSecretAccessKey" testStoragekey = "someStorageKey" @@ -59,7 +60,11 @@ var ( secretData = map[string][]byte{ "cloud": []byte("[default]" + "\n" + "aws_access_key_id=" + testAccessKey + "\n" + - "aws_secret_access_key=" + testSecretAccessKey), + "aws_secret_access_key=" + testSecretAccessKey + + "\n[test-profile]\n" + + "aws_access_key_id=" + testAccessKey + "\n" + + "aws_secret_access_key=" + testSecretAccessKey, + ), } secretAzureData = map[string][]byte{ "cloud": []byte("[default]" + "\n" + @@ -483,6 +488,7 @@ func TestVeleroReconciler_getAWSRegistryEnvVars(t *testing.T) { name string bsl *velerov1.BackupStorageLocation wantRegistryContainerEnvVar []corev1.EnvVar + wantProfile string secret *corev1.Secret wantErr bool }{ @@ -515,6 +521,7 @@ func TestVeleroReconciler_getAWSRegistryEnvVars(t *testing.T) { }, Data: secretData, }, + wantProfile: "test-profile", }, } for _, tt := range tests { @@ -553,7 +560,7 @@ func TestVeleroReconciler_getAWSRegistryEnvVars(t *testing.T) { }, { Name: RegistryStorageS3ProfileEnvVarKey, - Value: "default", + Value: tt.wantProfile, }, { Name: RegistryStorageS3SecretkeyEnvVarKey, diff --git a/tests/e2e/apps.go b/tests/e2e/apps.go index c139777098..456ca62fb4 100755 --- a/tests/e2e/apps.go +++ b/tests/e2e/apps.go @@ -102,7 +102,7 @@ func areApplicationPodsRunning(namespace string) wait.ConditionFunc { if len(condition.Message) > 0 { ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("Pod not running with condition: %s\n", condition.Message))) } - } + } return false, nil } } diff --git a/tests/e2e/registry_helpers.go b/tests/e2e/registry_helpers.go index c2ae00651a..364b18b6f0 100755 --- a/tests/e2e/registry_helpers.go +++ b/tests/e2e/registry_helpers.go @@ -22,21 +22,21 @@ func areRegistryDeploymentsAvailable(namespace string) wait.ConditionFunc { LabelSelector: "app.kubernetes.io/component=Registry", } // get pods in the oadp-operator-e2e namespace with label selector - deploymentList, err := client.AppsV1().Deployments(namespace).List(context.TODO(),registryListOptions) + deploymentList, err := client.AppsV1().Deployments(namespace).List(context.TODO(), registryListOptions) if err != nil { return false, nil } if len(deploymentList.Items) == 0 { - return false, fmt.Errorf("registry deployment is not yet created") + return false, fmt.Errorf("registry deployment is not yet created") } // loop until deployment status is 'Running' or timeout for _, deploymentInfo := range deploymentList.Items { for _, conditions := range deploymentInfo.Status.Conditions { - if conditions.Type == appsv1.DeploymentAvailable && conditions.Status != corev1.ConditionTrue{ - return false, fmt.Errorf("registry deployment is not yet available.\nconditions: %v", deploymentInfo.Status.Conditions) + if conditions.Type == appsv1.DeploymentAvailable && conditions.Status != corev1.ConditionTrue { + return false, fmt.Errorf("registry deployment is not yet available.\nconditions: %v", deploymentInfo.Status.Conditions) } } } return true, nil } -} \ No newline at end of file +} From 59b9c0d3893478ece09af02830098bf42d50f3e9 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Mon, 8 Nov 2021 20:41:53 -0500 Subject: [PATCH 07/10] Removing debug statements --- controllers/registry.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/controllers/registry.go b/controllers/registry.go index 0975cd64ca..061bf0c7b0 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -547,7 +547,6 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string } cleanedLine := strings.ReplaceAll(line, " ", "") parsedProfile := awsProfileRegex.ReplaceAllString(cleanedLine, "") - fmt.Println(parsedProfile, awsProfile, parsedProfile == awsProfile) if parsedProfile == awsProfile { // check for end of arr if index+1 >= len(splitString) { @@ -557,7 +556,6 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string if profLine == "" { continue } - fmt.Println(profLine) matchedAccessKey := awsAccessKeyRegex.MatchString(profLine) if err != nil { From 7d32a19444498c36fa369b00f634ef5b907ecf88 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Thu, 11 Nov 2021 02:14:16 -0500 Subject: [PATCH 08/10] Deleting registry envs --- controllers/registry.go | 13 ------------- controllers/registry_test.go | 8 -------- 2 files changed, 21 deletions(-) diff --git a/controllers/registry.go b/controllers/registry.go index 061bf0c7b0..c48d46ca4a 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -37,7 +37,6 @@ const ( RegistryStorageS3AccesskeyEnvVarKey = "REGISTRY_STORAGE_S3_ACCESSKEY" RegistryStorageS3BucketEnvVarKey = "REGISTRY_STORAGE_S3_BUCKET" RegistryStorageS3RegionEnvVarKey = "REGISTRY_STORAGE_S3_REGION" - RegistryStorageS3ProfileEnvVarKey = "REGISTRY_STORAGE_S3_PROFILE" RegistryStorageS3SecretkeyEnvVarKey = "REGISTRY_STORAGE_S3_SECRETKEY" RegistryStorageS3RegionendpointEnvVarKey = "REGISTRY_STORAGE_S3_REGIONENDPOINT" RegistryStorageS3RootdirectoryEnvVarKey = "REGISTRY_STORAGE_S3_ROOTDIRECTORY" @@ -87,10 +86,6 @@ var cloudProviderEnvVarMap = map[string][]corev1.EnvVar{ Name: RegistryStorageS3RegionEnvVarKey, Value: "", }, - { - Name: RegistryStorageS3ProfileEnvVarKey, - Value: "", - }, { Name: RegistryStorageS3SecretkeyEnvVarKey, Value: "", @@ -413,14 +408,6 @@ func (r *VeleroReconciler) getAWSRegistryEnvVars(bsl *velerov1.BackupStorageLoca awsEnvVars[i].Value = bsl.Spec.Config[Region] } - if awsEnvVars[i].Name == RegistryStorageS3ProfileEnvVarKey { - if value, exists := bsl.Spec.Config[Profile]; exists { - awsEnvVars[i].Value = value - } else { - awsEnvVars[i].Value = "default" - } - } - if awsEnvVars[i].Name == RegistryStorageS3SecretkeyEnvVarKey { awsEnvVars[i].Value = AWSSecretKey } diff --git a/controllers/registry_test.go b/controllers/registry_test.go index f28acac4f0..ccf0c7d4f7 100644 --- a/controllers/registry_test.go +++ b/controllers/registry_test.go @@ -324,10 +324,6 @@ func TestVeleroReconciler_buildRegistryDeployment(t *testing.T) { Name: RegistryStorageS3RegionEnvVarKey, Value: "aws-region", }, - { - Name: RegistryStorageS3ProfileEnvVarKey, - Value: "default", - }, { Name: RegistryStorageS3SecretkeyEnvVarKey, Value: testSecretAccessKey, @@ -558,10 +554,6 @@ func TestVeleroReconciler_getAWSRegistryEnvVars(t *testing.T) { Name: RegistryStorageS3RegionEnvVarKey, Value: "aws-region", }, - { - Name: RegistryStorageS3ProfileEnvVarKey, - Value: tt.wantProfile, - }, { Name: RegistryStorageS3SecretkeyEnvVarKey, Value: testSecretAccessKey, From 911b0ad464e198af639a5dd4e001ac736cca2155 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Thu, 11 Nov 2021 03:04:08 -0500 Subject: [PATCH 09/10] Adding error check for profile --- controllers/registry.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/controllers/registry.go b/controllers/registry.go index c48d46ca4a..f91bcf12d6 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -506,10 +506,9 @@ func (r *VeleroReconciler) getSecretNameAndKey(credential *corev1.SecretKeySelec return secretName, secretKey } -func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string, awsProfile string) (string, string, error) { +func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string, matchProfile string) (string, string, error) { - AWSAccessKey, AWSSecretKey := "", "" - // this logic only supports single profile presence in the aws credentials file + AWSAccessKey, AWSSecretKey, AWSProfile := "", "", "" splitString := strings.Split(string(secret.Data[secretKey]), "\n") keyNameRegex, err := regexp.Compile(`\[.*\]`) //ignore lines such as [default] if err != nil { @@ -534,7 +533,8 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string } cleanedLine := strings.ReplaceAll(line, " ", "") parsedProfile := awsProfileRegex.ReplaceAllString(cleanedLine, "") - if parsedProfile == awsProfile { + if parsedProfile == matchProfile { + AWSProfile = matchProfile // check for end of arr if index+1 >= len(splitString) { break @@ -578,6 +578,10 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string } } } + if AWSProfile == "" { + r.Log.Info("Error finding AWS Profile for the supplied AWS credential") + return AWSAccessKey, AWSSecretKey, errors.New("Error finding AWS Profile for the supplied AWS credential") + } if AWSAccessKey == "" { r.Log.Info("Error finding access key id for the supplied AWS credential") return AWSAccessKey, AWSSecretKey, errors.New("error finding access key id for the supplied AWS credential") From 29460ff56103817e8c5f717702e47c6c38c827d9 Mon Sep 17 00:00:00 2001 From: Deepak Raj D S Date: Mon, 15 Nov 2021 02:30:52 -0500 Subject: [PATCH 10/10] Removing old comments --- controllers/registry.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/registry.go b/controllers/registry.go index f91bcf12d6..05baf95f56 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -508,9 +508,9 @@ func (r *VeleroReconciler) getSecretNameAndKey(credential *corev1.SecretKeySelec func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string, matchProfile string) (string, string, error) { - AWSAccessKey, AWSSecretKey, AWSProfile := "", "", "" + AWSAccessKey, AWSSecretKey, profile := "", "", "" splitString := strings.Split(string(secret.Data[secretKey]), "\n") - keyNameRegex, err := regexp.Compile(`\[.*\]`) //ignore lines such as [default] + keyNameRegex, err := regexp.Compile(`\[.*\]`) if err != nil { return AWSAccessKey, AWSSecretKey, errors.New("parseAWSSecret faulty regex: keyNameRegex") } @@ -534,7 +534,7 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string cleanedLine := strings.ReplaceAll(line, " ", "") parsedProfile := awsProfileRegex.ReplaceAllString(cleanedLine, "") if parsedProfile == matchProfile { - AWSProfile = matchProfile + profile = matchProfile // check for end of arr if index+1 >= len(splitString) { break @@ -578,7 +578,7 @@ func (r *VeleroReconciler) parseAWSSecret(secret corev1.Secret, secretKey string } } } - if AWSProfile == "" { + if profile == "" { r.Log.Info("Error finding AWS Profile for the supplied AWS credential") return AWSAccessKey, AWSSecretKey, errors.New("Error finding AWS Profile for the supplied AWS credential") }