yannh / kubeconform

A FAST Kubernetes manifests validator, with support for Custom Resources!
Apache License 2.0
2.15k stars 121 forks source link

better error message #207

Closed DanielYWoo closed 1 year ago

DanielYWoo commented 1 year ago

The error message can be better. e.g., for the YAML below

~                              | 24       source:
~                              | 25         repoURL: https://somerepo
~                              | 26         targetRevision: main
~                              | 27         path: ./
~                              | 28         helm:
~                              | 29           releaseName: plt
~                              | 30           valueFiles:
~                              | 31             - overrides/values.yaml # default
~                              | 32             - overrides/{{region}}/{{env}}/values.yaml # per env override
~                              | 33           parameters: # values that can be inferred from appset
~                              | 34             - name: "consul.global.datacenter"
~                              | 35               value: {{region}}-{{env}}

kubeconform tells me something is wrong, but ain't tell me what is wrong.

failed validation: error unmarshalling resource: error converting YAML to JSON: yaml: line 34: did not find expected key
eyarz commented 1 year ago

the curly brackets ({}) are invalid yaml characters. you should build your manifest and only then pass it to kubeconform for validation.

DanielYWoo commented 1 year ago

I fixed it by extra double quotes around the literals. I guess this is a very special case, for normal helm or kustomize YAML I can render them locally then let kubeconform deal with it. This code snippet is from an ArgoCD application set, I cannot find a way to render it locally without ArgoCD, so I have to pass it to kubeconform. ;-)

eyarz commented 1 year ago

so in this case the solution is passing it as a string as you found out :)

DanielYWoo commented 1 year ago

Yes, I figured it out, but, is it possible to print a better error message by any chance?

eyarz commented 1 year ago

sure! It's an open-source project, so you or someone from the community is more than welcome to contribute a PR

yannh commented 1 year ago

Hi @DanielYWoo , it looks like the error comes from the Go YAML parser Kubeconform uses https://github.com/kubernetes-sigs/yaml (the one Kubernetes uses too, I believe) which relies on https://github.com/go-yaml/yaml - which throws this error. A nicer error would be good, but it requires fixing a number of external dependencies which falls a bit outside of the time I can allocate to this project. Sorry :(