Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion controllers/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func (r *DPAReconciler) ValidateDataProtectionCR(log logr.Logger) (bool, error)
return false, errors.New("no backupstoragelocations configured, ensure a backupstoragelocation has been configured or use the noDefaultLocationBackupLocation flag")
}

if dpa.Spec.Configuration.Velero.NoDefaultBackupLocation && dpa.BackupImages() {
return false, errors.New("backupImages needs to be set to false when noDefaultLocationBackupLocation is set")
}

if len(dpa.Spec.BackupLocations) > 0 {
for _, location := range dpa.Spec.BackupLocations {
// check for velero BSL config or cloud storage config
Expand Down Expand Up @@ -70,7 +74,7 @@ func (r *DPAReconciler) ValidateVeleroPlugins(log logr.Logger) (bool, error) {
pluginNeedsCheck = true
}

if ok && pluginSpecificMap.IsCloudProvider && pluginNeedsCheck {
if ok && pluginSpecificMap.IsCloudProvider && pluginNeedsCheck && !dpa.Spec.Configuration.Velero.NoDefaultBackupLocation {
secretName := pluginSpecificMap.SecretName
_, err := r.getProviderSecret(secretName)
if err != nil {
Expand Down
36 changes: 27 additions & 9 deletions controllers/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand All @@ -22,7 +23,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
wantErr bool
}{
{
name: "given valid DPA CR, no error case",
name: "given valid DPA CR, no default backup location, no backup images, no error case",
dpa: &oadpv1alpha1.DataProtectionApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "test-DPA-CR",
Expand All @@ -37,21 +38,37 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
NoDefaultBackupLocation: true,
},
},
BackupImages: pointer.Bool(false),
},
},
objects: []client.Object{
&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "cloud-credentials",
Namespace: "test-ns",
objects: []client.Object{},
wantErr: false,
want: true,
},
{
name: "given valid DPA CR, no default backup location, backup images cannot be nil, error case",
dpa: &oadpv1alpha1.DataProtectionApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "test-DPA-CR",
Namespace: "test-ns",
},
Spec: oadpv1alpha1.DataProtectionApplicationSpec{
Configuration: &oadpv1alpha1.ApplicationConfig{
Velero: &oadpv1alpha1.VeleroConfig{
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{
oadpv1alpha1.DefaultPluginAWS,
},
NoDefaultBackupLocation: true,
},
},
},
},
wantErr: false,
want: true,
objects: []client.Object{},
wantErr: true,
want: false,
},
{
name: "given valid DPA CR, error case",
name: "given valid DPA CR, no default backup location, backup images cannot be true, error case",
dpa: &oadpv1alpha1.DataProtectionApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "test-DPA-CR",
Expand All @@ -66,6 +83,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
NoDefaultBackupLocation: true,
},
},
BackupImages: pointer.Bool(true),
},
},
objects: []client.Object{},
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/backup_restore_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var _ = Describe("AWS backup restore tests", func() {
Expect(err).ToNot(HaveOccurred())
}

if dpaCR.CustomResource.Spec.BackupImages == nil || *dpaCR.CustomResource.Spec.BackupImages {
if dpaCR.CustomResource.BackupImages() {
log.Printf("Waiting for registry pods to be running")
Eventually(AreRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/dpa_deployment_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() {
Eventually(ResticDaemonSetHasNodeSelector(namespace, key, value), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
}
}
if dpa.Spec.BackupImages == nil || *installCase.DpaSpec.BackupImages {
if dpa.BackupImages() {
log.Printf("Waiting for registry pods to be running")
Eventually(AreRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/subscription_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var _ = Describe("Subscription Config Suite Test", func() {
log.Printf("Waiting for restic pods to be running")
Eventually(AreResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
}
if velero.Spec.BackupImages == nil || *velero.Spec.BackupImages {
if velero.BackupImages() {
log.Printf("Waiting for registry pods to be running")
Eventually(AreRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
}
Expand Down