Skip to content

Guard pod-spec type assertions against non-map manifest fields - #1215

Open
arpitjain099 wants to merge 1 commit into
FairwindsOps:masterfrom
arpitjain099:fix/podspec-nonmap-panic
Open

arpitjain099 wants to merge 1 commit into
FairwindsOps:masterfrom
arpitjain099:fix/podspec-nonmap-panic

Conversation

@arpitjain099

@arpitjain099 arpitjain099 commented Jul 23, 2026 •

Copy link
Copy Markdown

This PR fixes #

Checklist

  • I have signed the CLA
  • I have updated/added any relevant documentation

Description

What's the goal of this PR?

Keep a scan from panicking on a malformed manifest. GetPodSpec and GetPodTemplate walk podSpecFields (jobTemplate, spec, template) recursively and do an unchecked childYaml.(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 spec is a string. Before the fix the panic surfaces at pkg/kube/resource.go:269:

interface conversion: interface {} is string, not map[string]interface {}
        /tmp/polaris/pkg/kube/resource.go:269

What changes did you make?

Switched the two assertions (in GetPodSpec and GetPodTemplate) 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 the spec map a few lines up in GetPodTemplate (if yamlSpecMap, ok := yamlSpec.(map[string]any); ok).

Added TestGetPodSpecNonMapField, which feeds a manifest with a scalar spec and asserts neither function panics and both return nil. With the fix reverted the test panics as above; with it in place go 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.

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>
@CLAassistant

CLAassistant commented Jul 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the stale Marked as stale by stalebot label Sep 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Marked as stale by stalebot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants