feat: support composition revisions #80
Merged
+3,226
−205
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.
Description of your changes
This PR adds support for Crossplane's composition revision system and automatic/manual update policies in
crossplane-diff, ensuring diffs accurately reflect how Crossplane will render XRs based on their configuredupdate strategy.
Composition Revision Resolution
When diffing XRs,
crossplane-diffnow intelligently resolves which composition version to use based on theXR's
compositionUpdatePolicyandcompositionRevisionReffields:Automatic Update Policy: XRs with
compositionUpdatePolicy: Automatic(the default) always use the latestCompositionRevisionfor their composition. This mirrors Crossplane's behavior where automatic XRs arecontinuously upgraded to the newest composition version.
Manual Update Policy: XRs with
compositionUpdatePolicy: Manualuse the specificCompositionRevisionreferenced in their
spec.crossplane.compositionRevisionReffield. This allows users to see diffs for XRs thatare pinned to a specific composition version.
Fallback Behavior: If composition revisions cannot be found (e.g., for newly created compositions),
crossplane-difffalls back to using theCompositionresource directly.New CLI Flag:
--include-manualThe
compcommand now includes an--include-manualflag that controls which XRs are included in the diffoutput:
Default behavior (
--include-manual=false): Only shows diffs for XRs withAutomaticupdate policy,since these are the XRs that will actually be affected by composition changes.
With
--include-manual: Includes XRs withManualupdate policy in the diff output, allowing users tosee the potential impact if they were to upgrade these manually-pinned XRs.
This filtering ensures users see relevant results by default, while still allowing inspection of
manually-managed XRs when needed.
Implementation Details
CompositionRevisionClientto handle fetching and resolvingCompositionRevisionresourcesCompositionClient.FindMatchingComposition()to use revision-based resolution viaresolveCompositionFromRevisions()CompDiffProcessor.filterXRsByUpdatePolicy()compositionRevisionReffield before validation, as it's set byCrossplane controllers and may not be present in all XRD schemas
Fixes #71.
I have:
earthly +reviewableto ensure this PR is ready for review.- [ ] Linked a PR or a docs tracking issue to document this change.- [ ] Followed the API promotion workflow if this PR introduces, removes, or promotes an API.Need help with this checklist? See the cheat sheet.