instrumenta / kubeval

Validate your Kubernetes configuration files, supports multiple Kubernetes versions
https://kubeval.com
Other
3.16k stars 229 forks source link

missing kind key #23

Closed devikaturi closed 7 years ago

devikaturi commented 7 years ago

I am trying to use kubeval library in my project. calling the validate function: kubeval.Validate([]byte("v1.7.2"), "D:/Playground/nginx-deployment.yaml")

Throws the following error :

Missing a kind key Whats could be the reason for the failure? am I calling the validate function in the right way?

the deployment file is valid: apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 template: metadata: labels: app: nginx spec: containers:

garethr commented 7 years ago

I'll definitely get some better documentation for using this as a library written, with some simple examples.

The first param should be the file contents, rather than the API version. And the second param is just a string used in the response.

Something like the following, obviously with proper error handling, should get you what you want I think:

fileName := "nginx-deployment.yaml"
kubeval.Version = "1.7.2"
filePath, _ := filepath.Abs(fileName)
fileContents, _ := ioutil.ReadFile(filePath)
results, err := kubeval.Validate(fileContents, fileName)

The usage around https://github.com/garethr/kubeval/blob/master/cmd/root.go#L59-L71 should give you a guide.

Please reopen if that doesn't work for you, happy to help.