projects: Skip empty documents when applying init and extra resources - #208
Merged
haarchri merged 1 commit intoJul 23, 2026
Merged
Conversation
Contributor
📝 WalkthroughWalkthroughChangesEmpty resource handling
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
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. Comment |
Contributor
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@internal/project/install_test.go`:
- Around line 106-124: Convert the SkipsEmptyRaw test into the required
table-driven structure with args, want, and reason fields, covering the empty
raw extension alongside the real ConfigMap. Execute each case through the table
and compare returned errors using cmp.Diff with cmpopts.EquateErrors(), while
retaining assertions that the real resource is applied.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 7db5d502-960b-4229-9610-fe7d182a755b
📒 Files selected for processing (2)
internal/project/install.gointernal/project/install_test.go
crossplane project run --init-resources/--extra-resources failed with "encountered an invalid or empty raw resource" whenever a manifest began with a comment block before the first "---" separator, which is a common file header. The YAML stream loader returns that comment-only chunk as a document, it unmarshals to an empty RawExtension, and ApplyResources rejected it. kubectl skips empty and null documents; do the same in ApplyResources so an otherwise valid manifest applies instead of erroring. This fixes both --init-resources and --extra-resources, which share this code path. Fixes crossplane#207 Signed-off-by: Yury Tsarev <yury@upbound.io>
ytsarev
force-pushed
the
fix/skip-empty-init-extra-resources
branch
from
July 23, 2026 10:40
e8cb075 to
776fcd4
Compare
ytsarev
added a commit
to ytsarev/modelplane-public
that referenced
this pull request
Jul 23, 2026
The awk that strips prerequisites.yaml's leading comment-only document works around a crossplane CLI bug: `crossplane project run --init-resources` rejects an empty (comment-only) YAML document with "invalid or empty raw resource", where kubectl skips it. Filed upstream as crossplane/cli#207 with a fix in crossplane/cli#208. Once that ships, the awk can be dropped and the file passed through unmodified. Signed-off-by: Yury Tsarev <yury@upbound.io>
haarchri
approved these changes
Jul 23, 2026
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
crossplane project run --init-resources/--extra-resourcesrejected any manifest whose first YAML document is empty — most commonly a file-level comment header before the first---, a very common convention — with:The YAML stream loader (
LoadYAMLStreamFromFile) splits on---and only drops byte-empty chunks, so a comment-only chunk survives, unmarshals to an emptyruntime.RawExtension, andApplyResourcestreated that as fatal.kubectl apply -fon the identical file works because it skips empty/null documents.This changes
ApplyResourcesto skip empty raw resources (matching kubectl) instead of erroring, which fixes both--init-resourcesand--extra-resourcessince they share the path. The existingEmptyRawErrorsunit test becomesSkipsEmptyRaw, asserting an empty document is skipped and a real resource alongside it is still applied.Encountered in modelplaneai/modelplane#365 , see
run.shthere for additional context.Reproduction
Fixes #207
I have:
./nix.sh flake check— passes locally (generate-check, go-lint, and test all green for this commit). Also verifiedgo build ./...,go vet,gofmt, andgolangci-lint run(0 issues) directly.Linked a PR or a docs tracking issue to document this change.Bug fix with no user-facing docs change.AddedLeaving the backport decision to maintainers.backport release-x.ylabels to auto-backport this PR.