Log more info when validation fails due to unexpected fields on a resource
#94 创建于 2024年3月18日
仓库指标
- Star
- (268 star)
- PR 合并指标
- (PR 指标待抓取)
描述
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.