Skip to content

Conversation

@andfasano
Copy link
Contributor

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:

  • have a single generic function for defining and applying tags based validation
  • support future splitting of rules definition and their application by the use of a validation context


// 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"`
Copy link
Member

@stbenjam stbenjam Apr 1, 2020

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?

Copy link
Member

@stbenjam stbenjam Apr 1, 2020

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

Copy link
Contributor Author

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.

Comment on lines 126 to 98
Copy link
Contributor

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.

Copy link
Contributor Author

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)

@andfasano andfasano force-pushed the validate-hosts-number branch from 506f5f8 to c5268dd Compare April 2, 2020 11:18
@andfasano
Copy link
Contributor Author

/test pj-rehearse

@stbenjam
Copy link
Member

stbenjam commented Apr 2, 2020

pj-rehearse is only a job on openshift/release

You can do this to retest:

/retest

@andfasano
Copy link
Contributor Author

/retest

1 similar comment
@andfasano
Copy link
Contributor Author

/retest

@andfasano
Copy link
Contributor Author

/test e2e-metal-ipi

@stbenjam
Copy link
Member

stbenjam commented Apr 3, 2020

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.

@andfasano
Copy link
Contributor Author

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.

@andfasano andfasano force-pushed the validate-hosts-number branch from c5268dd to 0838dae Compare April 6, 2020 09:31
@andfasano
Copy link
Contributor Author

Reworked PR so that it contains just the plain validation rule without any refactoring

@andfasano andfasano force-pushed the validate-hosts-number branch from 0838dae to 19f9c83 Compare April 6, 2020 10:44
Copy link
Member

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?

Copy link
Contributor Author

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

@stbenjam
Copy link
Member

stbenjam commented Apr 6, 2020

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 6, 2020
@stbenjam
Copy link
Member

stbenjam commented Apr 6, 2020

Please have a look @abhinavdahiya, as this modifies files in pkg/types/validation, I can't approve it.

@stbenjam
Copy link
Member

stbenjam commented Apr 6, 2020

/assign @abhinavdahiya

@andfasano andfasano force-pushed the validate-hosts-number branch from 19f9c83 to f213bb4 Compare April 6, 2020 14:49
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Apr 6, 2020
@stbenjam
Copy link
Member

stbenjam commented Apr 6, 2020

/test e2e-metal-ipi

@abhinavdahiya
Copy link
Contributor

https://github.com/openshift/installer/pull/3392/files#diff-02200a3eac2ac223b4117e690cf2d0c7
https://github.com/openshift/installer/pull/3392/files#diff-9f95494109d2a540a4a321c151e20c63

/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 validatePlatform seems wrong to me.

@openshift-ci-robot
Copy link
Contributor

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 6, 2020
@andfasano andfasano force-pushed the validate-hosts-number branch from f213bb4 to 9cf5134 Compare April 7, 2020 08:26
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
@andfasano andfasano force-pushed the validate-hosts-number branch from 9cf5134 to c6f4c29 Compare April 7, 2020 10:29
@stbenjam
Copy link
Member

stbenjam commented Apr 7, 2020

Thanks for updating the commit message. I think this looks ok, will wait to see results of e2e-metal-ipi first, though.

@stbenjam
Copy link
Member

stbenjam commented Apr 7, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 7, 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-libvirt c6f4c29 link /test e2e-libvirt
ci/prow/e2e-aws-fips c6f4c29 link /test e2e-aws-fips
ci/prow/e2e-openstack c6f4c29 link /test e2e-openstack
ci/prow/e2e-aws-scaleup-rhel7 c6f4c29 link /test e2e-aws-scaleup-rhel7

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.

Details

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants