|
7 | 7 | "fmt" |
8 | 8 | "math/rand" |
9 | 9 | "os" |
10 | | - "sort" |
| 10 | + "slices" |
11 | 11 | "strings" |
12 | 12 | "sync" |
13 | 13 |
|
@@ -637,13 +637,18 @@ func mergeAllPertinentCRDsInDir(resourcePath string, filter ManifestFilter, star |
637 | 637 | // Sort the manifests such that any combination of feature gates is applied after the gates that it combines. |
638 | 638 | // 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. |
639 | 639 | // 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") |
645 | 643 |
|
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) |
647 | 652 | }) |
648 | 653 |
|
649 | 654 | foundAFile := false |
|
0 commit comments