diff --git a/pkg/configmap/configmap.go b/pkg/configmap/configmap.go index 2b310371f..f6ab07ec3 100644 --- a/pkg/configmap/configmap.go +++ b/pkg/configmap/configmap.go @@ -3,6 +3,8 @@ package configmap import ( "errors" "fmt" + "maps" + "slices" "strings" "github.com/sirupsen/logrus" @@ -68,7 +70,9 @@ func loadBundle(entry *logrus.Entry, cm *corev1.ConfigMap) (*api.Bundle, map[str } // Add kube resources to the bundle. - for name, content := range data { + // Sort keys by name to guarantee consistent ordering of bundle objects. + for _, name := range slices.Sorted(maps.Keys(data)) { + content := data[name] reader := strings.NewReader(content) logger := entry.WithFields(logrus.Fields{ "key": name, diff --git a/pkg/configmap/configmap_test.go b/pkg/configmap/configmap_test.go index 05e54bd93..f167b7451 100644 --- a/pkg/configmap/configmap_test.go +++ b/pkg/configmap/configmap_test.go @@ -62,7 +62,9 @@ func TestLoad(t *testing.T) { unst, err := unstructuredlib.FromString(csvGot) require.NoError(t, err) - assert.True(t, unst.GetName() == "first" || unst.GetName() == "second") + + // The last CSV (by lexicographical sort of configmap data keys) always wins. + assert.Equal(t, "second", unst.GetName()) }, }, { @@ -167,7 +169,9 @@ func TestLoadWriteRead(t *testing.T) { bundleObjects, err := unstructuredlib.FromBundle(bundle) require.NoError(t, err) - assert.ElementsMatch(t, expectedObjects, bundleObjects) + // Assert that the order of manifests from the original manifests + // directory is preserved (by lexicographical sorting by filename) + assert.Equal(t, expectedObjects, bundleObjects) }) } }