feat(comp): allow filtering downstream resources#322
Open
jcogilvie wants to merge 2 commits into
Open
Conversation
Signed-off-by: Jonathan Ogilvie <jonathan.ogilvie@sumologic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a --resource filter to crossplane-diff comp to restrict impact analysis to a specific set of named composites (XRs and/or Claims), with a preflight validation step and explicit surfacing of composites skipped due to Manual update policy.
Changes:
- Add
--resourceflag parsing/validation, including mutual exclusion with--namespace, and[namespace/]nameparsing. - Implement name-based composite fetching (
GetCompositesByName) and processor preflight to fail fast on globally-unmatched refs. - Introduce a new XR impact status
filtered_by_policy, including renderer handling and unit/integration test coverage.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents --resource, usage examples, and interaction with update-policy filtering. |
| cmd/diff/types/types.go | Adds ResourceRef type for stable namespace/name references. |
| cmd/diff/testutils/mocks.go | Extends mock CompositionClient with GetCompositesByName. |
| cmd/diff/testutils/mock_builder.go | Adds builder hook for configuring GetCompositesByName behavior in tests. |
| cmd/diff/renderer/structured_renderer.go | Adds XRStatusFilteredByPolicy status constant. |
| cmd/diff/renderer/comp_diff_renderer.go | Renders filtered_by_policy impacts in text output with an explicit marker and message. |
| cmd/diff/renderer/comp_diff_renderer_test.go | Adds JSON/text renderer tests and HasChanges() behavior coverage for filtered-only impacts. |
| cmd/diff/main.go | Tag-formatting-only changes in common CLI flags. |
| cmd/diff/diffprocessor/comp_processor.go | Adds resource-mode preflight, update-policy partitioning, and filtered-by-policy surfacing behavior. |
| cmd/diff/diffprocessor/comp_processor_test.go | Updates signatures and adds unit tests for --resource mode behavior and preflight failure. |
| cmd/diff/diff_integration_test.go | Extends integration harness to pass --resource and adds integration coverage for the feature. |
| cmd/diff/comp.go | Adds --resource flag, parsing, validation, and wiring into the processor call. |
| cmd/diff/comp_test.go | Adds unit tests for resource ref parsing and flag mutual exclusion validation. |
| cmd/diff/client/crossplane/composition_client.go | Adds GetCompositesByName implementation used by the preflight resolver. |
| cmd/diff/client/crossplane/composition_client_test.go | Adds unit tests for GetCompositesByName across XR/claim and error paths. |
| .requirements/20260518T224830Z_comp_resource_filter/REQUIREMENTS.md | Design/requirements doc capturing intent, behavior, and test plan. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+899
to
+906
| unmatched = append(unmatched, ref) | ||
|
|
||
| continue | ||
| case !apierrors.IsNotFound(err): | ||
| return nil, nil, errors.Wrapf(err, "cannot fetch composite %s as %s", ref.String(), xrGVK) | ||
| } | ||
|
|
||
| // XR-GVK was 404. Try claim GVK if available. |
|
|
||
| return types.ResourceRef{Namespace: ns, Name: name}, nil | ||
| default: | ||
| return types.ResourceRef{}, errors.Errorf("invalid --resource value %q: expected [namespace/]name format, got %d slash-separated parts", value, len(parts)-1) |
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.
Description of your changes
Fixes #321
I have:
earthly -P +reviewableto ensure this PR is ready for review.[ ] Followed the API promotion workflow if this PR introduces, removes, or promotes an API.Need help with this checklist? See the cheat sheet.