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
MGMT-11156: Cluster validation, merge the print and validate methods #4130
Conversation
408f6c4
to
7b1c542
Compare
Codecov Report
@@ 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
|
d6468af
to
52c508a
Compare
b8a5f49
to
592c154
Compare
/retest |
5a0b7e9
to
0d96ff6
Compare
0d96ff6
to
27560b7
Compare
/test edge-e2e-ai-operator-ztp-capi |
/test edge-e2e-metal-assisted-day2 |
f27e172
to
00cca33
Compare
internal/cluster/validator.go
Outdated
if !validationStatusToBool(clusterCidrDefined) || !validationStatusToBool(serviceCidrDefined) { | ||
status = ValidationPending | ||
} else { | ||
machineCidrDefined, _ := v.isMachineCidrDefined(c) | ||
machineNetworkRequired := network.IsMachineNetworkRequired(c.cluster) | ||
if machineNetworkRequired && !validationStatusToBool(machineCidrDefined) { | ||
status = ValidationPending |
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 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.
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), "+ |
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.
Small nit, but whenever possible I think the success case should be the least indented. So I'd reverse this.
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.
00cca33
to
36e076d
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.
New test cases look good, but the names and structure could be better
internal/cluster/validator_test.go
Outdated
/** | ||
type clusterValidator struct { | ||
log logrus.FieldLogger | ||
hostAPI host.API | ||
} | ||
*/ |
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.
Remove this
internal/cluster/validator_test.go
Outdated
} | ||
*/ | ||
|
||
var _ = Describe("Validator tests", func() { |
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.
This describe is unnecessary.
internal/cluster/validator_test.go
Outdated
validator = clusterValidator{logrus.New(), nil} | ||
}) | ||
|
||
Context("isNetworksSameAddressFamilies", func() { |
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.
This should be the top-level Describe block.
internal/cluster/validator_test.go
Outdated
Context("isNetworksSameAddressFamilies", func() { | ||
|
||
var preprocessContext *clusterPreprocessContext | ||
clusterID := strfmt.UUID(uuid.New().String()) |
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.
This should be in the BeforeEach
internal/cluster/validator_test.go
Outdated
preprocessContext = &clusterPreprocessContext{} | ||
}) | ||
|
||
It("Machine network not required but no cluster or service network", func() { |
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.
These test names should include the expected behavior.
Something like returns ValidationPending when cluster and service network are unset and required
internal/cluster/validator_test.go
Outdated
Expect(message).Should(Equal("Bad CIDR(s) appears in one of the networks")) | ||
}) | ||
|
||
It("Machine networks contain bad CIDRs", func() { |
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.
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) |
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.
Please remove this
internal/cluster/validator.go
Outdated
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. |
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.
Something I was confused about here was what "canonize" meant.
Maybe that's worth explaining too?
054bb59
to
aa46e27
Compare
[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:
Approvers can indicate their approval by writing |
/retest |
aa46e27
to
6742bb5
Compare
/lgtm |
@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. |
…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
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
What environments does this code impact?
How was this code tested?
Assignees
/cc @tsorya
/cc @ori-amizur
Checklist
docs
, README, etc)Reviewers Checklist