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

MGMT-11156: Cluster validation, merge the print and validate methods #4130

Merged
merged 2 commits into from Aug 11, 2022

Conversation

paul-maidment
Copy link
Contributor

@paul-maidment paul-maidment commented Jul 13, 2022

Same as 4e04230 but for cluster validations instead of host validations

The present implementation of cluster validation has a problem, it splits the validation into two phases. The validation and the printing of the validation message.

This leads to a situation in some cases where it is not possible to use the output of a validation to determine the message that should be sent back to the user, there are some workarounds but these involve poor practices such as code repetition.

This commit changes the validation to be a single method. Due to the complexity of the refactor, no effort has been made to make each of the validation methods their "most efficient" it is assumed that these fixes will take place in subsequent commits.

Because the validation methods made heavy use of return statements, the style has had to be changed to an if/else style and some code has had to be reorganised a little.

In theory, the existing tests should be sufficient to act as a "smoke" test for this functionality provided that there is enough coverage.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • [] CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • No tests needed

Assignees

/cc @tsorya
/cc @ori-amizur

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • Reviewers have been listed
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

@openshift-ci openshift-ci bot requested review from ori-amizur and tsorya July 13, 2022 16:12
@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 13, 2022
@paul-maidment paul-maidment force-pushed the MGMT-11156 branch 2 times, most recently from 408f6c4 to 7b1c542 Compare July 13, 2022 16:28
@openshift-ci openshift-ci bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 13, 2022
@codecov
Copy link

codecov bot commented Jul 13, 2022

Codecov Report

Merging #4130 (6742bb5) into master (d21ae1e) will increase coverage by 0.20%.
The diff coverage is 96.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4130      +/-   ##
==========================================
+ Coverage   65.89%   66.10%   +0.20%     
==========================================
  Files         188      189       +1     
  Lines       26523    26688     +165     
==========================================
+ Hits        17477    17641     +164     
+ Misses       7446     7440       -6     
- Partials     1600     1607       +7     
Impacted Files Coverage Δ
internal/cluster/validator.go 96.04% <96.20%> (+10.66%) ⬆️
internal/cluster/refresh_status_preprocessor.go 93.70% <100.00%> (-0.79%) ⬇️
internal/host/refresh_status_preprocessor.go 93.62% <0.00%> (-1.17%) ⬇️
...oller/controllers/clusterdeployments_controller.go 74.09% <0.00%> (-0.91%) ⬇️
internal/host/validator.go 78.48% <0.00%> (-0.79%) ⬇️
internal/host/host.go 74.03% <0.00%> (-0.78%) ⬇️
internal/host/hostutil/host_utils.go 24.08% <0.00%> (-0.39%) ⬇️
cmd/agentbasedinstaller/register.go 17.50% <0.00%> (-0.30%) ⬇️
...nternal/controller/controllers/agent_controller.go 79.05% <0.00%> (-0.18%) ⬇️
internal/common/disks_info.go 0.00% <0.00%> (ø)
... and 11 more

@paul-maidment paul-maidment force-pushed the MGMT-11156 branch 4 times, most recently from d6468af to 52c508a Compare July 13, 2022 17:21
@openshift-ci openshift-ci bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 13, 2022
@paul-maidment paul-maidment force-pushed the MGMT-11156 branch 2 times, most recently from b8a5f49 to 592c154 Compare July 14, 2022 10:49
@paul-maidment paul-maidment changed the title WIP: Cluster validation, merge the print and validate methods WIP: MGMT-11156: Cluster validation, merge the print and validate methods Jul 14, 2022
@paul-maidment
Copy link
Contributor Author

/retest

@paul-maidment paul-maidment force-pushed the MGMT-11156 branch 3 times, most recently from 5a0b7e9 to 0d96ff6 Compare July 14, 2022 12:30
@paul-maidment paul-maidment changed the title WIP: MGMT-11156: Cluster validation, merge the print and validate methods MGMT-11156: Cluster validation, merge the print and validate methods Jul 20, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 20, 2022
@paul-maidment
Copy link
Contributor Author

/test edge-e2e-ai-operator-ztp-capi
/test edge-e2e-ai-operator-ztp-ipv4v6-3masters-ocp-410
/test edge-e2e-ai-operator-ztp-converged
/test edge-e2e-metal-assisted-day2

@paul-maidment
Copy link
Contributor Author

/test edge-e2e-metal-assisted-day2
/test edge-e2e-ai-operator-ztp-ipv4v6-3masters-ocp-410

