Skip to content

fix: loaded XRD must honor the composite schema#123

Open
fernandezcuesta wants to merge 1 commit into
crossplane:mainfrom
fernandezcuesta:118--support-legacy-xrd
Open

fix: loaded XRD must honor the composite schema#123
fernandezcuesta wants to merge 1 commit into
crossplane:mainfrom
fernandezcuesta:118--support-legacy-xrd

Conversation

@fernandezcuesta

@fernandezcuesta fernandezcuesta commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Description of your changes

The XRD was loaded and used for applying defaults, but never passed to CompositionInputs. The render engine comment explicitly says:

when nil the binary falls back to its default behavior (Schema=Modern)

For LegacyCluster XRDs, this means resourceRefs end up at spec.crossplane.resourceRefs instead of spec.resourceRefs, which is incorrect and furtherly causing a validation error.

Fixes #118

I have:

Need help with this checklist? See the cheat sheet.

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
@fernandezcuesta fernandezcuesta changed the title fix: loaded XRD must honor the schmea fix: loaded XRD must honor the schema Jun 17, 2026
@fernandezcuesta fernandezcuesta changed the title fix: loaded XRD must honor the schema fix: loaded XRD must honor the composite schema Jun 17, 2026
@fernandezcuesta fernandezcuesta marked this pull request as ready for review June 18, 2026 05:43
@fernandezcuesta fernandezcuesta requested review from a team, jcogilvie and tampakrap as code owners June 18, 2026 05:43
@fernandezcuesta fernandezcuesta requested review from negz and removed request for a team June 18, 2026 05:44
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The render xr command changes how an optional --xrd input is handled: the loaded XRD object is now converted to *unstructured.Unstructured using kruntime.DefaultUnstructuredConverter.ToUnstructured and forwarded to render.BuildCompositeRequest via a new XRD field on render.CompositionInputs, replacing the prior in-place XR defaulting behavior. A new test case and xrd.yaml fixture verify the engine receives the XRD.

Changes

XRD Forwarding to Render Engine

Layer / File(s) Summary
XRD unstructured conversion and CompositionInputs wiring
cmd/crossplane/render/xr/cmd.go
Adds the kruntime import alias, introduces xrdUnstructured, replaces the prior XRD-defaulting block with DefaultUnstructuredConverter.ToUnstructured, and sets XRD: xrdUnstructured on the render.CompositionInputs passed to BuildCompositeRequest.
Test: XRDPassedToEngine case and xrd.yaml fixture
cmd/crossplane/render/xr/cmd_test.go
Adds the xrdYAML embedded fixture and a new table test case that sets Cmd.XRD, asserts GetCompositeResourceDefinition() is non-nil inside MockRender, and validates stdout matches successOutput.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • crossplane/cli#61: Directly modifies the same --xrd handling flow in cmd/crossplane/render/xr/cmd.go, making it a predecessor to the refactoring introduced here.

Suggested reviewers

  • jcogilvie
  • negz
  • adamwg
🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely describes the fix: ensuring loaded XRD schemas are honored during composition rendering, directly addressing the core issue.
Linked Issues check ✅ Passed The code changes directly address issue #118 by modifying the render command to pass the loaded XRD to CompositionInputs, ensuring legacy schemas honor resourceRef placement correctly.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the XRD schema handling in render xr command and corresponding tests, with no unrelated modifications.
Breaking Changes ✅ Passed No breaking changes: The PR only adds optional fields (XRD in Cmd struct and CompositionInputs), removes no public fields/flags, adds no required fields, and doesn't remove behavior.
Feature Gate Requirement ✅ Passed PR is a bug fix that populates an existing optional field in CompositionInputs; affects only cmd/crossplane/render/xr (not apis/**) and requires no feature flag.
Description check ✅ Passed The pull request description clearly explains the bug being fixed—XRD not being passed to CompositionInputs causes incorrect field placement in legacy schemas, leading to validation errors. It includes context, justification, and references issue #118.

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

🧹 Nitpick comments (1)
cmd/crossplane/render/xr/cmd_test.go (1)

488-490: ⚡ Quick win

Harden XRDPassedToEngine by asserting XRD shape, not only non-nil.

Line 488 currently validates presence only. Could we also assert a stable field (e.g., spec) so the test guarantees the loaded XRD payload is actually forwarded?

Suggested assertion tightening
- if req.GetComposite().GetCompositeResourceDefinition() == nil {
- 	t.Error("expected render request to contain the XRD, got nil")
- }
+ xrd := req.GetComposite().GetCompositeResourceDefinition()
+ if xrd == nil {
+ 	t.Fatal("expected render request to contain the XRD, got nil")
+ }
+ if _, ok := xrd.GetFields()["spec"]; !ok {
+ 	t.Errorf("expected forwarded XRD to include spec, got fields: %v", xrd.GetFields())
+ }
🤖 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/render/xr/cmd_test.go` around lines 488 - 490, The current
test assertion in the XRDPassedToEngine test only validates that
GetCompositeResourceDefinition() returns a non-nil value, but does not verify
that the actual XRD payload contains expected structure. Enhance the assertion
by adding a check for a stable field such as spec on the returned XRD object to
ensure the loaded XRD is properly forwarded to the engine. This tightens the
test and guarantees the XRD payload shape, not just its presence.
🤖 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/render/xr/cmd_test.go`:
- Around line 488-490: The current test assertion in the XRDPassedToEngine test
only validates that GetCompositeResourceDefinition() returns a non-nil value,
but does not verify that the actual XRD payload contains expected structure.
Enhance the assertion by adding a check for a stable field such as spec on the
returned XRD object to ensure the loaded XRD is properly forwarded to the
engine. This tightens the test and guarantees the XRD payload shape, not just
its presence.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6d4de0f5-81fd-4a70-b6d8-cb84f87ae6e8

📥 Commits

Reviewing files that changed from the base of the PR and between b869d00 and 8b193e8.

⛔ Files ignored due to path filters (1)
  • cmd/crossplane/render/xr/testdata/cmd/xrd.yaml is excluded by !**/testdata/** and included by **/*.yaml
📒 Files selected for processing (2)
  • cmd/crossplane/render/xr/cmd.go
  • cmd/crossplane/render/xr/cmd_test.go

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.

Can't validate v1/legacy compositions

1 participant