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
17 changes: 10 additions & 7 deletions internal/controller/repository_maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ func (r *DataProtectionApplicationReconciler) updateRepositoryMaintenanceCM(cm *
return fmt.Errorf("failed to set controller reference: %w", err)
}

// Convert NodeAgentConfigMapSettings to a generic map
configRepositoryMaintenanceJSON, err := json.Marshal(r.dpa.Spec.Configuration.RepositoryMaintenance)
if err != nil {
return fmt.Errorf("failed to serialize repository maintenance config: %w", err)
}

cm.Name = common.RepoMaintConfigMapPrefix + r.dpa.Name
cm.Namespace = r.NamespacedName.Namespace
cm.Labels = map[string]string{
Expand All @@ -45,7 +39,16 @@ func (r *DataProtectionApplicationReconciler) updateRepositoryMaintenanceCM(cm *
if cm.Data == nil {
cm.Data = make(map[string]string)
}
cm.Data["repository-maintenance-config"] = string(configRepositoryMaintenanceJSON)
// TODO: This implementation of ConfigMap is different from the Node-Agent
// to to match the upstream implementation
// https://github.com/vmware-tanzu/velero/issues/9159
for key, config := range r.dpa.Spec.Configuration.RepositoryMaintenance {
configJSON, err := json.Marshal(config)
if err != nil {
return fmt.Errorf("failed to serialize repository maintenance config for key %s: %w", key, err)
}
cm.Data[key] = string(configJSON)
}

return nil
}
Expand Down
21 changes: 13 additions & 8 deletions internal/controller/repository_maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func TestDataProtectionApplicationReconciler_updateRepositoryMaintenanceCM(t *te
},
},
Data: map[string]string{
"repository-maintenance-config": `{"global":{"loadAffinity":[{"nodeSelector":{"matchLabels":{"app.kubernetes.io/name":"test-dpa"}}}],"podResources":{"cpuRequest":"100m","memoryRequest":"128Mi","cpuLimit":"200m","memoryLimit":"256Mi"}},"maintenance-job-1":{"loadAffinity":[{"nodeSelector":{"matchLabels":{"app.kubernetes.io/name":"test-dpa"}}}]}}`,
"global": `{"loadAffinity":[{"nodeSelector":{"matchLabels":{"app.kubernetes.io/name":"test-dpa"}}}],"podResources":{"cpuRequest":"100m","memoryRequest":"128Mi","cpuLimit":"200m","memoryLimit":"256Mi"}}`,
"maintenance-job-1": `{"loadAffinity":[{"nodeSelector":{"matchLabels":{"app.kubernetes.io/name":"test-dpa"}}}]}`,
},
},
},
Expand Down Expand Up @@ -116,15 +117,19 @@ func TestDataProtectionApplicationReconciler_updateRepositoryMaintenanceCM(t *te
require.Equal(t, tt.wantCM.ObjectMeta.Labels, tt.cm.ObjectMeta.Labels, "ConfigMap Labels do not match")

// Compare Data fields, we need to unmarshal the JSON to ignore key order
expectedData := tt.wantCM.Data["repository-maintenance-config"]
actualData := tt.cm.Data["repository-maintenance-config"]
require.Equal(t, len(tt.wantCM.Data), len(tt.cm.Data), "ConfigMap Data key count does not match")

var expectedMap map[string]interface{}
var actualMap map[string]interface{}
for key, expectedData := range tt.wantCM.Data {
actualData, exists := tt.cm.Data[key]
require.True(t, exists, "ConfigMap Data key %s not found", key)

require.NoError(t, json.Unmarshal([]byte(expectedData), &expectedMap), "Failed to unmarshal expected Data")
require.NoError(t, json.Unmarshal([]byte(actualData), &actualMap), "Failed to unmarshal actual Data")
require.Equal(t, expectedMap, actualMap, "ConfigMap Data does not match")
var expectedMap map[string]interface{}
var actualMap map[string]interface{}

require.NoError(t, json.Unmarshal([]byte(expectedData), &expectedMap), "Failed to unmarshal expected Data for key %s", key)
require.NoError(t, json.Unmarshal([]byte(actualData), &actualMap), "Failed to unmarshal actual Data for key %s", key)
require.Equal(t, expectedMap, actualMap, "ConfigMap Data does not match for key %s", key)
}
})
}
}