kubernetes-sigs / kubectl-validate

Apache License 2.0
121 stars 31 forks source link

Log more info when validation fails due to unexpected fields on a resource #94

Open blaivs opened 3 months ago

blaivs commented 3 months ago

What would you like to be added?

When validating a resource, if there's, let's say a typo on a property, the validation results in an error where no reference to the resource that failed to validate is logged. When validating a file with several resources in it, it's hard to find which to find which one errored.

Example:

apiVersion: v1
kind: ConfigMap
metadata:
  name: x.com
datas: # extra "s"
  key: value

Error message: datas: Invalid value: value provided for unknown field

So no reference to name and kind of the resource.

This happens as when resource parsing fails, it errors without parsing metadata's name. Group and kind are returned but not attached to the error. https://github.com/kubernetes-sigs/kubectl-validate/blob/e1c86ccfb5930bcf8dc827919bd8c7c991b2c738/pkg/validator/validator.go#L82 Feels like getting this basic info on the resource could be done at parse function?

Why is this needed?

It will help identifying the resource that caused the error.

alexzielenski commented 3 months ago

I agree parse errors should be accumulated and linked back to the original object. Attributing only to file makes it hard to reason about large yamls with many documents

annaelizabeth2019 commented 2 months ago

/assign

annaelizabeth2019 commented 2 months ago

unassigned myself because I'm having a bit of trouble setting up my environment and don't want to block development. I'll try a good first issue when I'm set up. :)

omerap12 commented 2 months ago

/assign