Skip to content

fix(render): support repeating --required-resources and --extra-resources#107

Open
chaitanyapantheor wants to merge 1 commit into
crossplane:mainfrom
chaitanyapantheor:issues/90
Open

fix(render): support repeating --required-resources and --extra-resources#107
chaitanyapantheor wants to merge 1 commit into
crossplane:mainfrom
chaitanyapantheor:issues/90

Conversation

@chaitanyapantheor

Copy link
Copy Markdown

Summary

Fixes #90

--required-resources and --extra-resources (deprecated) on crossplane render xr and crossplane render op silently ignored all but the last occurrence when the flag was repeated. Resources from earlier flags were dropped with no error or warning, causing functions that needed those resources to receive an empty set.

Root cause: The fields were declared as string instead of []string. Kong's CLI parser silently overwrites a string field on repeated flags, keeping only the last value.

Fix: Change both flags to []string and loop over all provided paths in Run(), merging resources from every file/directory into a single slice.

Test Plan

  • Added MultipleRequiredResourcesFirstMissing test to render xr — verifies an error on the first of two files propagates (previously silently dropped)
  • Added MultipleExtraResourcesFirstMissing test to render xr — same for deprecated --extra-resources
  • Added MultipleRequiredResourcesFirstMissing test to render op
  • Updated existing LoadRequiredResourcesError tests to use []string
  • Full test suite passes (go test ./...)

Example

# Before: only resources-b.yaml was loaded; resources-a.yaml was silently dropped
crossplane render xr xr.yaml composition.yaml functions.yaml \
  --required-resources resources-a.yaml \
  --required-resources resources-b.yaml

# After: both files are loaded and merged
crossplane render xr xr.yaml composition.yaml functions.yaml \
  --required-resources resources-a.yaml \
  --required-resources resources-b.yaml

🤖 Generated with Claude Code

@chaitanyapantheor chaitanyapantheor requested review from phisco and removed request for a team June 13, 2026 17:00
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@chaitanyapantheor, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 36 minutes and 7 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7b94f82e-b82d-4b7a-b596-0e6ae2908b87

📥 Commits

Reviewing files that changed from the base of the PR and between 11e8bc2 and 7caefa1.

📒 Files selected for processing (4)
  • cmd/crossplane/render/op/cmd.go
  • cmd/crossplane/render/op/cmd_test.go
  • cmd/crossplane/render/xr/cmd.go
  • cmd/crossplane/render/xr/cmd_test.go
📝 Walkthrough

Walkthrough

This PR fixes issue #90 and adds OCI annotation support. The render op and render xr commands now accumulate all --required-resources and --extra-resources flags instead of silently dropping all but the last. The push command gains repeatable --oci-annotation KEY=VALUE support with annotation metadata applied to images and indexes before writing.

Changes

Render and Push Command Improvements

Layer / File(s) Summary
Render op command - multi-resource support
cmd/crossplane/render/op/cmd.go, cmd/crossplane/render/op/cmd_test.go
RequiredResources becomes a []string slice, and Run iterates over all provided resource paths, loading and accumulating them. Tests verify both single and multiple resource loading with proper error handling when resources are missing.
Render xr command - multi-resource support
cmd/crossplane/render/xr/cmd.go, cmd/crossplane/render/xr/cmd_test.go
Both ExtraResources and RequiredResources become []string slices. Loading logic replaces conditional single-path checks with iteration over all provided paths, accumulating results in order (required first, extra second). Tests verify error propagation when any resource path is missing.
OCI annotation parsing and application helpers
cmd/crossplane/xpkg/annotations.go, cmd/crossplane/xpkg/annotations_test.go
New annotation infrastructure: parseAnnotations converts key=value strings into a map (validating format and rejecting empty keys), annotateImage applies annotations to OCI images when non-empty, and annotateIndex applies annotations to OCI indexes. Comprehensive tests cover valid entries, multiple = characters in values, malformed input, and empty slices.
Push command - OCI annotation integration
cmd/crossplane/xpkg/push.go
Introduces repeatable --oci-annotation CLI flag. Run parses annotations via parseAnnotations, wraps parse errors, and passes the annotation map through pushImages. Single-image and multi-image push paths each call annotateImage before writing, and the final OCI index is annotated via annotateIndex before remote.WriteIndex.
Supporting updates
cmd/crossplane/xpkg/batch.go, cmd/crossplane/xpkg/build.go
pushImages call in pushWithRetry is updated with the new annotations parameter. Build command help text is clarified for the --ignore flag, documenting comma-separated paths, wildcard support, and directory exclusion behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

