Skip to content

Commit

Permalink
fixup! fix: read ephemeral-storage in code
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <[email protected]>
  • Loading branch information
mateusoliveira43 committed Aug 8, 2024
1 parent 4eab463 commit 25b9d0b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
6 changes: 3 additions & 3 deletions controllers/nodeagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand Down
24 changes: 7 additions & 17 deletions controllers/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
}
)
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 25b9d0b

Please sign in to comment.