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
6 changes: 5 additions & 1 deletion pkg/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package configmap
import (
"errors"
"fmt"
"maps"
"slices"
"strings"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions pkg/configmap/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
},
},
{
Expand Down Expand Up @@ -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)
})
}
}
Expand Down