Make CRD merging deduplication deterministic#4
Merged
Conversation
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>
tamalsaha
added a commit
that referenced
this pull request
Jul 13, 2026
crd-only deduplicates CRDs by GroupKind, keeping the first copy seen. The winner was decided by the order Helm's CRDObjects() enumerates charts, which is not stable — it varies with how subcharts were loaded (directory vs .tgz, freshly pulled OCI deps, Helm version). #4 only sorted the output file order, not which duplicate wins, so the generated crds-only chart still flapped between conflicting copies of the same CRD. Collect every candidate with its source chart path and a content digest, then pick the winner by a total order: group, kind, chart depth (the parent chart wins over its subcharts), chart path, filename, and finally content digest. The digest tiebreak covers the case where one subchart is present as both a directory and a .tgz (or reached via a diamond dependency) with differing content and therefore an otherwise identical (group, kind, path, filename) key. Warn only when a dropped copy actually differs from the winner. Signed-off-by: Tamal Saha <tamal@appscode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
crd-onlycommand produced nondeterministic output for the same input chart. After deduplicating CRDs intocrdMap(keyed byGroupKind), the finalcrdFilesslice was built by ranging over the map — and Go map iteration order is randomized per run. This made the generated chart's CRD file set order vary between otherwise identical runs.Fix
Collect the map keys, sort them by
GroupthenKind, and buildcrdFilesin that stable order. Same input now yields byte-identical output.The dedup precedence itself was already deterministic (parent-first, then dependencies — both stable slices;
CRDObjects()returns sorted files), so only the final slice construction needed fixing.crd-lessneeded no change since it only preserves existing slice order.