kubernetes-sigs/kubectl-validate

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

Open

#94 opened on Mar 18, 2024

View on GitHub
 (6 comments) (0 reactions) (1 assignee)Go (56 forks)auto 404
good first issuekind/feature

Repository metrics

Stars
 (268 stars)
PR merge metrics
 (PR metrics pending)

Description

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.

Contributor guide