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
1 change: 1 addition & 0 deletions v2/internal/pkg/clusterresources/clusterresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func writeMirrorSet[T confv1.ImageDigestMirrorSet | confv1.ImageTagMirrorSet](mi
return fmt.Errorf("error while sanitizing the catalogSource object prior to marshalling: %v", err)
}
delete(unstructuredObj.Object["metadata"].(map[string]interface{}), "creationTimestamp")
delete(unstructuredObj.Object, "status")

msBytes, err := yaml.Marshal(unstructuredObj.Object)
if err != nil {
Expand Down
59 changes: 59 additions & 0 deletions v2/internal/pkg/clusterresources/clusterresources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,65 @@ func TestIDMS_ITMSGenerator(t *testing.T) {
}
}

// verifyNoStatusField checks that a YAML file (if it exists) does not contain a 'status' field.
func verifyNoStatusField(t *testing.T, filePath string) {
t.Helper()
if _, err := os.Stat(filePath); err != nil {
return
}

yamlData, err := parser.ParseYamlFile[map[string]any](filePath)
assert.NoError(t, err)

assert.NotContains(t, yamlData, "status")
}

func TestIDMS_ITMS_NoStatusField(t *testing.T) {
log := clog.New("trace")

type testCase struct {
caseName string
imgList []v2alpha1.CopyImageSchema
}
testCases := []testCase{
{
caseName: "Testing ITMS file does not contain status field - release use case",
imgList: imageListRelease,
},
{
caseName: "Testing IDMS and ITMS files do not contain status field - mixed images",
imgList: imageListMixed,
},
{
caseName: "Testing IDMS file does not contain status field - digests only",
imgList: imageListDigestsOnly,
},
}

for _, testCase := range testCases {
t.Run(testCase.caseName, func(t *testing.T) {
tmpDir := t.TempDir()
workingDir := tmpDir + "/working-dir"

cr := &ClusterResourcesGenerator{
Log: log,
WorkingDir: workingDir,
LocalStorageFQDN: "localhost:55000",
}

err := cr.IDMS_ITMSGenerator(testCase.imgList, false)
assert.NoError(t, err)

// Check IDMS and ITMS files
idmsPath := filepath.Join(workingDir, clusterResourcesDir, "idms-oc-mirror.yaml")
itmsPath := filepath.Join(workingDir, clusterResourcesDir, "itms-oc-mirror.yaml")

verifyNoStatusField(t, idmsPath)
verifyNoStatusField(t, itmsPath)
})
}
}

func TestGenerateIDMS(t *testing.T) {
log := clog.New("trace")

Expand Down