fix(autodiscovery/kubernetes): handle empty yaml#8943
Merged
Conversation
Signed-off-by: Olblak <[email protected]>
1 task
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a nil-pointer panic in the Kubernetes autodiscovery crawler introduced when support for multi-document YAML was added, by ensuring empty YAML documents don’t produce nil decoded structs and by safely skipping any nil entries during discovery.
Changes:
- Skip storing
nildecoded documents ingetManifestDatato avoid propagating empty YAML docs. - Add
nilguards in Kubernetes and Prow manifest discovery loops. - Extend test coverage with empty-YAML fixtures and allow “no manifest” scenarios to pass.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/plugins/autodiscovery/kubernetes/utils.go | Avoids inserting nil decoded YAML documents into the returned map. |
| pkg/plugins/autodiscovery/kubernetes/utils_test.go | Updates file-search expectations to include new empty YAML fixtures. |
| pkg/plugins/autodiscovery/kubernetes/testdata/empty/kubernetes.1.yaml | Adds an empty YAML fixture file (0 bytes) for regression coverage. |
| pkg/plugins/autodiscovery/kubernetes/testdata/empty/kubernetes.2.yaml | Adds an “empty document” YAML fixture (---) for regression coverage. |
| pkg/plugins/autodiscovery/kubernetes/prow.go | Skips nil document entries during Prow manifest discovery to prevent panics. |
| pkg/plugins/autodiscovery/kubernetes/main.go | Adjusts handling/logging when no working directory is defined. |
| pkg/plugins/autodiscovery/kubernetes/main_test.go | Adds a “no manifest” test case and removes the hard failure on zero pipelines. |
| pkg/plugins/autodiscovery/kubernetes/kubernetes.go | Skips nil document entries during Kubernetes manifest discovery to prevent panics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fix #8915
In version v0.115.0 we introduced the ability to update multiple YAML document but I didn't handle well test case where an empty yaml was loaded which would result to its data to be set to nil. I fix the problem and added a test case
Test
To test this pull request, you can run the following commands:
Additional Information
Checklist
Tradeoff
Potential improvement