From b673f3a8e0e0070c1b86d31e7adc34e5cb1bfe57 Mon Sep 17 00:00:00 2001 From: Mateus Oliveira Date: Thu, 17 Oct 2024 15:20:11 -0300 Subject: [PATCH] fix: Remove duplication around plugins' names Signed-off-by: Mateus Oliveira --- controllers/bsl.go | 13 ++-- controllers/bsl_test.go | 114 ++++++++++++++-------------- controllers/nodeagent_test.go | 2 +- controllers/registry.go | 92 +--------------------- controllers/registry_test.go | 10 +-- controllers/validator_test.go | 16 ++-- controllers/velero_test.go | 2 +- controllers/vsl.go | 39 +++++----- controllers/vsl_test.go | 36 ++++----- pkg/credentials/credentials.go | 6 +- pkg/credentials/credentials_test.go | 4 +- 11 files changed, 122 insertions(+), 212 deletions(-) diff --git a/controllers/bsl.go b/controllers/bsl.go index 8caecfd4a6..4bab1b3067 100644 --- a/controllers/bsl.go +++ b/controllers/bsl.go @@ -47,19 +47,18 @@ func (r *DPAReconciler) ValidateBackupStorageLocations() (bool, error) { return false, fmt.Errorf("no provider specified for one of the backupstoragelocations configured") } - // TODO: cases might need some updates for IBM/Minio/noobaa switch provider { - case AWSProvider, "velero.io/aws": + case string(oadpv1alpha1.DefaultPluginAWS), "velero.io/aws": err := r.validateAWSBackupStorageLocation(*bslSpec.Velero) if err != nil { return false, err } - case AzureProvider, "velero.io/azure": + case string(oadpv1alpha1.DefaultPluginMicrosoftAzure), "velero.io/azure": err := r.validateAzureBackupStorageLocation(*bslSpec.Velero) if err != nil { return false, err } - case GCPProvider, "velero.io/gcp": + case string(oadpv1alpha1.DefaultPluginGCP), "velero.io/gcp": err := r.validateGCPBackupStorageLocation(*bslSpec.Velero) if err != nil { return false, err @@ -175,7 +174,7 @@ func (r *DPAReconciler) ReconcileBackupStorageLocations(log logr.Logger) (bool, } switch bucket.Spec.Provider { case oadpv1alpha1.AWSBucketProvider: - bsl.Spec.Provider = AWSProvider + bsl.Spec.Provider = string(oadpv1alpha1.DefaultPluginAWS) case oadpv1alpha1.AzureBucketProvider: return fmt.Errorf("azure provider not yet supported") case oadpv1alpha1.GCPBucketProvider: @@ -271,7 +270,7 @@ func (r *DPAReconciler) updateBSLFromSpec(bsl *velerov1.BackupStorageLocation, b // However, the registry deployment fails without a valid storage account key. // This logic prevents the registry pods from being deployed if Azure SP is used as an auth mechanism. registryDeployment := "True" - if bslSpec.Provider == "azure" && bslSpec.Config != nil { + if bslSpec.Provider == string(oadpv1alpha1.DefaultPluginMicrosoftAzure) && bslSpec.Config != nil { if len(bslSpec.Config["storageAccountKeyEnvVar"]) == 0 { registryDeployment = "False" } @@ -280,7 +279,7 @@ func (r *DPAReconciler) updateBSLFromSpec(bsl *velerov1.BackupStorageLocation, b // (80 for HTTP and 443 for HTTPS) before calculating a signature, and not // all S3-compatible services do this. Remove the ports here to avoid 403 // errors from mismatched signatures. - if bslSpec.Provider == "aws" && bslSpec.Config != nil { + if bslSpec.Provider == string(oadpv1alpha1.DefaultPluginAWS) && bslSpec.Config != nil { s3Url := bslSpec.Config["s3Url"] if len(s3Url) > 0 { if s3Url, err = common.StripDefaultPorts(s3Url); err == nil { diff --git a/controllers/bsl_test.go b/controllers/bsl_test.go index 91c676b563..b30e7a5f5d 100644 --- a/controllers/bsl_test.go +++ b/controllers/bsl_test.go @@ -123,7 +123,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", }, @@ -219,7 +219,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", }, @@ -256,7 +256,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", }, @@ -293,7 +293,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "", @@ -335,7 +335,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -377,7 +377,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -421,7 +421,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -467,7 +467,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "azure", + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-azure-bucket", @@ -509,7 +509,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "azure", + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-azure-bucket", @@ -549,7 +549,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "gcp", + Provider: string(oadpv1alpha1.DefaultPluginGCP), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{}, }, @@ -586,7 +586,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -632,7 +632,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -676,7 +676,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -718,7 +718,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "gcp", + Provider: string(oadpv1alpha1.DefaultPluginGCP), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-gcp-bucket", @@ -757,7 +757,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "azure", + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-azure-bucket", @@ -800,7 +800,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -821,7 +821,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { }, { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "azure", + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-azure-bucket", @@ -842,7 +842,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { }, { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "gcp", + Provider: string(oadpv1alpha1.DefaultPluginGCP), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-gcp-bucket", @@ -903,7 +903,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -1047,7 +1047,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -1068,7 +1068,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { }, { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "azure", + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-azure-bucket", @@ -1089,7 +1089,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { }, { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "gcp", + Provider: string(oadpv1alpha1.DefaultPluginGCP), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-gcp-bucket", @@ -1147,7 +1147,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -1188,7 +1188,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: DiscoverableBucket, @@ -1225,7 +1225,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "bucket", @@ -1261,7 +1261,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Profile: "default", S3ForcePathStyle: "true", @@ -1301,7 +1301,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Profile: "default", }, @@ -1341,7 +1341,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ S3ForcePathStyle: "false", }, @@ -1382,7 +1382,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ S3ForcePathStyle: "true", }, @@ -1421,7 +1421,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ S3ForcePathStyle: "true", Region: "noobaa", @@ -1462,7 +1462,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ S3ForcePathStyle: "true", }, @@ -1546,7 +1546,7 @@ func TestDPAReconciler_updateBSLFromSpec(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -1590,7 +1590,7 @@ func TestDPAReconciler_updateBSLFromSpec(t *testing.T) { }}, }, Spec: velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -1629,7 +1629,7 @@ func TestDPAReconciler_updateBSLFromSpec(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -1670,7 +1670,7 @@ func TestDPAReconciler_updateBSLFromSpec(t *testing.T) { }}, }, Spec: velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -1705,7 +1705,7 @@ func TestDPAReconciler_updateBSLFromSpec(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -1750,7 +1750,7 @@ func TestDPAReconciler_updateBSLFromSpec(t *testing.T) { }}, }, Spec: velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-aws-bucket", @@ -1819,17 +1819,17 @@ func TestDPAReconciler_ensureBackupLocationHasVeleroOrCloudStorage(t *testing.T) BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), }, }, { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "azure", + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), }, }, { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "gcp", + Provider: string(oadpv1alpha1.DefaultPluginGCP), }, }, }, @@ -1848,7 +1848,7 @@ func TestDPAReconciler_ensureBackupLocationHasVeleroOrCloudStorage(t *testing.T) BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), }, CloudStorage: &oadpv1alpha1.CloudStorageLocation{ CloudStorageRef: corev1.LocalObjectReference{ @@ -1872,32 +1872,32 @@ func TestDPAReconciler_ensureBackupLocationHasVeleroOrCloudStorage(t *testing.T) BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), }, }, { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), }, }, { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "azure", + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), }, }, { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "azure", + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), }, }, { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "gcp", + Provider: string(oadpv1alpha1.DefaultPluginGCP), }, }, { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "gcp", + Provider: string(oadpv1alpha1.DefaultPluginGCP), }, }, }, @@ -2127,7 +2127,7 @@ func TestDPAReconciler_ReconcileBackupStorageLocations(t *testing.T) { Key: "credentials", }, Name: "test-cs", - Provider: "aws", + Provider: oadpv1alpha1.AWSBucketProvider, }, } @@ -2150,7 +2150,7 @@ func TestDPAReconciler_ReconcileBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", }, @@ -2269,7 +2269,7 @@ func TestDPAReconciler_ReconcileBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", }, @@ -2305,7 +2305,7 @@ func TestDPAReconciler_ReconcileBackupStorageLocations(t *testing.T) { Namespace: "test-ns", }, Spec: velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", checksumAlgorithm: "", @@ -2364,7 +2364,7 @@ func TestDPAReconciler_ReconcileBackupStorageLocations(t *testing.T) { Namespace: "test-ns", }, Spec: oadpv1alpha1.CloudStorageSpec{ - Provider: "aws", + Provider: oadpv1alpha1.AWSBucketProvider, CreationSecret: corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "cloud-credentials", @@ -2382,7 +2382,7 @@ func TestDPAReconciler_ReconcileBackupStorageLocations(t *testing.T) { Namespace: "test-ns", }, Spec: velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Prefix: "test-prefix", @@ -2409,7 +2409,7 @@ func TestDPAReconciler_ReconcileBackupStorageLocations(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", }, @@ -2447,7 +2447,7 @@ func TestDPAReconciler_ReconcileBackupStorageLocations(t *testing.T) { Namespace: "test-ns", }, Spec: velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", checksumAlgorithm: "", @@ -2509,7 +2509,7 @@ func TestDPAReconciler_ReconcileBackupStorageLocations(t *testing.T) { Namespace: "test-ns", }, Spec: oadpv1alpha1.CloudStorageSpec{ - Provider: "aws", + Provider: oadpv1alpha1.AWSBucketProvider, CreationSecret: corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "cloud-credentials", @@ -2529,7 +2529,7 @@ func TestDPAReconciler_ReconcileBackupStorageLocations(t *testing.T) { Namespace: "test-ns", }, Spec: velerov1.BackupStorageLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "test-bucket", diff --git a/controllers/nodeagent_test.go b/controllers/nodeagent_test.go index 758f36bf0d..01398edfe0 100644 --- a/controllers/nodeagent_test.go +++ b/controllers/nodeagent_test.go @@ -1065,7 +1065,7 @@ func TestDPAReconciler_buildNodeAgentDaemonset(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: AWSProvider, + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "aws-bucket", diff --git a/controllers/registry.go b/controllers/registry.go index 87b2542721..5706b3becd 100644 --- a/controllers/registry.go +++ b/controllers/registry.go @@ -52,11 +52,7 @@ const ( // provider specific object storage const ( S3 = "s3" - Azure = "azure" GCS = "gcs" - AWSProvider = "aws" - AzureProvider = "azure" - GCPProvider = "gcp" Region = "region" Profile = "profile" S3URL = "s3Url" @@ -67,88 +63,6 @@ const ( ResourceGroup = "resourceGroup" ) -// creating skeleton for provider based env var map -var cloudProviderEnvVarMap = map[string][]corev1.EnvVar{ - "aws": { - { - Name: RegistryStorageEnvVarKey, - Value: S3, - }, - { - Name: RegistryStorageS3AccesskeyEnvVarKey, - Value: "", - }, - { - Name: RegistryStorageS3BucketEnvVarKey, - Value: "", - }, - { - Name: RegistryStorageS3RegionEnvVarKey, - Value: "", - }, - { - Name: RegistryStorageS3SecretkeyEnvVarKey, - Value: "", - }, - { - Name: RegistryStorageS3RegionendpointEnvVarKey, - Value: "", - }, - { - Name: RegistryStorageS3SkipverifyEnvVarKey, - Value: "", - }, - }, - "azure": { - { - Name: RegistryStorageEnvVarKey, - Value: Azure, - }, - { - Name: RegistryStorageAzureContainerEnvVarKey, - Value: "", - }, - { - Name: RegistryStorageAzureAccountnameEnvVarKey, - Value: "", - }, - { - Name: RegistryStorageAzureAccountkeyEnvVarKey, - Value: "", - }, - { - Name: RegistryStorageAzureAADEndpointEnvVarKey, - Value: "", - }, - { - Name: RegistryStorageAzureSPNClientIDEnvVarKey, - Value: "", - }, - { - Name: RegistryStorageAzureSPNClientSecretEnvVarKey, - Value: "", - }, - { - Name: RegistryStorageAzureSPNTenantIDEnvVarKey, - Value: "", - }, - }, - "gcp": { - { - Name: RegistryStorageEnvVarKey, - Value: GCS, - }, - { - Name: RegistryStorageGCSBucket, - Value: "", - }, - { - Name: RegistryStorageGCSKeyfile, - Value: "", - }, - }, -} - type azureCredentials struct { subscriptionID string tenantID string @@ -614,7 +528,7 @@ func (r *DPAReconciler) ReconcileRegistrySecrets(log logr.Logger) (bool, error) // Now for each of these bsl instances, create a registry secret for _, bsl := range bslList.Items { // skip for GCP as nothing is directly exposed in env vars - if bsl.Spec.Provider == GCPProvider { + if bsl.Spec.Provider == string(oadpv1alpha1.DefaultPluginGCP) { continue } secret := corev1.Secret{ @@ -683,9 +597,9 @@ func (r *DPAReconciler) patchRegistrySecret(secret *corev1.Secret, bsl *velerov1 // to get around the immutable fields provider := bsl.Spec.Provider switch provider { - case AWSProvider: + case string(oadpv1alpha1.DefaultPluginAWS): err = r.populateAWSRegistrySecret(bsl, secret) - case AzureProvider: + case string(oadpv1alpha1.DefaultPluginMicrosoftAzure): err = r.populateAzureRegistrySecret(bsl, secret) } diff --git a/controllers/registry_test.go b/controllers/registry_test.go index c511024496..9eab170e80 100644 --- a/controllers/registry_test.go +++ b/controllers/registry_test.go @@ -147,10 +147,6 @@ var ( } ) -var testAWSEnvVar = cloudProviderEnvVarMap["aws"] -var testAzureEnvVar = cloudProviderEnvVarMap["azure"] -var testGCPEnvVar = cloudProviderEnvVarMap["gcp"] - func TestDPAReconciler_getSecretNameAndKey(t *testing.T) { tests := []struct { name string @@ -164,7 +160,7 @@ func TestDPAReconciler_getSecretNameAndKey(t *testing.T) { name: "given provider secret, appropriate secret name and key are returned", bsl: &oadpv1alpha1.BackupLocation{ Velero: &velerov1.BackupStorageLocationSpec{ - Provider: AWSProvider, + Provider: string(oadpv1alpha1.DefaultPluginAWS), Credential: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "cloud-credentials-aws", @@ -192,7 +188,7 @@ func TestDPAReconciler_getSecretNameAndKey(t *testing.T) { name: "given no provider secret, appropriate secret name and key are returned", bsl: &oadpv1alpha1.BackupLocation{ Velero: &velerov1.BackupStorageLocationSpec{ - Provider: AWSProvider, + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "aws-region", S3URL: "https://sr-url-aws-domain.com", @@ -446,7 +442,7 @@ func TestDPAReconciler_populateAzureRegistrySecret(t *testing.T) { Namespace: "test-ns", }, Spec: velerov1.BackupStorageLocationSpec{ - Provider: AzureProvider, + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "azure-bucket", diff --git a/controllers/validator_test.go b/controllers/validator_test.go index d7bad3ecec..0ec95b3326 100644 --- a/controllers/validator_test.go +++ b/controllers/validator_test.go @@ -381,7 +381,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &v1.VolumeSnapshotLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ AWSRegion: "us-east-1", }, @@ -429,7 +429,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &v1.VolumeSnapshotLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ AWSRegion: "us-east-1", }, @@ -470,7 +470,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &v1.VolumeSnapshotLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ AWSRegion: "us-east-1", }, @@ -494,7 +494,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) { Namespace: "test-ns", }, Spec: oadpv1alpha1.CloudStorageSpec{ - Provider: "aws", + Provider: oadpv1alpha1.AWSBucketProvider, }, }, }, @@ -528,7 +528,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &v1.VolumeSnapshotLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ AWSRegion: "us-east-1", }, @@ -552,7 +552,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) { Namespace: "test-ns", }, Spec: oadpv1alpha1.CloudStorageSpec{ - Provider: "aws", + Provider: oadpv1alpha1.AWSBucketProvider, }, }, &corev1.Secret{ @@ -860,7 +860,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &v1.VolumeSnapshotLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ AWSRegion: "us-east-1", }, @@ -1038,7 +1038,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &v1.VolumeSnapshotLocationSpec{ - Provider: "aws", + Provider: string(oadpv1alpha1.DefaultPluginAWS), Credential: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "custom-vsl-credentials", diff --git a/controllers/velero_test.go b/controllers/velero_test.go index 489b2a7de3..3b806875f0 100644 --- a/controllers/velero_test.go +++ b/controllers/velero_test.go @@ -1490,7 +1490,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { BackupLocations: []oadpv1alpha1.BackupLocation{ { Velero: &velerov1.BackupStorageLocationSpec{ - Provider: AWSProvider, + Provider: string(oadpv1alpha1.DefaultPluginAWS), StorageType: velerov1.StorageType{ ObjectStorage: &velerov1.ObjectStorageLocation{ Bucket: "aws-bucket", diff --git a/controllers/vsl.go b/controllers/vsl.go index 682500393e..aec2e86e3a 100644 --- a/controllers/vsl.go +++ b/controllers/vsl.go @@ -56,7 +56,7 @@ func (r *DPAReconciler) LabelVSLSecrets(log logr.Logger) (bool, error) { for _, vsl := range dpa.Spec.SnapshotLocations { provider := strings.TrimPrefix(vsl.Velero.Provider, veleroIOPrefix) switch provider { - case "aws": + case string(oadpv1alpha1.DefaultPluginAWS): if vsl.Velero.Credential != nil { secretName := vsl.Velero.Credential.Name _, err := r.UpdateCredentialsSecretLabels(secretName, dpa.Namespace, dpa.Name) @@ -70,7 +70,7 @@ func (r *DPAReconciler) LabelVSLSecrets(log logr.Logger) (bool, error) { return false, err } } - case "gcp": + case string(oadpv1alpha1.DefaultPluginGCP): if vsl.Velero.Credential != nil { secretName := vsl.Velero.Credential.Name _, err := r.UpdateCredentialsSecretLabels(secretName, dpa.Namespace, dpa.Name) @@ -84,7 +84,7 @@ func (r *DPAReconciler) LabelVSLSecrets(log logr.Logger) (bool, error) { return false, err } } - case "azure": + case string(oadpv1alpha1.DefaultPluginMicrosoftAzure): if vsl.Velero.Credential != nil { secretName := vsl.Velero.Credential.Name _, err := r.UpdateCredentialsSecretLabels(secretName, dpa.Namespace, dpa.Name) @@ -116,62 +116,63 @@ func (r *DPAReconciler) ValidateVolumeSnapshotLocations() (bool, error) { } // check for valid provider - if vslSpec.Velero.Provider != AWSProvider && vslSpec.Velero.Provider != GCPProvider && - vslSpec.Velero.Provider != AzureProvider { - return false, fmt.Errorf("DPA %s.provider %s is invalid: only %s, %s and %s are supported", veleroVSLYAMLPath, vslSpec.Velero.Provider, AWSProvider, GCPProvider, AzureProvider) + if vslSpec.Velero.Provider != string(oadpv1alpha1.DefaultPluginAWS) && + vslSpec.Velero.Provider != string(oadpv1alpha1.DefaultPluginGCP) && + vslSpec.Velero.Provider != string(oadpv1alpha1.DefaultPluginMicrosoftAzure) { + return false, fmt.Errorf("DPA %s.provider %s is invalid: only %s, %s and %s are supported", veleroVSLYAMLPath, vslSpec.Velero.Provider, string(oadpv1alpha1.DefaultPluginAWS), string(oadpv1alpha1.DefaultPluginGCP), string(oadpv1alpha1.DefaultPluginMicrosoftAzure)) } //AWS - if vslSpec.Velero.Provider == AWSProvider { + if vslSpec.Velero.Provider == string(oadpv1alpha1.DefaultPluginAWS) { //in AWS, region is a required field if len(vslSpec.Velero.Config[AWSRegion]) == 0 { - return false, fmt.Errorf("region for %s VSL in DPA %s.config is not configured, please ensure a region is configured", AWSProvider, veleroVSLYAMLPath) + return false, fmt.Errorf("region for %s VSL in DPA %s.config is not configured, please ensure a region is configured", string(oadpv1alpha1.DefaultPluginAWS), veleroVSLYAMLPath) } // check for invalid config key for key := range vslSpec.Velero.Config { valid := validAWSKeys[key] if !valid { - return false, fmt.Errorf("DPA %s.config key %s is not a valid %s config key", veleroVSLYAMLPath, key, AWSProvider) + return false, fmt.Errorf("DPA %s.config key %s is not a valid %s config key", veleroVSLYAMLPath, key, string(oadpv1alpha1.DefaultPluginAWS)) } } //checking the aws plugin, if not present, throw warning message - if !containsPlugin(dpa.Spec.Configuration.Velero.DefaultPlugins, AWSProvider) { - return false, fmt.Errorf("to use VSL for %s specified in DPA %s, %s plugin must be present in %s.defaultPlugins", AWSProvider, vslYAMLPath, AWSProvider, veleroConfigYAMLPath) + if !containsPlugin(dpa.Spec.Configuration.Velero.DefaultPlugins, string(oadpv1alpha1.DefaultPluginAWS)) { + return false, fmt.Errorf("to use VSL for %s specified in DPA %s, %s plugin must be present in %s.defaultPlugins", string(oadpv1alpha1.DefaultPluginAWS), vslYAMLPath, string(oadpv1alpha1.DefaultPluginAWS), veleroConfigYAMLPath) } } //GCP - if vslSpec.Velero.Provider == GCPProvider { + if vslSpec.Velero.Provider == string(oadpv1alpha1.DefaultPluginGCP) { // check for invalid config key for key := range vslSpec.Velero.Config { valid := validGCPKeys[key] if !valid { - return false, fmt.Errorf("DPA %s.config key %s is not a valid %s config key", veleroVSLYAMLPath, key, GCPProvider) + return false, fmt.Errorf("DPA %s.config key %s is not a valid %s config key", veleroVSLYAMLPath, key, string(oadpv1alpha1.DefaultPluginGCP)) } } //checking the gcp plugin, if not present, throw warning message - if !containsPlugin(dpa.Spec.Configuration.Velero.DefaultPlugins, "gcp") { + if !containsPlugin(dpa.Spec.Configuration.Velero.DefaultPlugins, string(oadpv1alpha1.DefaultPluginGCP)) { - return false, fmt.Errorf("to use VSL for %s specified in DPA %s, %s plugin must be present in %s.defaultPlugins", GCPProvider, vslYAMLPath, GCPProvider, veleroConfigYAMLPath) + return false, fmt.Errorf("to use VSL for %s specified in DPA %s, %s plugin must be present in %s.defaultPlugins", string(oadpv1alpha1.DefaultPluginGCP), vslYAMLPath, string(oadpv1alpha1.DefaultPluginGCP), veleroConfigYAMLPath) } } //Azure - if vslSpec.Velero.Provider == AzureProvider { + if vslSpec.Velero.Provider == string(oadpv1alpha1.DefaultPluginMicrosoftAzure) { // check for invalid config key for key := range vslSpec.Velero.Config { valid := validAzureKeys[key] if !valid { - return false, fmt.Errorf("DPA %s.config key %s is not a valid %s config key", veleroVSLYAMLPath, key, AzureProvider) + return false, fmt.Errorf("DPA %s.config key %s is not a valid %s config key", veleroVSLYAMLPath, key, string(oadpv1alpha1.DefaultPluginMicrosoftAzure)) } } //checking the azure plugin, if not present, throw warning message - if !containsPlugin(dpa.Spec.Configuration.Velero.DefaultPlugins, "azure") { + if !containsPlugin(dpa.Spec.Configuration.Velero.DefaultPlugins, string(oadpv1alpha1.DefaultPluginMicrosoftAzure)) { - return false, fmt.Errorf("to use VSL for %s specified in DPA %s, %s plugin must be present in %s.defaultPlugins", AzureProvider, vslYAMLPath, AzureProvider, veleroConfigYAMLPath) + return false, fmt.Errorf("to use VSL for %s specified in DPA %s, %s plugin must be present in %s.defaultPlugins", string(oadpv1alpha1.DefaultPluginMicrosoftAzure), vslYAMLPath, string(oadpv1alpha1.DefaultPluginMicrosoftAzure), veleroConfigYAMLPath) } } diff --git a/controllers/vsl_test.go b/controllers/vsl_test.go index 7be09a1b34..461e2402e9 100644 --- a/controllers/vsl_test.go +++ b/controllers/vsl_test.go @@ -100,7 +100,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AWSProvider, + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", }, @@ -138,7 +138,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AWSProvider, + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", }, @@ -171,7 +171,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AWSProvider, + Provider: string(oadpv1alpha1.DefaultPluginAWS), }, }, }, @@ -205,7 +205,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AWSProvider, + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", AWSProfile: "test-profile", @@ -239,7 +239,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AWSProvider, + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", "invalid-test": "foo", @@ -279,7 +279,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: GCPProvider, + Provider: string(oadpv1alpha1.DefaultPluginGCP), }, }, }, @@ -309,7 +309,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: GCPProvider, + Provider: string(oadpv1alpha1.DefaultPluginGCP), }, }, }, @@ -343,7 +343,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: GCPProvider, + Provider: string(oadpv1alpha1.DefaultPluginGCP), Config: map[string]string{ GCPSnapshotLocation: "test-location", }, @@ -380,7 +380,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: GCPProvider, + Provider: string(oadpv1alpha1.DefaultPluginGCP), Config: map[string]string{ GCPProject: "alt-project", }, @@ -413,7 +413,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: GCPProvider, + Provider: string(oadpv1alpha1.DefaultPluginGCP), Config: map[string]string{ "invalid-test": "foo", }, @@ -452,7 +452,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AzureProvider, + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), }, }, }, @@ -482,7 +482,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AzureProvider, + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), }, }, }, @@ -516,7 +516,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AzureProvider, + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), Config: map[string]string{ AzureApiTimeout: "5m", }, @@ -553,7 +553,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AzureProvider, + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), Config: map[string]string{ ResourceGroup: "test-rg", }, @@ -590,7 +590,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AzureProvider, + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), Config: map[string]string{ AzureSubscriptionId: "test-alt-sub", }, @@ -627,7 +627,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AzureProvider, + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), Config: map[string]string{ AzureIncremental: "false", }, @@ -660,7 +660,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AzureProvider, + Provider: string(oadpv1alpha1.DefaultPluginMicrosoftAzure), Config: map[string]string{ "invalid-test": "foo", }, @@ -732,7 +732,7 @@ func TestDPAReconciler_ReconcileVolumeSnapshotLocations(t *testing.T) { SnapshotLocations: []oadpv1alpha1.SnapshotLocation{ { Velero: &velerov1.VolumeSnapshotLocationSpec{ - Provider: AWSProvider, + Provider: string(oadpv1alpha1.DefaultPluginAWS), Config: map[string]string{ Region: "us-east-1", }, diff --git a/pkg/credentials/credentials.go b/pkg/credentials/credentials.go index d00d1c4b66..69f129e296 100644 --- a/pkg/credentials/credentials.go +++ b/pkg/credentials/credentials.go @@ -336,16 +336,16 @@ func BslUsesShortLivedCredential(bls []oadpv1alpha1.BackupLocation, namespace st func SecretContainsShortLivedCredential(secretName, secretKey, provider, namespace string, config map[string]string) (bool, error) { switch provider { - case "aws": + case string(oadpv1alpha1.DefaultPluginAWS): // AWS credentials short lived are determined by enableSharedConfig // if enableSharedConfig is not set, then we assume it is not short lived // if enableSharedConfig is set, then we assume it is short lived // Alternatively, we can check if the secret contains a session token // TODO: check if secret contains session token return false, nil - case "gcp": + case string(oadpv1alpha1.DefaultPluginGCP): return gcpSecretAccountTypeIsShortLived(secretName, secretKey, namespace) - case "azure": + case string(oadpv1alpha1.DefaultPluginMicrosoftAzure): // TODO: check if secret contains session token return false, nil } diff --git a/pkg/credentials/credentials_test.go b/pkg/credentials/credentials_test.go index 83d276e2b7..ed47e6c8f5 100644 --- a/pkg/credentials/credentials_test.go +++ b/pkg/credentials/credentials_test.go @@ -398,7 +398,7 @@ func TestSecretContainsShortLivedCredential(t *testing.T) { "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/SERVICE_ACCOUNT_EMAIL" } `, - provider: "gcp", + provider: string(oadpv1alpha1.DefaultPluginGCP), config: nil, }, want: false, @@ -418,7 +418,7 @@ func TestSecretContainsShortLivedCredential(t *testing.T) { } } `, - provider: "gcp", + provider: string(oadpv1alpha1.DefaultPluginGCP), config: nil, }, want: true,