-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Give validation errors on unknown config fields #1246
Conversation
I don't know what the "UnmarshalStrictIgnoringFields" was made for, apparently a field called "interval" has caused problems, maybe telemetry related. |
There's also |
1643f78
to
6e7ea2f
Compare
Signed-off-by: Kimmo Lehto <[email protected]> Tab sneaked into test Signed-off-by: Kimmo Lehto <[email protected]> Better implementation Signed-off-by: Kimmo Lehto <[email protected]>
6e7ea2f
to
a7418a6
Compare
} | ||
return nil | ||
decoder := json.NewDecoder(bytes.NewReader(data)) | ||
decoder.DisallowUnknownFields() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the yaml package already turns DisallowUnknownFields
on. Will turning it on here solve our issue?
https://github.com/kubernetes-sigs/yaml/blob/39f74b9b8a135185d095704ab98c760ca031a9f8/yaml.go#L63-L64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The json.Unmarshal
in the UnmarshalJSON
function creates a new decoder that doesn't know anything about the DisallowUnknownFields
set by the yaml thing.
The yaml.Unmarshalstrict is already turning on the DisallowUnknownFields option for the json unmarshaller. If this is not working as intended, I think a better route would be to submit a fix upstream. |
I don't think it's possible to fix in upstream. The func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
// do stuff
if err := unmarshal(yc); err != nil { // this function can inherit options from the original decoder
return err
}
return nil
} func (c *Config) UnmarshalJSON(data []byte) error {
// do stuff
if err := json.Unmarshal(data, c); err != nil { // this can not
return err
}
return nil
} |
Btw, I think the |
Yes, that is correct. There is an issue about this same problem already open upstream: kubernetes-sigs/yaml#15 |
Signed-off-by: Kimmo Lehto <[email protected]> Tab sneaked into test Signed-off-by: Kimmo Lehto <[email protected]> Better implementation Signed-off-by: Kimmo Lehto <[email protected]>
Signed-off-by: Kimmo Lehto [email protected]
As mentioned in #1237 (comment) - the unknown field validation has not been working as intended since the move to https://sigs.k8s.io/yaml
Seems what breaks it is the
UnmarshalJSON
function which runs basicjson.Unmarshal
, which will lose the strictness. This PR makes it use theDisallowUnknownFields
JSON decoder option.