Skip to content

xrd: Handle v2 XRDs in crossplane xrd convert#122

Merged
adamwg merged 1 commit into
crossplane:mainfrom
adamwg:awg/convert-v2-xrd
Jun 16, 2026
Merged

xrd: Handle v2 XRDs in crossplane xrd convert#122
adamwg merged 1 commit into
crossplane:mainfrom
adamwg:awg/convert-v2-xrd

Conversation

@adamwg

@adamwg adamwg commented Jun 16, 2026

Copy link
Copy Markdown
Member

Description of your changes

Previously, the crossplane xrd convert command accepted only v1 XRDs, even though the conversion logic works fine for v2 XRDs as well. Update the GVK check to include v2 so that the command works for either XRD version.

I have:

Previously, the `crossplane xrd convert` command accepted only v1 XRDs, even
though the conversion logic works fine for v2 XRDs as well. Update the GVK check
to include v2 so that the command works for either XRD version.

Signed-off-by: Adam Wolfe Gordon <awg@upbound.io>
@adamwg adamwg requested review from a team, jcogilvie and tampakrap as code owners June 16, 2026 21:22
@adamwg adamwg requested review from phisco and removed request for a team June 16, 2026 21:22
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The xrd convert command's GVK validation is updated to accept both apiextensions/v1 and apiextensions/v2 CompositeResourceDefinition kinds. The single equality check is replaced with a slices.Contains membership check against a two-element allowed list, and the relevant imports are added.

Changes

XRD Convert v2 GVK Support

Layer / File(s) Summary
v2 GVK import and validation
cmd/crossplane/xrd/convert.go
Adds slices and the apiextensionsv2 GVK constant to imports; replaces the single v1 GroupVersionKind equality check with a slices.Contains check against a slice of both v1 and v2 allowed kinds, updating the error message to include the full allowed list.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • crossplane/cli#12: Introduced the xrd convert command including the original v1-only GroupVersionKind validation that this PR extends to support v2.

Suggested reviewers

  • jcogilvie
🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: enabling v2 XRD support in the crossplane xrd convert command. It is clear, concise, and within the 72-character limit.
Description check ✅ Passed The description clearly explains why the change was needed, what was changed, and references the underlying conversion logic working for both versions. It is directly related to the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Breaking Changes ✅ Passed The change to cmd/crossplane/xrd/convert.go extends behavior (v1 XRDs still accepted, v2 now also accepted) without removing/renaming public fields/flags, adding required fields, or removing behavi...
Feature Gate Requirement ✅ Passed Change is in cmd/ directory (not apis/**) and enables existing working v2 XRD conversion rather than introducing new experimental features, so no feature gate is required.

✏️ 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
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/crossplane/xrd/convert.go (1)

73-87: ⚠️ Potential issue | 🟡 Minor

Add test coverage for v2 XRD input to verify struct compatibility.

The code now accepts v2 XRDs via the GVK check (lines 78–81), but I notice the tests only cover v1 XRD structs. The comment in the test says "A v2 cluster-scoped XRD," but it's actually constructing a v1 struct with a v1 scope value—not testing v2 YAML input.

Since the code unmarshals directly into a apiextensionsv1.CompositeResourceDefinition struct and then passes it to the xcrd functions, it would be helpful to verify that:

  1. v2 YAML successfully unmarshals into the v1 Go struct without losing any v2-specific fields
  2. The downstream xcrd.ForCompositeResource and xcrd.ForCompositeResourceClaim calls handle the data correctly when it came from a v2 source

Could you add a test case that unmarshals actual v2 XRD YAML? This would confirm the v2 support works end-to-end.

🤖 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/xrd/convert.go` around lines 73 - 87, Add a test case that
uses actual v2 XRD YAML input (not v1 YAML with a misleading v2 comment) to
verify that v2 YAML successfully unmarshals into the
apiextensionsv1.CompositeResourceDefinition struct without data loss and that
the downstream toCRDs function correctly processes the data from v2 sources.
This test should confirm end-to-end v2 support by exercising the same code path
as the updated GVK validation check for
apiextensionsv2.CompositeResourceDefinitionGroupVersionKind.
🧹 Nitpick comments (1)
cmd/crossplane/xrd/convert.go (1)

78-85: ⚡ Quick win

Consider a more user-friendly error message format.

The current error message uses %v to format the GVK slice, which will produce verbose Go struct output like:

input is not one of [{apiextensions.crossplane.io v1 CompositeResourceDefinition} {apiextensions.crossplane.io v2 CompositeResourceDefinition}]; got ...

This format includes technical Go struct notation that may confuse CLI users. Per the coding guidelines, CLI error messages should avoid technical jargon and be meaningful to end users.

Would something like this be clearer?

return errors.Errorf("input must be a CompositeResourceDefinition with apiVersion apiextensions.crossplane.io/v1 or v2; got %s", xrd.GroupVersionKind())

Or even more concise:

return errors.Errorf("input must be a v1 or v2 XRD; got %s", xrd.GroupVersionKind().GroupVersion().String()+"/"+xrd.GroupVersionKind().Kind)

Thank you for expanding XRD support to v2!

🤖 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/xrd/convert.go` around lines 78 - 85, Replace the error
message in the XRD GroupVersionKind validation check (around the errors.Errorf
call with the xrdGVKs comparison) to provide a clearer, more user-friendly
message that avoids using %v to format the slice of GroupVersionKind structs.
Instead of showing verbose Go struct notation, craft a message that clearly
states in plain language that the input must be a CompositeResourceDefinition
with either v1 or v2 apiVersion, then include the actual GroupVersionKind that
was received. This makes the error meaningful to CLI users rather than exposing
technical Go struct details.

Source: Coding guidelines

🤖 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.

Outside diff comments:
In `@cmd/crossplane/xrd/convert.go`:
- Around line 73-87: Add a test case that uses actual v2 XRD YAML input (not v1
YAML with a misleading v2 comment) to verify that v2 YAML successfully
unmarshals into the apiextensionsv1.CompositeResourceDefinition struct without
data loss and that the downstream toCRDs function correctly processes the data
from v2 sources. This test should confirm end-to-end v2 support by exercising
the same code path as the updated GVK validation check for
apiextensionsv2.CompositeResourceDefinitionGroupVersionKind.

---

Nitpick comments:
In `@cmd/crossplane/xrd/convert.go`:
- Around line 78-85: Replace the error message in the XRD GroupVersionKind
validation check (around the errors.Errorf call with the xrdGVKs comparison) to
provide a clearer, more user-friendly message that avoids using %v to format the
slice of GroupVersionKind structs. Instead of showing verbose Go struct
notation, craft a message that clearly states in plain language that the input
must be a CompositeResourceDefinition with either v1 or v2 apiVersion, then
include the actual GroupVersionKind that was received. This makes the error
meaningful to CLI users rather than exposing technical Go struct details.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e7f75b5c-554f-41b7-8e58-d357eb57228e

📥 Commits

Reviewing files that changed from the base of the PR and between 3e9e14f and b8e942d.

📒 Files selected for processing (1)
  • cmd/crossplane/xrd/convert.go

@adamwg adamwg merged commit b869d00 into crossplane:main Jun 16, 2026
10 checks passed
@adamwg adamwg deleted the awg/convert-v2-xrd branch June 16, 2026 22:52
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.

2 participants