-
Notifications
You must be signed in to change notification settings - Fork 1.5k
baremetal: validate hosts number #3392
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
baremetal: validate hosts number #3392
Conversation
pkg/types/baremetal/platform.go
Outdated
|
|
||
| // Hosts is the information needed to create the objects in Ironic. | ||
| Hosts []*Host `json:"hosts" validate:"omitempty,dive"` | ||
| Hosts []*Host `json:"hosts" validate:"hostscount,omitempty,dive"` |
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.
I'm a little bit hesitant to say we should use annotations for all validations.
This isn't reusable for anything else, unlike other validations. TBH, I think it makes sense for this just to be a normal validation with a very simple check in the body of the ValidatePlatform function. I would find that code easier to read.
What do you think?
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.
Also: what does 'dive' mean?
Nevermind, I see: https://godoc.org/gopkg.in/go-playground/validator.v9#hdr-Dive
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.
Well, I also had some doubts about the reusability of this rule and agreed that very likely it will not be reusable elsewhere. I followed such approach for a matter of maintenance/readability (it is sufficient to look at the struct tags to understand all the validations applied to a given field) and because the boilerplate code required to add a new validation rule was essentially the same in this case (types.InstallConfig must always be passed as a contextual info to apply the cross-struct validation). I can revert it back to a normal validation to see how it looks like.
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.
i think this is mis-use of the context.
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.
config and uniqueValues are required contextual information to apply correctly the rules. customErrs is a necessary workaround required to build as much as possible a generic messaging layer that will adapt to the current one and will allow to reuse the pre-existing rules (and it could be removed once the issue go-playground/validator#506 will be fixed). The usage of context in this case will allow more decoupling between the definition and calling of validation rules, that in theory could be pretty far each other (instead of closures)
506f5f8 to
c5268dd
Compare
|
/test pj-rehearse |
|
pj-rehearse is only a job on openshift/release You can do this to retest: /retest |
|
/retest |
1 similar comment
|
/retest |
|
/test e2e-metal-ipi |
|
Thanks this looks great. Would it be difficult to separate out the hosts count validation from the refactor into a separate PR? I want to get the hosts count validation merged now, but then look closer at the refactor with the context stuff. I think it doesn't make sense now to combine the refactor if the count validation is by itself. |
Sure, I'll rework the current PR just to keep the validation as it is without the refactoring, an move it eventually to another PR; note that until we'll want to share the validations across the code the refactoring is not yet required, let me know what you think about it. |
c5268dd to
0838dae
Compare
|
Reworked PR so that it contains just the plain validation rule without any refactoring |
0838dae to
19f9c83
Compare
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.
With really nested values, the excessive calls to build are distracting. Is it avoidable? Maybe by using a builder interface, you could have Compute's build call it on the passed arguments, for example?
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.
Sounds a good idea, the syntax looks less heavy, pushed it (version with no interface) (could be also extended directly to the test struct).
|
/lgtm |
|
Please have a look @abhinavdahiya, as this modifies files in |
|
/assign @abhinavdahiya |
19f9c83 to
f213bb4
Compare
|
/test e2e-metal-ipi |
/approve personally the commit message in the PR is missing any details on what new validation is being added, also sending in the entire install-config to a function |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: abhinavdahiya, stbenjam The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
f213bb4 to
9cf5134
Compare
New validation rule to verify that the hosts specified in the baremetal platform configuration is at least the amount of configured replicas for ControlPlane and Compute nodes
9cf5134 to
c6f4c29
Compare
|
Thanks for updating the commit message. I think this looks ok, will wait to see results of e2e-metal-ipi first, though. |
|
/lgtm |
|
@andfasano: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
This PR adds a new Baremetal platform validation rule to verify that the configured hosts are equal or greater than the sum of the configured ControlPlane and Compute replicas.
In addition, it contains refactoring steps to: