Guard pod-spec type assertions against non-map manifest fields - #1215
Open
arpitjain099 wants to merge 1 commit into
Open
arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
GetPodSpec and GetPodTemplate recurse through the podSpecFields (jobTemplate, spec, template) with an unchecked type assertion childYaml.(map[string]any). A malformed manifest whose nested field is a scalar instead of a map makes that assertion panic and aborts the scan. Use the comma-ok assertion so a non-map value is skipped and the walk returns cleanly with no pod spec found, matching the sibling guard already used for the spec map at resource.go:283. Adds a test covering a scalar spec field for both functions. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
arpitjain099
requested review from
jdesouza,
sudermanjr and
vitorvezani
as code owners
July 23, 2026 16:43
This branch has not been deployed
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.
This PR fixes #
Checklist
Description
What's the goal of this PR?
Keep a scan from panicking on a malformed manifest.
GetPodSpecandGetPodTemplatewalkpodSpecFields(jobTemplate,spec,template) recursively and do an uncheckedchildYaml.(map[string]any)assertion on each. If one of those fields is a scalar instead of a map, the assertion panics and takes down the whole scan.Reproduced with a manifest whose
specis a string. Before the fix the panic surfaces atpkg/kube/resource.go:269:What changes did you make?
Switched the two assertions (in
GetPodSpecandGetPodTemplate) to the comma-ok form, so a non-map value is skipped and the walk returns cleanly with no pod spec / template found. This matches the guard already used for thespecmap a few lines up inGetPodTemplate(if yamlSpecMap, ok := yamlSpec.(map[string]any); ok).Added
TestGetPodSpecNonMapField, which feeds a manifest with a scalarspecand asserts neither function panics and both return nil. With the fix reverted the test panics as above; with it in placego test ./pkg/kube/passes.What alternative solution should we consider, if any?
Could validate/normalize the manifest shape earlier in the pipeline, but guarding the assertions here is the smaller change and lines up with the existing comma-ok pattern in the same function.