-
Notifications
You must be signed in to change notification settings - Fork 116
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
General cleanup in validate.go #422
General cleanup in validate.go #422
Conversation
Thanks for your PR,
To skip the vendors CIs use one of:
|
Pull Request Test Coverage Report for Build 5072635988
💛 - Coveralls |
/cc @bn222 |
As discussed, let's have It seems to me that we should also refactor the for loop in the function dynamicValidateSriovNetworkNodePolicy. Some parts of it are nested 5 deep. |
85b2dd1
to
c6822a6
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
c6822a6
to
f1bf6aa
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
f1bf6aa
to
1f9f03d
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
pkg/webhook/validate.go
Outdated
} | ||
|
||
// Check the vendor and device ID of the VF only if we are on a virtual environment | ||
for key := range utils.PlatformMap { | ||
if strings.Contains(strings.ToLower(node.Spec.ProviderID), strings.ToLower(key)) && | ||
selector.NetFilter != "" && selector.NetFilter == iface.NetFilter && | ||
sriovnetworkv1.IsVfSupportedModel(iface.Vendor, iface.DeviceID) { | ||
return true | ||
return nil | ||
} else { |
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 is divergent logic. The "for" loop is trying to find something matching. It doesn't mean that if it doesn't match that it is an error.
So the new behaviour of the code you have implemented here is not equivalent to the original.
/cc @pliurh |
1f9f03d
to
fda20b2
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
fda20b2
to
aed33c3
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
aed33c3
to
f7c30d8
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
f7c30d8
to
84eb8b7
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
84eb8b7
to
b4dfa71
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
pkg/webhook/validate.go
Outdated
if validateNicModel(&policy.Spec.NicSelector, &iface, node) { | ||
interfaceSelected = true | ||
err := validateNicModel(&policy.Spec.NicSelector, &iface, node) | ||
if err != nil { |
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.
Err contains important information. But it is not passed down or shown to the user.
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 can be resolved by logging and showing to the user without changing the behavior too much. Latest changes reflect that.
b4dfa71
to
e06ddd2
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
e06ddd2
to
d9c667c
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
Thanks for your PR,
To skip the vendors CIs use one of:
|
f45ecda
to
a37c9c5
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
a37c9c5
to
5d94f17
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
Thanks for your PR,
To skip the vendors CIs use one of:
|
0fa4b93
to
025c5a3
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
025c5a3
to
ee63e61
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
pkg/webhook/validate_test.go
Outdated
} | ||
|
||
func TestValidatePolicyForNodeStateWithValidVFAndNetFilter(t *testing.T) { | ||
interfaceSelected = false |
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.
Don't we still need this?
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.
You removed interfaceSelected
from the tests when it is still used.
ee63e61
to
ba91e19
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
We use more expressive return types and also reduce cyclomatic complexity.
ba91e19
to
bd6efc0
Compare
Thanks for your PR,
To skip the vendors CIs use one of:
|
g.Expect(err).NotTo(HaveOccurred()) | ||
g.Expect(ok).To(Equal(true)) | ||
g.Expect(interfaceSelected).To(Equal(true)) | ||
} |
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.
Should we add more tests for validateNicModel
, since now it returns an error instead of a boolean?
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.
what sort of tests are you looking to add? Imo, these functions test validateNicModel quite heavily.
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.
validatePolicyForNodeState
gets tested. But in err := validateNicModel(&policy.Spec.NicSelector, &iface, node)
, the err
gets thrown away. I think it would be worth it to test validateNicModel
indepedently.
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 agree that we should test that out but maybe not in this PR. In my other PR I test this when the variable interfaceSelected is removed. Please see this line here for instance: https://github.com/k8snetworkplumbingwg/sriov-network-operator/pull/434/files#diff-ae978883f1787164fb6fa85b31c5fde6421f8a06d9c9f5f013fb72e6f21863a0R560 a
remove interfaceSelected anyways in a later PR and testing the return types for validateNicModel
we don't have to add that to this PR.
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.
Ok
LGTM |
This is a pretty small change that doesn't actually change functionality. CI is green and we already have an LGTM from RH. Can you PTAL? Should be pretty quick. Regards, |
lgtm |
glog.V(2).Infof("validatePolicyForNodeState(): validate policy %s for node %s.", policy.GetName(), state.GetName()) | ||
for _, iface := range state.Status.Interfaces { | ||
if validateNicModel(&policy.Spec.NicSelector, &iface, node) { | ||
err := validateNicModel(&policy.Spec.NicSelector, &iface, node) |
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.
nit:
if err := validateNicModel; err == nil {
...
}
that said, its really a matter of taste here so im fine with keeping as is.
Thx @vrindle for this improvement ! |
Uses more expressive return types and also reduces cyclomatic complexity.