backport release-2.3

Suggested reviewers

  • tampakrap
  • jcogilvie
🚥 Pre-merge checks | ✅ 4 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title is 73 characters, exceeding the 72-character limit, but clearly describes the main change: enabling repeating flags for required and extra resources. Shorten the title to 72 characters or fewer while preserving clarity, for example: 'fix(render): support repeating --required/extra-resources'
Out of Scope Changes check ⚠️ Warning Changes to annotations.go, annotations_test.go, batch.go, build.go, and push.go appear unrelated to the core fix for repeating flags in render commands. Clarify whether annotation-related changes are necessary for this PR. Consider separating unrelated xpkg annotation work into a different pull request to keep scope focused.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the bug, root cause, fix, test coverage, and provides a concrete example related to the changeset.
Linked Issues check ✅ Passed The PR implementation fully addresses issue #90 by converting string fields to []string slices and iterating over all provided paths to merge resources from every occurrence.
Breaking Changes ✅ Passed cmd/crossplane/render/{op,xr}/cmd.go keeps the same --required-resources/--extra-resources flags (short/name unchanged) and now loops over all paths (string→[]string); no flags/behavior removed and...
Feature Gate Requirement ✅ Passed PR only fixes repeatable --required-resources/--extra-resources handling by switching fields to []string and iterating all paths; no new experimental apis/** feature or feature-flag toggle was intr...

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
cmd/crossplane/xpkg/annotations_test.go (1)

26-86: ⚡ Quick win

Add test case for empty key validation.

The parseAnnotations function validates that keys are non-empty (annotations.go line 37-39), but there's no test case exercising this validation. Consider adding:

"EmptyKey": {
    reason: "An entry with an empty key should return an error.",
    args:   args{kvs: []string{"=value"}},
    want:   want{err: cmpopts.AnyError},
},

This ensures the validation path is covered.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/crossplane/xpkg/annotations_test.go` around lines 26 - 86, Add a test
case to TestParseAnnotations that verifies parseAnnotations rejects an empty
key: insert a case named "EmptyKey" into the cases map in annotations_test.go
with reason "An entry with an empty key should return an error.", args {kvs:
[]string{"=value"}}, and want {err: cmpopts.AnyError}; this exercises the
parseAnnotations validation logic (the code that checks for empty keys) and
ensures the error path is covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/crossplane/xpkg/annotations_test.go`:
- Around line 26-86: Add a test case to TestParseAnnotations that verifies
parseAnnotations rejects an empty key: insert a case named "EmptyKey" into the
cases map in annotations_test.go with reason "An entry with an empty key should
return an error.", args {kvs: []string{"=value"}}, and want {err:
cmpopts.AnyError}; this exercises the parseAnnotations validation logic (the
code that checks for empty keys) and ensures the error path is covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fb337407-fde5-46b9-92c1-3275037d83b0

📥 Commits

Reviewing files that changed from the base of the PR and between 1cfeb97 and 11e8bc2.

📒 Files selected for processing (9)
  • cmd/crossplane/render/op/cmd.go
  • cmd/crossplane/render/op/cmd_test.go
  • cmd/crossplane/render/xr/cmd.go
  • cmd/crossplane/render/xr/cmd_test.go
  • cmd/crossplane/xpkg/annotations.go
  • cmd/crossplane/xpkg/annotations_test.go
  • cmd/crossplane/xpkg/batch.go
  • cmd/crossplane/xpkg/build.go
  • cmd/crossplane/xpkg/push.go

@chaitanyapantheor chaitanyapantheor force-pushed the issues/90 branch 2 times, most recently from 8519911 to 11e8bc2 Compare June 13, 2026 17:17
…rces

The flags were declared as `string` instead of `[]string`, so Kong's CLI
parser silently overwrote the value on each repetition, keeping only the
last occurrence. Resources from all earlier flags were dropped with no
error or warning.

Change both flags to `[]string` and loop over the slice in Run(), merging
resources from every provided path into a single slice. The deprecated
--extra-resources flag in `render xr` is fixed in the same way.

Fixes crossplane#90

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Chaitanya Maili <chaitanya.maili@pantheon.io>
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.

crossplane render only honors the LAST --extra-resources flag

1 participant