Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type assertion error with bool keys #91

Closed
Zertsov opened this issue Aug 21, 2018 · 7 comments · Fixed by #143
Closed

Type assertion error with bool keys #91

Zertsov opened this issue Aug 21, 2018 · 7 comments · Fixed by #143

Comments

@Zertsov
Copy link

Zertsov commented Aug 21, 2018

In the following yaml, when kubeval goes over it, there's a type assertion error in the utils.go for a boolean value. This causes a panic, and therefore should be fixed instead of ending the execution of whatever program is using the lib.

https://pastebin.com/p8TWvL1K

@Zertsov
Copy link
Author

Zertsov commented Aug 21, 2018

Note that this is a completely valid YAML file, although not a Kubernetes yaml

@garethr
Copy link
Collaborator

garethr commented Aug 21, 2018

Thanks for reporting. Could you include the output you see and an example kubernetes config that triggers it? I can add that to the acceptance tests which makes fixing easier.

@garethr garethr added the bug label Aug 21, 2018
@Zertsov
Copy link
Author

Zertsov commented Aug 21, 2018

The error I get is panic: interface conversion: interface {} is bool, not string on the given link I posted with the YAML it failed on.

@Zertsov
Copy link
Author

Zertsov commented Aug 21, 2018

So it's not that it's a kubernetes config, but the way the convertToStringKeys function is going through that yaml is incorrect, as it's seeing a key as true which isn't in the valid pastebin yaml.

My fix in the meantime was to just have my own struct look for the Kind: key in the yaml which is not a very good solution but otherwise the panic causes the app to crash.

@Zertsov
Copy link
Author

Zertsov commented Dec 5, 2018

@garethr Any update on this issue? I'm revisiting an old product I wrote and wanted to use this but need this issue resolved first.

@Zertsov
Copy link
Author

Zertsov commented Dec 11, 2018

In case anyone else is having this issue, the way I'm working around it is to just recover from the panic and warn the user that it recovered from a panic 🤷‍♂️

defer func() {
	if r := recover(); r != nil {
		logger.Warn("Recovered from panic while validating file: " + path)
	}
}()

results, err := kubeval.Validate(fileContents, path)
...

@garethr
Copy link
Collaborator

garethr commented Apr 26, 2019

This is also the same issue as #98, that one has an int rather than a bool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants