@@ -49,21 +49,38 @@ func getFakeClientFromObjectsForRegistry(objs ...client.Object) (client.WithWatc
49
49
}
50
50
51
51
const (
52
- testProfile = "someProfile"
53
- testAccessKey = "someAccessKey"
54
- testSecretAccessKey = "someSecretAccessKey"
55
- testStoragekey = "someStorageKey"
56
- testCloudName = "someCloudName"
52
+ testProfile = "someProfile"
53
+ testAccessKey = "someAccessKey"
54
+ testSecretAccessKey = "someSecretAccessKey"
55
+ testStoragekey = "someStorageKey"
56
+ testCloudName = "someCloudName"
57
+ testBslProfile = "bslProfile"
58
+ testBslAccessKey = "bslAccessKey"
59
+ testBslSecretAccessKey = "bslSecretAccessKey"
57
60
)
58
61
59
62
var (
60
63
secretData = map [string ][]byte {
61
- "cloud" : []byte ("[default]" + "\n " +
62
- "aws_access_key_id=" + testAccessKey + "\n " +
63
- "aws_secret_access_key=" + testSecretAccessKey +
64
- "\n [test-profile]\n " +
65
- "aws_access_key_id=" + testAccessKey + "\n " +
66
- "aws_secret_access_key=" + testSecretAccessKey ,
64
+ "cloud" : []byte (
65
+ "\n [" + testBslProfile + "]\n " +
66
+ "aws_access_key_id=" + testBslAccessKey + "\n " +
67
+ "aws_secret_access_key=" + testBslSecretAccessKey +
68
+ "\n [default]" + "\n " +
69
+ "aws_access_key_id=" + testAccessKey + "\n " +
70
+ "aws_secret_access_key=" + testSecretAccessKey +
71
+ "\n [test-profile]\n " +
72
+ "aws_access_key_id=" + testAccessKey + "\n " +
73
+ "aws_secret_access_key=" + testSecretAccessKey ,
74
+ ),
75
+ }
76
+ awsSecretDataWithMissingProfile = map [string ][]byte {
77
+ "cloud" : []byte (
78
+ "[default]" + "\n " +
79
+ "aws_access_key_id=" + testAccessKey + "\n " +
80
+ "aws_secret_access_key=" + testSecretAccessKey +
81
+ "\n [test-profile]\n " +
82
+ "aws_access_key_id=" + testAccessKey + "\n " +
83
+ "aws_secret_access_key=" + testSecretAccessKey ,
67
84
),
68
85
}
69
86
secretAzureData = map [string ][]byte {
@@ -487,6 +504,7 @@ func TestVeleroReconciler_getAWSRegistryEnvVars(t *testing.T) {
487
504
wantProfile string
488
505
secret * corev1.Secret
489
506
wantErr bool
507
+ matchProfile bool
490
508
}{
491
509
{
492
510
name : "given aws bsl, appropriate env var for the container are returned" ,
@@ -517,7 +535,70 @@ func TestVeleroReconciler_getAWSRegistryEnvVars(t *testing.T) {
517
535
},
518
536
Data : secretData ,
519
537
},
520
- wantProfile : "test-profile" ,
538
+ wantProfile : "test-profile" ,
539
+ matchProfile : true ,
540
+ }, {
541
+ name : "given aws profile in bsl, appropriate env var for the container are returned" ,
542
+ bsl : & velerov1.BackupStorageLocation {
543
+ ObjectMeta : metav1.ObjectMeta {
544
+ Name : "test-bsl" ,
545
+ Namespace : "test-ns" ,
546
+ },
547
+ Spec : velerov1.BackupStorageLocationSpec {
548
+ Provider : AWSProvider ,
549
+ StorageType : velerov1.StorageType {
550
+ ObjectStorage : & velerov1.ObjectStorageLocation {
551
+ Bucket : "aws-bucket" ,
552
+ },
553
+ },
554
+ Config : map [string ]string {
555
+ Region : "aws-region" ,
556
+ S3URL : "https://sr-url-aws-domain.com" ,
557
+ InsecureSkipTLSVerify : "false" ,
558
+ Profile : testBslProfile ,
559
+ },
560
+ },
561
+ },
562
+ secret : & corev1.Secret {
563
+ ObjectMeta : metav1.ObjectMeta {
564
+ Name : "cloud-credentials" ,
565
+ Namespace : "test-ns" ,
566
+ },
567
+ Data : secretData ,
568
+ },
569
+ wantProfile : testBslProfile ,
570
+ matchProfile : true ,
571
+ }, {
572
+ name : "given missing aws profile in bsl, env var should not match" ,
573
+ bsl : & velerov1.BackupStorageLocation {
574
+ ObjectMeta : metav1.ObjectMeta {
575
+ Name : "test-bsl" ,
576
+ Namespace : "test-ns" ,
577
+ },
578
+ Spec : velerov1.BackupStorageLocationSpec {
579
+ Provider : AWSProvider ,
580
+ StorageType : velerov1.StorageType {
581
+ ObjectStorage : & velerov1.ObjectStorageLocation {
582
+ Bucket : "aws-bucket" ,
583
+ },
584
+ },
585
+ Config : map [string ]string {
586
+ Region : "aws-region" ,
587
+ S3URL : "https://sr-url-aws-domain.com" ,
588
+ InsecureSkipTLSVerify : "false" ,
589
+ Profile : testBslProfile ,
590
+ },
591
+ },
592
+ },
593
+ secret : & corev1.Secret {
594
+ ObjectMeta : metav1.ObjectMeta {
595
+ Name : "cloud-credentials" ,
596
+ Namespace : "test-ns" ,
597
+ },
598
+ Data : awsSecretDataWithMissingProfile ,
599
+ },
600
+ wantProfile : testBslProfile ,
601
+ matchProfile : false ,
521
602
},
522
603
}
523
604
for _ , tt := range tests {
@@ -567,15 +648,47 @@ func TestVeleroReconciler_getAWSRegistryEnvVars(t *testing.T) {
567
648
Value : "false" ,
568
649
},
569
650
}
651
+ if tt .wantProfile == testBslProfile {
652
+ tt .wantRegistryContainerEnvVar = []corev1.EnvVar {
653
+ {
654
+ Name : RegistryStorageEnvVarKey ,
655
+ Value : S3 ,
656
+ },
657
+ {
658
+ Name : RegistryStorageS3AccesskeyEnvVarKey ,
659
+ Value : testBslAccessKey ,
660
+ },
661
+ {
662
+ Name : RegistryStorageS3BucketEnvVarKey ,
663
+ Value : "aws-bucket" ,
664
+ },
665
+ {
666
+ Name : RegistryStorageS3RegionEnvVarKey ,
667
+ Value : "aws-region" ,
668
+ },
669
+ {
670
+ Name : RegistryStorageS3SecretkeyEnvVarKey ,
671
+ Value : testBslSecretAccessKey ,
672
+ },
673
+ {
674
+ Name : RegistryStorageS3RegionendpointEnvVarKey ,
675
+ Value : "https://sr-url-aws-domain.com" ,
676
+ },
677
+ {
678
+ Name : RegistryStorageS3SkipverifyEnvVarKey ,
679
+ Value : "false" ,
680
+ },
681
+ }
682
+ }
570
683
571
684
gotRegistryContainerEnvVar , gotErr := r .getAWSRegistryEnvVars (tt .bsl , testAWSEnvVar )
572
685
573
- if (gotErr != nil ) != tt .wantErr {
686
+ if tt . matchProfile && (gotErr != nil ) != tt .wantErr {
574
687
t .Errorf ("ValidateBackupStorageLocations() gotErr = %v, wantErr %v" , gotErr , tt .wantErr )
575
688
return
576
689
}
577
690
578
- if ! reflect .DeepEqual (tt .wantRegistryContainerEnvVar , gotRegistryContainerEnvVar ) {
691
+ if tt . matchProfile && ! reflect .DeepEqual (tt .wantRegistryContainerEnvVar , gotRegistryContainerEnvVar ) {
579
692
t .Errorf ("expected registry container env var to be %#v, got %#v" , tt .wantRegistryContainerEnvVar , gotRegistryContainerEnvVar )
580
693
}
581
694
})
0 commit comments