Make CRD dedup winner deterministic#5
Merged
Conversation
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
crd-onlydeduplicates CRDs byGroupKind, keeping the first copy it encounters. But which copy is "first" is decided by the order Helm'sCRDObjects()enumerates the chart tree — and that order is not stable. It varies with how subcharts happen to be loaded (a directory vs a vendored.tgz, freshly pulled OCI dependencies, Helm version, diamond dependencies).#4 made the output file ordering deterministic (sorted
crdKeys), but it did not change which duplicate wins. So when the same CRD (GroupKind) is shipped by multiple charts with differing content, the generated*-certified-crdschart still flaps between the conflicting copies from run to run — e.g. cert-manager'sCertificate/IssuerCRDs, which several subcharts vendor.Reproduction (parent chart with subchart
subpresent as both a directory and a.tgz, each shipping a different version of the same CRD):Fix
Collect every candidate CRD with its source chart path and a content digest, then choose the winner by a total order:
group, thenkind— stable output file order.tgz(or reached via a diamond dependency) with differing content, so the key(group, kind, path, filename)would otherwise tie andsort.Slice(unstable) would pick arbitrarilyBecause candidates are sorted by
(group, kind)first, the output slice is already in stable order — the separate post-sort of keys is removed. The redundant second pass overch.Dependencies()is dropped too, sinceCRDObjects()already recurses into all subcharts.A duplicate warning is now emitted only when a dropped copy actually differs in content from the winner, so identical duplicates (the common case) stay quiet while genuine version conflicts remain visible.