diff --git a/controllers/nodeagent_test.go b/controllers/nodeagent_test.go index 17237e1137..8e2a82d110 100644 --- a/controllers/nodeagent_test.go +++ b/controllers/nodeagent_test.go @@ -944,7 +944,7 @@ func TestDPAReconciler_buildNodeAgentDaemonset(t *testing.T) { }), }, { - name: "valid DPA CR with aws plugin from CloudStorage, NodeAgent DaemonSet is built with aws plugin", + name: "invalid DPA CR with aws plugin from CloudStorage, error is returned", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -990,8 +990,8 @@ func TestDPAReconciler_buildNodeAgentDaemonset(t *testing.T) { }, }, }, - nodeAgentDaemonSet: testNodeAgentDaemonSet.DeepCopy(), - wantNodeAgentDaemonSet: createTestBuiltNodeAgentDaemonSet(TestBuiltNodeAgentDaemonSetOptions{}), + nodeAgentDaemonSet: testNodeAgentDaemonSet.DeepCopy(), + errorMessage: "spec.backupLocations.velero must be provided in DPA", }, { name: "valid DPA CR with aws plugin and BSL, NodeAgent DaemonSet is built", diff --git a/controllers/velero.go b/controllers/velero.go index 6f0b2f440e..d48cd8f044 100644 --- a/controllers/velero.go +++ b/controllers/velero.go @@ -65,9 +65,6 @@ var ( Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi"), - // TODO add defaults? - // corev1.ResourceStorage: resource.MustParse("0"), - // corev1.ResourceEphemeralStorage: resource.MustParse("0"), }, } ) @@ -680,39 +677,32 @@ func getAppLabels(instanceName string) map[string]string { return labels } -// getResourceListFrom get the values of cpu, memory, storage and ephemeral-storage from -// input into fallback. -func getResourceListFrom(input corev1.ResourceList, fallback corev1.ResourceList) (*corev1.ResourceList, error) { +// getResourceListFrom get the values of cpu, memory and ephemeral-storage from +// input into defaultResourceList. +func getResourceListFrom(input corev1.ResourceList, defaultResourceList corev1.ResourceList) (*corev1.ResourceList, error) { if input.Cpu() != nil && input.Cpu().Value() != 0 { parsedQuantity, err := resource.ParseQuantity(input.Cpu().String()) if err != nil { return nil, err } - fallback[corev1.ResourceCPU] = parsedQuantity + defaultResourceList[corev1.ResourceCPU] = parsedQuantity } if input.Memory() != nil && input.Memory().Value() != 0 { parsedQuantity, err := resource.ParseQuantity(input.Memory().String()) if err != nil { return nil, err } - fallback[corev1.ResourceMemory] = parsedQuantity - } - if input.Storage() != nil && input.Storage().Value() != 0 { - parsedQuantity, err := resource.ParseQuantity(input.Storage().String()) - if err != nil { - return nil, err - } - fallback[corev1.ResourceStorage] = parsedQuantity + defaultResourceList[corev1.ResourceMemory] = parsedQuantity } if input.StorageEphemeral() != nil && input.StorageEphemeral().Value() != 0 { parsedQuantity, err := resource.ParseQuantity(input.StorageEphemeral().String()) if err != nil { return nil, err } - fallback[corev1.ResourceEphemeralStorage] = parsedQuantity + defaultResourceList[corev1.ResourceEphemeralStorage] = parsedQuantity } - return &fallback, nil + return &defaultResourceList, nil } func getResourceReqs(dpa *corev1.ResourceRequirements) (corev1.ResourceRequirements, error) { diff --git a/pkg/credentials/credentials.go b/pkg/credentials/credentials.go index f63d19eba7..f9ec05fc81 100644 --- a/pkg/credentials/credentials.go +++ b/pkg/credentials/credentials.go @@ -221,6 +221,9 @@ func AppendCloudProviderVolumes(dpa *oadpv1alpha1.DataProtectionApplication, ds } } for _, bslSpec := range dpa.Spec.BackupLocations { + if bslSpec.Velero == nil { + return errors.New("spec.backupLocations.velero must be provided in DPA") + } if _, ok := bslSpec.Velero.Config["credentialsFile"]; ok { if secretName, err := GetSecretNameFromCredentialsFileConfigString(bslSpec.Velero.Config["credentialsFile"]); err == nil { ds.Spec.Template.Spec.Volumes = append(