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

baremetal: platform host validations #3232

Merged
merged 2 commits into from
Mar 20, 2020

Conversation

andfasano
Copy link
Contributor

This change proposes the same host validations already described in another PR (#3208 thanks to @stbenjam) but using the go-playground/validator module to make the validation process easier, reusable and more scalable, and helping in reducing the amount of code requested.
This change only affects the host validations by reusing an existing validation rule and adding a custom one for detecting duplicated values, but it could also be easily adopted for other kind of validations.

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 4, 2020
@stbenjam
Copy link
Member

stbenjam commented Mar 4, 2020

/label platform/baremetal

@openshift-ci-robot openshift-ci-robot added the platform/baremetal IPI bare metal hosts platform label Mar 4, 2020
@stbenjam
Copy link
Member

stbenjam commented Mar 4, 2020

On 45da73f, the commit message could have a little more detail. It's not just duplicates, and should mention that it's for baremetal.

@abhinavdahiya PTAL - alternative approach to #3208

@stbenjam
Copy link
Member

stbenjam commented Mar 4, 2020

/assign @abhinavdahiya

@metal3ci
Copy link

metal3ci commented Mar 4, 2020

Build FAILURE, see build http://10.8.144.11:8080/job/dev-tools/1563/

@abhinavdahiya
Copy link
Contributor

Personally I don't see how this helps, it's more magic with fields parent tags etc, uses reflect for later reporting.

The only benefit was required was reduced, and that kind of already easy to DRY out.. and in cases where required needs more special handling like required when this other thing is set, we will end up creating these new tags or write that logic anyway.

So I like the previous method as it's more easy to ready, extend.

@andfasano
Copy link
Contributor Author

Personally I don't see how this helps, it's more magic with fields parent tags etc, uses reflect for later reporting.

The only benefit was required was reduced, and that kind of already easy to DRY out.. and in cases where required needs more special handling like required when this other thing is set, we will end up creating these new tags or write that logic anyway.

So I like the previous method as it's more easy to ready, extend.

A validation rule is identified by a tag. So it's just a matter to annotate which fields of which struct are required to be validate against which rules. And the framework already offers many pre-baked rules, and by default allows to apply the validation to nested struct (see for example the validate:"required" tag on baremetal.BMC and baremetal.Host structs).
So, no additional code has been added for that and the readability has been improved as the reader can immediately understand which rules will be applied by simply looking at the struct definition.
The uniqueField custom rule is instead an example of how a custom rule could be injected in the underlying framework to address those validations that are not supported by default, and the framework makes it easy to apply to any field that has been properly tagged of any nested struct, and offers all the necessary parameters to perform the validation.
And there's no need to explicitly reference any specific field, thus allowing for a more generic implementation (and less amount of code).

@stbenjam
Copy link
Member

stbenjam commented Mar 4, 2020

I like the annotation based approach for validations, rather than having the same checks over and over again in each platform's validations. The general case is more common than a special case ("if this field, then that one" or other constraints) and would probably simplify most platforms.

@abhinavdahiya
Copy link
Contributor

more than happy to approve the vendoring after this PR is LGTM from baremetal-approvers. If the baremetal validations are more successful with this approach we can look at expanding them.

fieldValues[fieldValue] = struct{}{}
}
} else {
panic(fmt.Sprintf("Cannot apply validation rule 'uniqueField' on field %s", fl.FieldName()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panics are less desirable in the code for installer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure about the standard adopted, I noticed that it was used somewhere (https://github.com/openshift/installer/search?q=panic+-path%3A%2Fvendor&unscoped_q=panic+-path%3A%2Fvendor) and thought it could have been useful in case of configuration mistake. But if it's not I'll remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A panic seems fair here, this would only happen if a dev adds the annotation that a field is uniqueValue and it's not Comparable.

@metal3ci
Copy link

metal3ci commented Mar 6, 2020

Build FAILURE, see build http://10.8.144.11:8080/job/dev-tools/1581/

@openshift-ci-robot openshift-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 6, 2020
@metal3ci
Copy link

metal3ci commented Mar 6, 2020

Build FAILURE, see build http://10.8.144.11:8080/job/dev-tools/1584/

@andfasano
Copy link
Contributor Author

/test pj-rehearse

@stbenjam
Copy link
Member

/test golint

@stbenjam
Copy link
Member

I'm happy with this version. @andfasano Could you clean up the commit history? Should be 1 vendor commit, 1 code commit

@andfasano
Copy link
Contributor Author

Cleanup done, please let me know if it's ok

@stbenjam
Copy link
Member

/lgtm

@abhinavdahiya PTAL, thanks!

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 18, 2020
@abhinavdahiya
Copy link
Contributor

b47a051 LGTM

/approve

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 19, 2020
@openshift-ci-robot openshift-ci-robot removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 19, 2020
@@ -919,10 +926,15 @@ github.com/keybase/go-crypto/rsa
github.com/konsorten/go-windows-terminal-sequences
# github.com/kr/fs v0.1.0
github.com/kr/fs
<<<<<<< HEAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's still an unresolved conflict

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just run go mod tidy && go mod vendor instead of trying to solve the merge conflict.. maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry my fault I'll do it asap

This module simplify and make more scalable the validation steps, It's  annotations based, offers a good set of pre-existing validation rules and  allows to add easily new custom validation rules
baremetal.Host is validated using go-playground/validator module and a custom defined rule for duplicates
@metal3ci
Copy link

Build SUCCESS, see build http://10.8.144.11:8080/job/dev-tools/1658/

@andfasano
Copy link
Contributor Author

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 20, 2020
@andfasano
Copy link
Contributor Author

/retest

@stbenjam
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 20, 2020
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

11 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit d3acf80 into openshift:master Mar 20, 2020
@openshift-ci-robot
Copy link
Contributor

@andfasano: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/e2e-metal-ipi 3b5d253 link /test e2e-metal-ipi
ci/prow/e2e-libvirt 508e7e4 link /test e2e-libvirt

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.

Instructions 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. platform/baremetal IPI bare metal hosts platform size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants