From 14af7cf175e62dc2bc0fc5aad089f5c50aa9929c Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Mon, 13 Jul 2026 03:51:54 +0600 Subject: [PATCH] Make CRD merging deduplication deterministic 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 --- pkg/cmds/crdonly.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/cmds/crdonly.go b/pkg/cmds/crdonly.go index 74ca7b0..ac9c1c7 100644 --- a/pkg/cmds/crdonly.go +++ b/pkg/cmds/crdonly.go @@ -19,6 +19,7 @@ package cmds import ( "fmt" "os" + "sort" "strings" "github.com/spf13/cobra" @@ -65,10 +66,21 @@ func NewCmdGenerateCRDOnlyChart() *cobra.Command { } } - // Convert to slice - var crdFiles []*chart.File - for _, file := range crdMap { - crdFiles = append(crdFiles, file) + // Convert to slice in a deterministic order (sorted by group then kind) + // so repeated runs over the same input always produce identical output. + crdKeys := make([]schema.GroupKind, 0, len(crdMap)) + for key := range crdMap { + crdKeys = append(crdKeys, key) + } + sort.Slice(crdKeys, func(i, j int) bool { + if crdKeys[i].Group != crdKeys[j].Group { + return crdKeys[i].Group < crdKeys[j].Group + } + return crdKeys[i].Kind < crdKeys[j].Kind + }) + crdFiles := make([]*chart.File, 0, len(crdMap)) + for _, key := range crdKeys { + crdFiles = append(crdFiles, crdMap[key]) } var extraFiles []*chart.File