Skip to content

Commit d58d215

Browse files
authored
Make CRD merging deduplication deterministic (#4)
Build the deduplicated CRD file slice from map keys sorted by group then kind, instead of ranging over the crdMap Go map whose iteration order is randomized per run. This makes repeated runs over the same input produce byte-identical output. Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 5404a63 commit d58d215

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

‎pkg/cmds/crdonly.go‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package cmds
1919
import (
2020
"fmt"
2121
"os"
22+
"sort"
2223
"strings"
2324

2425
"github.com/spf13/cobra"
@@ -65,10 +66,21 @@ func NewCmdGenerateCRDOnlyChart() *cobra.Command {
6566
}
6667
}
6768

68-
// Convert to slice
69-
var crdFiles []*chart.File
70-
for _, file := range crdMap {
71-
crdFiles = append(crdFiles, file)
69+
// Convert to slice in a deterministic order (sorted by group then kind)
70+
// so repeated runs over the same input always produce identical output.
71+
crdKeys := make([]schema.GroupKind, 0, len(crdMap))
72+
for key := range crdMap {
73+
crdKeys = append(crdKeys, key)
74+
}
75+
sort.Slice(crdKeys, func(i, j int) bool {
76+
if crdKeys[i].Group != crdKeys[j].Group {
77+
return crdKeys[i].Group < crdKeys[j].Group
78+
}
79+
return crdKeys[i].Kind < crdKeys[j].Kind
80+
})
81+
crdFiles := make([]*chart.File, 0, len(crdMap))
82+
for _, key := range crdKeys {
83+
crdFiles = append(crdFiles, crdMap[key])
7284
}
7385

7486
var extraFiles []*chart.File

0 commit comments

Comments
 (0)