fix(common/load/streamToUnstructured): skip empty documents - #241
Conversation
Signed-off-by: Nikita Z <nkzk95@gmail.com>
📝 WalkthroughWalkthroughChangesEmpty document handling
Estimated code review effort: 1 (Trivial) | ~3 minutes Suggested reviewers: Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error)
✅ Passed checks (5 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cmd/crossplane/common/load/loader_test.go (1)
489-497: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a regression case for comment-only documents.
Thanks for covering empty byte documents. The PR objective also includes YAML documents that contain only comments. Add a table entry such as
[]byte("# comment only\n")and expect an empty non-nilresourcesslice with no error.🤖 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/common/load/loader_test.go` around lines 489 - 497, Extend the table-driven cases in the loader test around “SkipEmptyDocuments” with a comment-only YAML stream such as []byte("# comment only\n"). Assert no error and an empty, non-nil resources slice, matching the existing empty-byte document expectations.
🤖 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/common/load/loader_test.go`:
- Around line 489-497: Extend the table-driven cases in the loader test around
“SkipEmptyDocuments” with a comment-only YAML stream such as []byte("# comment
only\n"). Assert no error and an empty, non-nil resources slice, matching the
existing empty-byte document expectations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: b8dc6e85-c7d7-46a1-9216-8dd2d4163d63
📒 Files selected for processing (2)
cmd/crossplane/common/load/loader.gocmd/crossplane/common/load/loader_test.go
… comment ref. coderabbit suggestion Signed-off-by: Nikita Z <nkzk95@gmail.com>
Description of your changes
Reimplementing crossplane/crossplane#7089.
The
streamToUnstructured()function loads a stream of yaml into unstructured objects, and is used by different Loaders during beta validate.If a yaml document in the stream only contains a comment, or the file is empty, this function will currently not fail, but add an empty object to the unstructured array, resulting in this warning during validation in
resource validate: [!] could not find CRD/XRD for: /, Kind=A simple example of where this might be an issue:
We generate the rendered resources that should be validated with a tool that wraps around crossplane render functionality.
Since we want the user to know that these files were generated, we add the following comment at the top:
But these comment results in the empty document issue when passing this file to the validate command.
Since this is valid yaml i believe the best thing is to fix what i believe is a logical issue in this function, instead of changing the generated file to accommodate.
I added a test and fix that ensures streamToUnstructured() skips empty objects like this.
I have:
./nix.sh flake checkto ensure this PR is ready for review.- [] Linked a PR or a docs tracking issue to document this change.- [ ] Addedbackport release-x.ylabels to auto-backport this PR.Need help with this checklist? See the cheat sheet.