Skip to content

feat(comp): allow filtering downstream resources#322

Open
jcogilvie wants to merge 2 commits into
mainfrom
comp-resource-filter
Open

feat(comp): allow filtering downstream resources#322
jcogilvie wants to merge 2 commits into
mainfrom
comp-resource-filter

Conversation

@jcogilvie
Copy link
Copy Markdown
Collaborator

@jcogilvie jcogilvie commented May 19, 2026

Description of your changes

Fixes #321

I have:

  • Read and followed Crossplane's contribution process.
  • Run earthly -P +reviewable to ensure this PR is ready for review.
  • Added or updated unit tests.
  • Added or updated e2e tests.
  • Documented this change as needed.
  • [ ] Followed the API promotion workflow if this PR introduces, removes, or promotes an API.

Need help with this checklist? See the cheat sheet.

jcogilvie added 2 commits May 19, 2026 11:36
Signed-off-by: Jonathan Ogilvie <jonathan.ogilvie@sumologic.com>
Signed-off-by: Jonathan Ogilvie <jonathan.ogilvie@sumologic.com>
@jcogilvie jcogilvie marked this pull request as ready for review May 21, 2026 20:49
Copilot AI review requested due to automatic review settings May 21, 2026 20:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --resource flag parsing/validation, including mutual exclusion with --namespace, and [namespace/]name parsing.
  • 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.
Comment thread cmd/diff/comp.go

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Supporting comp for a list of specific resources

2 participants