Skip to content

Commit 172bfaf

Browse files
Merge pull request #2524 from JoelSpeed/fix-manifest-sorting
Switch to slices stable sort on manifest merging
2 parents 207a829 + d5e334d commit 172bfaf

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tools/codegen/pkg/manifestmerge/generator.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"fmt"
88
"math/rand"
99
"os"
10-
"sort"
10+
"slices"
1111
"strings"
1212
"sync"
1313

@@ -637,13 +637,18 @@ func mergeAllPertinentCRDsInDir(resourcePath string, filter ManifestFilter, star
637637
// Sort the manifests such that any combination of feature gates is applied after the gates that it combines.
638638
// This means that if we have a file that is "foo+bar" and a file that is "foo", the "foo+bar" file will be applied last.
639639
// This enables more speicfic handling for combinations of feature gates that affect the same field.
640-
sort.Slice(partialManifestFiles, func(i, j int) bool {
641-
// Get the name of the files without the ".yaml" suffix.
642-
// This should be the name of the feature gate, or, a list of feature gates separated by `+`.
643-
iBase := strings.TrimSuffix(filepath.Base(partialManifestFiles[i].Name()), ".yaml")
644-
jBase := strings.TrimSuffix(filepath.Base(partialManifestFiles[j].Name()), ".yaml")
640+
slices.SortStableFunc(partialManifestFiles, func(a, b os.DirEntry) int {
641+
aBase := strings.TrimSuffix(filepath.Base(a.Name()), ".yaml")
642+
bBase := strings.TrimSuffix(filepath.Base(b.Name()), ".yaml")
645643

646-
return strings.Contains(jBase, "+") && strings.Contains(jBase, iBase)
644+
if strings.Contains(bBase, "+") && strings.Contains(bBase, aBase) {
645+
return -1
646+
}
647+
if strings.Contains(aBase, "+") && strings.Contains(aBase, bBase) {
648+
return 1
649+
}
650+
651+
return strings.Compare(aBase, bBase)
647652
})
648653

649654
foundAFile := false

0 commit comments

Comments
 (0)