Skip to content
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

Merged
merged 2 commits into from
Nov 13, 2019
Merged

Conversation

jakubdyszkiewicz
Copy link
Contributor

Summary

Mesh entity validation

@jakubdyszkiewicz jakubdyszkiewicz requested review from yskopets and a team November 13, 2019 09:47
return verr
}

func validateLoggingTcp(tcp_ *mesh_proto.LoggingBackend_Tcp_) validators.ValidationError {
Copy link
Contributor

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
Copy link
Contributor

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 ?

Comment on lines 35 to 37
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))
Copy link
Contributor

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() ?

Copy link
Contributor Author

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))
Copy link
Contributor

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

@jakubdyszkiewicz jakubdyszkiewicz merged commit 3508cc7 into master Nov 13, 2019
@jakubdyszkiewicz jakubdyszkiewicz deleted the feature/mesh-validation branch November 13, 2019 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants