-
Notifications
You must be signed in to change notification settings - Fork 327
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
feat(kuma-cp) mesh validation #430
Conversation
return verr | ||
} | ||
|
||
func validateLoggingTcp(tcp_ *mesh_proto.LoggingBackend_Tcp_) validators.ValidationError { |
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.
Let's avoid this weird name tcp_
var verr validators.ValidationError | ||
if backend.Name == "" { | ||
verr.AddViolation("name", "cannot be empty") | ||
return verr |
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.
Why aren't we checking the rest of configuration in that case ?
verr.AddError(validators.RootedAt("backends").Index(i).String(), validateBackend(backend)) | ||
if usedNames[backend.Name] { | ||
verr.AddViolationAt(validators.RootedAt("backends").Index(i).Field("name"), fmt.Sprintf("%s name is already used for another backend", backend.Name)) |
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.
How do you decide when to use verr.AddError()
and when verr.AddViolation()
?
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.
AddError
takes validators.ValidationError
and combines them, AddViolation
adds single violation
for i, backend := range logging.Backends { | ||
verr.AddError(validators.RootedAt("backends").Index(i).String(), validateBackend(backend)) | ||
if usedNames[backend.Name] { | ||
verr.AddViolationAt(validators.RootedAt("backends").Index(i).Field("name"), fmt.Sprintf("%s name is already used for another backend", backend.Name)) |
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.
Let's use %q
when reporting field values
Summary
Mesh entity validation