Skip to content

Commit

Permalink
OADP-3054: BSL default configuration validation (#1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
sseago authored Nov 8, 2023
1 parent b730dbf commit 66d0b27
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
17 changes: 17 additions & 0 deletions controllers/bsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ func (r *DPAReconciler) ValidateBackupStorageLocations(dpa oadpv1alpha1.DataProt

// Ensure BSL is a valid configuration
// First, check for provider and then call functions based on the cloud provider for each backupstoragelocation configured
numDefaultLocations := 0
for _, bslSpec := range dpa.Spec.BackupLocations {
if bslSpec.Velero != nil {
if bslSpec.Velero.Default {
numDefaultLocations++
} else if bslSpec.Name == "default" {
return false, fmt.Errorf("Storage location named 'default' must be set as default")
}
provider := bslSpec.Velero.Provider
if len(provider) == 0 {
return false, fmt.Errorf("no provider specified for one of the backupstoragelocations configured")
Expand Down Expand Up @@ -65,11 +71,22 @@ func (r *DPAReconciler) ValidateBackupStorageLocations(dpa oadpv1alpha1.DataProt
if bslSpec.CloudStorage.Credential.LocalObjectReference.Name == "" {
return false, fmt.Errorf("must provide a valid credential secret name")
}
if bslSpec.CloudStorage.Default {
numDefaultLocations++
} else if bslSpec.Name == "default" {
return false, fmt.Errorf("Storage location named 'default' must be set as default")
}
}
if bslSpec.CloudStorage != nil && bslSpec.Velero != nil {
return false, fmt.Errorf("must choose one of bucket or velero")
}
}
if numDefaultLocations > 1 {
return false, fmt.Errorf("Only one Storage Location be set as default")
}
if numDefaultLocations == 0 && !dpa.Spec.Configuration.Velero.NoDefaultBackupLocation {
return false, errors.New("no default backupstoragelocations configured, ensure that one backupstoragelocation has been configured as the default location")
}
// TODO: Discuss If multiple BSLs exist, ensure we have multiple credentials

return true, nil
Expand Down
50 changes: 50 additions & 0 deletions controllers/bsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) {
Name: "cloud-credentials",
},
},
Default: true,
},
},
},
Expand Down Expand Up @@ -582,6 +583,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) {
Name: "cloud-credentials",
},
},
Default: true,
},
},
},
Expand All @@ -596,6 +598,50 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) {
},
},
},
{
name: "test BSLs specified, no default set",
dpa: &oadpv1alpha1.DataProtectionApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "test-ns",
},
Spec: oadpv1alpha1.DataProtectionApplicationSpec{
Configuration: &oadpv1alpha1.ApplicationConfig{
Velero: &oadpv1alpha1.VeleroConfig{},
},
BackupLocations: []oadpv1alpha1.BackupLocation{
{
Velero: &velerov1.BackupStorageLocationSpec{
Provider: "aws",
StorageType: velerov1.StorageType{
ObjectStorage: &velerov1.ObjectStorageLocation{
Bucket: "test-aws-bucket",
Prefix: "velero",
},
},
Config: map[string]string{
Region: "test-region",
},
Credential: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "cloud-credentials",
},
},
Default: false,
},
},
},
},
},
want: false,
wantErr: true,
secret: &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "cloud-credentials",
Namespace: "test-ns",
},
},
},
{
name: "test BSLs specified, prefix not present for aws BSL",
dpa: &oadpv1alpha1.DataProtectionApplication{
Expand Down Expand Up @@ -749,6 +795,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) {
Name: "cloud-credentials",
},
},
Default: true,
},
},
{
Expand Down Expand Up @@ -984,6 +1031,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) {
Name: "cloud-credentials",
},
},
Default: true,
},
},
{
Expand Down Expand Up @@ -1111,6 +1159,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) {
Prefix: "prefix",
},
},
Default: true,
},
},
},
Expand Down Expand Up @@ -1150,6 +1199,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) {
Prefix: "prefix",
},
},
Default: true,
},
},
},
Expand Down
14 changes: 13 additions & 1 deletion controllers/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
Key: "credentials",
},
Default: true,
},
},
},
Expand Down Expand Up @@ -260,6 +261,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
Key: "credentials",
},
Default: true,
},
},
},
Expand Down Expand Up @@ -312,6 +314,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
Key: "credentials",
},
Default: true,
},
},
},
Expand Down Expand Up @@ -375,6 +378,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
Key: "credentials",
},
Default: true,
},
},
},
Expand Down Expand Up @@ -422,6 +426,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
Key: "credentials",
},
Default: true,
},
},
},
Expand Down Expand Up @@ -521,6 +526,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
Key: "credentials",
},
Default: true,
},
},
},
Expand Down Expand Up @@ -589,6 +595,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
Name: "cloud-credentials-gcp",
},
},
Default: true,
},
},
},
Expand Down Expand Up @@ -631,6 +638,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
},
Provider: "velero.io/gcp",
Default: true,
},
},
},
Expand Down Expand Up @@ -739,6 +747,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
Config: map[string]string{
"region": "us-east-1",
},
Default: true,
},
},
},
Expand Down Expand Up @@ -853,6 +862,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
Config: map[string]string{
"region": "us-east-1",
},
Default: true,
},
},
},
Expand Down Expand Up @@ -1001,7 +1011,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
want: false,
},
{
name: "given valid DPA CR AWS with BSL and VSL credentials referencing to a custom secret",
name: "given valid DPA CR AWS with BSL and VSL credentials referencing a custom secret",
dpa: &oadpv1alpha1.DataProtectionApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "test-DPA-CR",
Expand All @@ -1028,6 +1038,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
Config: map[string]string{
"region": "us-east-1",
},
Default: true,
},
},
},
Expand Down Expand Up @@ -1123,6 +1134,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
Key: "cloud",
},
Default: true,
},
},
},
Expand Down

0 comments on commit 66d0b27

Please sign in to comment.