Skip to content

Commit e490bd9

Browse files
perdasilvaPer Goncalves da Silva
and
Per Goncalves da Silva
authored
sort generated manifests (#1897)
Signed-off-by: Per Goncalves da Silva <[email protected]> Co-authored-by: Per Goncalves da Silva <[email protected]>
1 parent 23b9cdc commit e490bd9

File tree

39 files changed

+12
-1
lines changed

39 files changed

+12
-1
lines changed

test/convert/generate-manifests.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package main
22

33
import (
4+
"cmp"
45
"fmt"
56
"os"
67
"path/filepath"
8+
"slices"
79
"strings"
810

11+
"sigs.k8s.io/controller-runtime/pkg/client"
912
"sigs.k8s.io/yaml"
1013

1114
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
@@ -75,7 +78,7 @@ func generateManifests(outputPath, bundleDir, installNamespace, watchNamespace s
7578
}
7679

7780
if err := func() error {
78-
for idx, obj := range plain.Objects {
81+
for idx, obj := range slices.SortedFunc(slices.Values(plain.Objects), orderByKindNamespaceName) {
7982
kind := obj.GetObjectKind().GroupVersionKind().Kind
8083
fileName := fmt.Sprintf("%02d_%s_%s.yaml", idx, strings.ToLower(kind), obj.GetName())
8184
data, err := yaml.Marshal(obj)
@@ -95,3 +98,11 @@ func generateManifests(outputPath, bundleDir, installNamespace, watchNamespace s
9598

9699
return nil
97100
}
101+
102+
func orderByKindNamespaceName(a client.Object, b client.Object) int {
103+
return cmp.Or(
104+
cmp.Compare(a.GetObjectKind().GroupVersionKind().Kind, b.GetObjectKind().GroupVersionKind().Kind),
105+
cmp.Compare(a.GetNamespace(), b.GetNamespace()),
106+
cmp.Compare(a.GetName(), b.GetName()),
107+
)
108+
}

0 commit comments

Comments
 (0)