@paul-maidment paul-maidment force-pushed the MGMT-11156 branch 8 times, most recently from f27e172 to 00cca33 Compare August 9, 2022 13:50
Comment on lines 414 to 420
if !validationStatusToBool(clusterCidrDefined) || !validationStatusToBool(serviceCidrDefined) {
status = ValidationPending
} else {
machineCidrDefined, _ := v.isMachineCidrDefined(c)
machineNetworkRequired := network.IsMachineNetworkRequired(c.cluster)
if machineNetworkRequired && !validationStatusToBool(machineCidrDefined) {
status = ValidationPending
Copy link
Member

Choose a reason for hiding this comment

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

I think you could probably combine this with the message handling and return early, no?

network.IsMachineNetworkRequired is checking user managed networking so it'd imagine it's more accurate than the check below.

Comment on lines +500 to +503
if synced {
return ValidationSuccess, "No ntp problems found"
}
return ValidationFailure, fmt.Sprintf("Hosts' clocks are not synchronized (there's more than a %d minutes gap between clocks), "+
Copy link
Member

Choose a reason for hiding this comment

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

Small nit, but whenever possible I think the success case should be the least indented. So I'd reverse this.

Suggested change
if synced {
return ValidationSuccess, "No ntp problems found"
}
return ValidationFailure, fmt.Sprintf("Hosts' clocks are not synchronized (there's more than a %d minutes gap between clocks), "+
if !synced {
return ValidationFailure, fmt.Sprintf("Hosts' clocks are not synchronized (there's more than a %d minutes gap between clocks), "+
}
return ValidationSuccess, "No ntp problems found"

Same as 4e04230 but for cluster validations instead of host validations

The present implementation of cluster validation has a problem, it splits the validation into two phases. The validation and the printing of the validation message.

This leads to a situation in some cases where it is not possible to use the output of a validation to determine the message that should be sent back to the user, there are some workarounds but these involve poor practices such as code repetition.

This commit changes the validation to be a single method. Due to the complexity of the refactor, no effort has been made to make each of the validation methods their "most efficient" it is assumed that these fixes will take place in subsequent commits.

Because the validation methods made heavy use of return statements, the style has had to be changed to an if/else style and some code has had to be reorganised a little.

In theory, the existing tests should be sufficient to act as a "smoke" test for this functionality provided that there is enough coverage.
@paul-maidment paul-maidment marked this pull request as draft August 10, 2022 13:57
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 10, 2022
Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

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

New test cases look good, but the names and structure could be better

Comment on lines 16 to 21
/**
type clusterValidator struct {
log logrus.FieldLogger
hostAPI host.API
}
*/
Copy link
Member

Choose a reason for hiding this comment

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

Remove this

}
*/

var _ = Describe("Validator tests", func() {
Copy link
Member

Choose a reason for hiding this comment

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

This describe is unnecessary.

validator = clusterValidator{logrus.New(), nil}
})

Context("isNetworksSameAddressFamilies", func() {
Copy link
Member

Choose a reason for hiding this comment

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

This should be the top-level Describe block.

Context("isNetworksSameAddressFamilies", func() {

var preprocessContext *clusterPreprocessContext
clusterID := strfmt.UUID(uuid.New().String())
Copy link
Member

Choose a reason for hiding this comment

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

This should be in the BeforeEach

preprocessContext = &clusterPreprocessContext{}
})

It("Machine network not required but no cluster or service network", func() {
Copy link
Member

Choose a reason for hiding this comment

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

These test names should include the expected behavior.
Something like returns ValidationPending when cluster and service network are unset and required

Expect(message).Should(Equal("Bad CIDR(s) appears in one of the networks"))
})

It("Machine networks contain bad CIDRs", func() {
Copy link
Member

Choose a reason for hiding this comment

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

This test name talks about bad CIDRs, but the check isn't the same as the one above about bad cidrs, I think it should be more specific.

@@ -11,6 +12,7 @@ import (
func TestCluster(t *testing.T) {
RegisterFailHandler(Fail)
common.InitializeDBTest()
time.Sleep(10 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this

return ValidationError, "Bad CIDR(s) appears in one of the networks"
}
// serviceNetworkFamilies should only ever have a maximum of two distinct families.
// clusterNetworkFamilies may have multiple indistinct families so need to be canonized prior to comparison.
Copy link
Member

Choose a reason for hiding this comment

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

Something I was confused about here was what "canonize" meant.
Maybe that's worth explaining too?

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 10, 2022
@openshift-ci
Copy link

openshift-ci bot commented Aug 10, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: carbonin, gamli75, paul-maidment

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [carbonin,gamli75,paul-maidment]

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

@paul-maidment paul-maidment marked this pull request as ready for review August 10, 2022 19:53
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 10, 2022
@paul-maidment
Copy link
Contributor Author

/retest

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 10, 2022
@carbonin
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 10, 2022
@openshift-ci
Copy link

openshift-ci bot commented Aug 10, 2022

@paul-maidment: all tests passed!

Full PR test history. Your PR dashboard.

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.

@openshift-merge-robot openshift-merge-robot merged commit fba1595 into openshift:master Aug 11, 2022
danielerez pushed a commit to danielerez/assisted-service that referenced this pull request Oct 15, 2023
…penshift#4130)

* MGMT-11156: Cluster validation, merge the print and validate methods

Same as 4e04230 but for cluster validations instead of host validations

The present implementation of cluster validation has a problem, it splits the validation into two phases. The validation and the printing of the validation message.

This leads to a situation in some cases where it is not possible to use the output of a validation to determine the message that should be sent back to the user, there are some workarounds but these involve poor practices such as code repetition.

This commit changes the validation to be a single method. Due to the complexity of the refactor, no effort has been made to make each of the validation methods their "most efficient" it is assumed that these fixes will take place in subsequent commits.

Because the validation methods made heavy use of return statements, the style has had to be changed to an if/else style and some code has had to be reorganised a little.

In theory, the existing tests should be sufficient to act as a "smoke" test for this functionality provided that there is enough coverage.

* MGMT-11156: Adding tests for isNetworksSameAddressFamilies in validator
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. kind/dependency-change Categorizes issue or PR as related to changing dependencies lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants