Skip to content

Commit 5074e09

Browse files
committed
Remove empty status field from generated IDMS/ITMS files
1 parent efa9f7a commit 5074e09

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

internal/pkg/clusterresources/clusterresources.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func writeMirrorSet[T confv1.ImageDigestMirrorSet | confv1.ImageTagMirrorSet](mi
163163
return fmt.Errorf("error while sanitizing the catalogSource object prior to marshalling: %v", err)
164164
}
165165
delete(unstructuredObj.Object["metadata"].(map[string]interface{}), "creationTimestamp")
166+
delete(unstructuredObj.Object, "status")
166167

167168
msBytes, err := yaml.Marshal(unstructuredObj.Object)
168169
if err != nil {

internal/pkg/clusterresources/clusterresources_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,65 @@ func TestIDMS_ITMSGenerator(t *testing.T) {
291291
}
292292
}
293293

294+
// verifyNoStatusField checks that a YAML file (if it exists) does not contain a 'status' field.
295+
func verifyNoStatusField(t *testing.T, filePath string) {
296+
t.Helper()
297+
if _, err := os.Stat(filePath); err != nil {
298+
return
299+
}
300+
301+
yamlData, err := parser.ParseYamlFile[map[string]any](filePath)
302+
assert.NoError(t, err)
303+
304+
assert.NotContains(t, yamlData, "status")
305+
}
306+
307+
func TestIDMS_ITMS_NoStatusField(t *testing.T) {
308+
log := clog.New("trace")
309+
310+
type testCase struct {
311+
caseName string
312+
imgList []v2alpha1.CopyImageSchema
313+
}
314+
testCases := []testCase{
315+
{
316+
caseName: "Testing ITMS file does not contain status field - release use case",
317+
imgList: imageListRelease,
318+
},
319+
{
320+
caseName: "Testing IDMS and ITMS files do not contain status field - mixed images",
321+
imgList: imageListMixed,
322+
},
323+
{
324+
caseName: "Testing IDMS file does not contain status field - digests only",
325+
imgList: imageListDigestsOnly,
326+
},
327+
}
328+
329+
for _, testCase := range testCases {
330+
t.Run(testCase.caseName, func(t *testing.T) {
331+
tmpDir := t.TempDir()
332+
workingDir := tmpDir + "/working-dir"
333+
334+
cr := &ClusterResourcesGenerator{
335+
Log: log,
336+
WorkingDir: workingDir,
337+
LocalStorageFQDN: "localhost:55000",
338+
}
339+
340+
err := cr.IDMS_ITMSGenerator(testCase.imgList, false)
341+
assert.NoError(t, err)
342+
343+
// Check IDMS and ITMS files
344+
idmsPath := filepath.Join(workingDir, clusterResourcesDir, "idms-oc-mirror.yaml")
345+
itmsPath := filepath.Join(workingDir, clusterResourcesDir, "itms-oc-mirror.yaml")
346+
347+
verifyNoStatusField(t, idmsPath)
348+
verifyNoStatusField(t, itmsPath)
349+
})
350+
}
351+
}
352+
294353
func TestGenerateIDMS(t *testing.T) {
295354
log := clog.New("trace")
296355

0 commit comments

Comments
 (0)