Skip to content

Commit 08fecbd

Browse files
authored
Use proper ConfigMap for the repository maintenance job (#1896)
The CM for the Repository Maintenance do not match the CM layout for the Node Agent. In upstream documentation CM for the Repository Maintenance is the same as for the Node Agent, but implementation is different. Upstream issue: vmware-tanzu/velero#9159 Signed-off-by: Michal Pryc <[email protected]>
1 parent 9beaf49 commit 08fecbd

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

internal/controller/repository_maintenance.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ func (r *DataProtectionApplicationReconciler) updateRepositoryMaintenanceCM(cm *
2727
return fmt.Errorf("failed to set controller reference: %w", err)
2828
}
2929

30-
// Convert NodeAgentConfigMapSettings to a generic map
31-
configRepositoryMaintenanceJSON, err := json.Marshal(r.dpa.Spec.Configuration.RepositoryMaintenance)
32-
if err != nil {
33-
return fmt.Errorf("failed to serialize repository maintenance config: %w", err)
34-
}
35-
3630
cm.Name = common.RepoMaintConfigMapPrefix + r.dpa.Name
3731
cm.Namespace = r.NamespacedName.Namespace
3832
cm.Labels = map[string]string{
@@ -45,7 +39,16 @@ func (r *DataProtectionApplicationReconciler) updateRepositoryMaintenanceCM(cm *
4539
if cm.Data == nil {
4640
cm.Data = make(map[string]string)
4741
}
48-
cm.Data["repository-maintenance-config"] = string(configRepositoryMaintenanceJSON)
42+
// TODO: This implementation of ConfigMap is different from the Node-Agent
43+
// to to match the upstream implementation
44+
// https://github.com/vmware-tanzu/velero/issues/9159
45+
for key, config := range r.dpa.Spec.Configuration.RepositoryMaintenance {
46+
configJSON, err := json.Marshal(config)
47+
if err != nil {
48+
return fmt.Errorf("failed to serialize repository maintenance config for key %s: %w", key, err)
49+
}
50+
cm.Data[key] = string(configJSON)
51+
}
4952

5053
return nil
5154
}

internal/controller/repository_maintenance_test.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ func TestDataProtectionApplicationReconciler_updateRepositoryMaintenanceCM(t *te
8484
},
8585
},
8686
Data: map[string]string{
87-
"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"}}}]}}`,
87+
"global": `{"loadAffinity":[{"nodeSelector":{"matchLabels":{"app.kubernetes.io/name":"test-dpa"}}}],"podResources":{"cpuRequest":"100m","memoryRequest":"128Mi","cpuLimit":"200m","memoryLimit":"256Mi"}}`,
88+
"maintenance-job-1": `{"loadAffinity":[{"nodeSelector":{"matchLabels":{"app.kubernetes.io/name":"test-dpa"}}}]}`,
8889
},
8990
},
9091
},
@@ -116,15 +117,19 @@ func TestDataProtectionApplicationReconciler_updateRepositoryMaintenanceCM(t *te
116117
require.Equal(t, tt.wantCM.ObjectMeta.Labels, tt.cm.ObjectMeta.Labels, "ConfigMap Labels do not match")
117118

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

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

125-
require.NoError(t, json.Unmarshal([]byte(expectedData), &expectedMap), "Failed to unmarshal expected Data")
126-
require.NoError(t, json.Unmarshal([]byte(actualData), &actualMap), "Failed to unmarshal actual Data")
127-
require.Equal(t, expectedMap, actualMap, "ConfigMap Data does not match")
126+
var expectedMap map[string]interface{}
127+
var actualMap map[string]interface{}
128+
129+
require.NoError(t, json.Unmarshal([]byte(expectedData), &expectedMap), "Failed to unmarshal expected Data for key %s", key)
130+
require.NoError(t, json.Unmarshal([]byte(actualData), &actualMap), "Failed to unmarshal actual Data for key %s", key)
131+
require.Equal(t, expectedMap, actualMap, "ConfigMap Data does not match for key %s", key)
132+
}
128133
})
129134
}
130135
}

0 commit comments

Comments
 (0)