Skip to content

Commit 0f24e41

Browse files
authored
Allow more than one BSL of a provider (#887)
1 parent 0204698 commit 0f24e41

2 files changed

Lines changed: 39 additions & 23 deletions

File tree

controllers/bsl.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ func (r *DPAReconciler) ValidateBackupStorageLocations(log logr.Logger) (bool, e
2727
return false, errors.New("no backupstoragelocations configured, ensure a backupstoragelocation has been configured")
2828
}
2929

30-
// Ensure BSL:Provider has a 1:1 mapping
31-
if err := r.ensureBSLProviderMapping(&dpa); err != nil {
30+
if err := r.ensureBackupLocationHasVeleroOrCloudStorage(&dpa); err != nil {
3231
return false, err
3332
}
3433

@@ -336,27 +335,14 @@ func (r *DPAReconciler) validateProviderPluginAndSecret(bslSpec velerov1.BackupS
336335
return nil
337336
}
338337

339-
func (r *DPAReconciler) ensureBSLProviderMapping(dpa *oadpv1alpha1.DataProtectionApplication) error {
340-
341-
providerBSLMap := map[string]int{}
338+
func (r *DPAReconciler) ensureBackupLocationHasVeleroOrCloudStorage(dpa *oadpv1alpha1.DataProtectionApplication) error {
342339
for _, bsl := range dpa.Spec.BackupLocations {
343340
if bsl.CloudStorage == nil && bsl.Velero == nil {
344-
return fmt.Errorf("no bucket or BSL provided for backupstoragelocations")
341+
return fmt.Errorf("no bucket CloudStorage or velero BackupStorageLocation provided for backupLocations")
345342
}
346-
if bsl.Velero != nil {
347-
// Only check the default providers here, if there are extra credentials passed then we can have more than one.
348-
if bsl.Velero.Credential == nil {
349-
provider := bsl.Velero.Provider
350-
351-
providerBSLMap[provider]++
352343

353-
if providerBSLMap[provider] > 1 {
354-
return fmt.Errorf("more than one backupstoragelocations configured for provider %s ", provider)
355-
}
356-
}
357-
}
358344
if bsl.CloudStorage != nil && bsl.Velero != nil {
359-
return fmt.Errorf("more than one of backupstoragelocations and bucket provided for a single StorageLocation")
345+
return fmt.Errorf("cannot have both backupstoragelocations and bucket provided for a single StorageLocation")
360346
}
361347
}
362348
return nil

controllers/bsl_test.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
corev1 "k8s.io/api/core/v1"
9+
v1 "k8s.io/api/core/v1"
910

1011
"github.com/go-logr/logr"
1112
oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1"
@@ -1305,7 +1306,7 @@ func TestDPAReconciler_updateBSLFromSpec(t *testing.T) {
13051306
}
13061307
}
13071308

1308-
func TestDPAReconciler_ensureBSLProviderMapping(t *testing.T) {
1309+
func TestDPAReconciler_ensureBackupLocationHasVeleroOrCloudStorage(t *testing.T) {
13091310
tests := []struct {
13101311
name string
13111312
dpa *oadpv1alpha1.DataProtectionApplication
@@ -1341,7 +1342,7 @@ func TestDPAReconciler_ensureBSLProviderMapping(t *testing.T) {
13411342
wantErr: false,
13421343
},
13431344
{
1344-
name: "two bsl configured for aws provider",
1345+
name: "wantErr: a bsl has both velero and cloudstorage configured",
13451346
dpa: &oadpv1alpha1.DataProtectionApplication{
13461347
ObjectMeta: metav1.ObjectMeta{
13471348
Name: "foo",
@@ -1353,12 +1354,41 @@ func TestDPAReconciler_ensureBSLProviderMapping(t *testing.T) {
13531354
Velero: &velerov1.BackupStorageLocationSpec{
13541355
Provider: "aws",
13551356
},
1357+
CloudStorage: &oadpv1alpha1.CloudStorageLocation{
1358+
CloudStorageRef: v1.LocalObjectReference{
1359+
Name: "foo",
1360+
},
1361+
},
13561362
},
1363+
},
1364+
},
1365+
},
1366+
wantErr: true,
1367+
},
1368+
{
1369+
name: "two bsl configured per provider",
1370+
dpa: &oadpv1alpha1.DataProtectionApplication{
1371+
ObjectMeta: metav1.ObjectMeta{
1372+
Name: "foo",
1373+
Namespace: "test-ns",
1374+
},
1375+
Spec: oadpv1alpha1.DataProtectionApplicationSpec{
1376+
BackupLocations: []oadpv1alpha1.BackupLocation{
13571377
{
13581378
Velero: &velerov1.BackupStorageLocationSpec{
13591379
Provider: "aws",
13601380
},
13611381
},
1382+
{
1383+
Velero: &velerov1.BackupStorageLocationSpec{
1384+
Provider: "aws",
1385+
},
1386+
},
1387+
{
1388+
Velero: &velerov1.BackupStorageLocationSpec{
1389+
Provider: "azure",
1390+
},
1391+
},
13621392
{
13631393
Velero: &velerov1.BackupStorageLocationSpec{
13641394
Provider: "azure",
@@ -1371,13 +1401,13 @@ func TestDPAReconciler_ensureBSLProviderMapping(t *testing.T) {
13711401
},
13721402
{
13731403
Velero: &velerov1.BackupStorageLocationSpec{
1374-
Provider: "thirdpary-objectstorage-provider",
1404+
Provider: "gcp",
13751405
},
13761406
},
13771407
},
13781408
},
13791409
},
1380-
wantErr: true,
1410+
wantErr: false,
13811411
},
13821412
}
13831413
for _, tt := range tests {
@@ -1389,7 +1419,7 @@ func TestDPAReconciler_ensureBSLProviderMapping(t *testing.T) {
13891419
r := &DPAReconciler{
13901420
Scheme: scheme,
13911421
}
1392-
if err := r.ensureBSLProviderMapping(tt.dpa); (err != nil) != tt.wantErr {
1422+
if err := r.ensureBackupLocationHasVeleroOrCloudStorage(tt.dpa); (err != nil) != tt.wantErr {
13931423
t.Errorf("ensureBSLProviderMapping() error = %v, wantErr %v", err, tt.wantErr)
13941424
}
13951425
})

0 commit comments

Comments
 (0)