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

General cleanup in validate.go #422

Merged
merged 1 commit into from
May 31, 2023

Conversation

vrindle
Copy link
Contributor

@vrindle vrindle commented Mar 20, 2023

Uses more expressive return types and also reduces cyclomatic complexity.

@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@coveralls
Copy link

coveralls commented Mar 20, 2023

Pull Request Test Coverage Report for Build 5072635988

  • 16 of 37 (43.24%) changed or added relevant lines in 1 file are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.1%) to 25.661%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/webhook/validate.go 16 37 43.24%
Files with Coverage Reduction New Missed Lines %
pkg/webhook/validate.go 1 54.71%
controllers/sriovibnetwork_controller.go 2 66.04%
Totals Coverage Status
Change from base Build 5022019978: 0.1%
Covered Lines: 1940
Relevant Lines: 7560

💛 - Coveralls

@wizhaoredhat
Copy link
Contributor

/cc @bn222
/cc @wizhaoredhat
/cc @SalDaniele

@bn222
Copy link
Collaborator

bn222 commented Mar 20, 2023

As discussed, let's have validateNicModel return an error instead. Also, let's get rid of the side-effect way to communicate the result of functions. More precisely, we should at least address interfaceSelected and maybe even nodesSelected.

It seems to me that we should also refactor the for loop in the function dynamicValidateSriovNetworkNodePolicy. Some parts of it are nested 5 deep.

@vrindle vrindle force-pushed the fix_error_message branch from 85b2dd1 to c6822a6 Compare March 29, 2023 02:15
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from c6822a6 to f1bf6aa Compare March 29, 2023 03:10
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from f1bf6aa to 1f9f03d Compare March 29, 2023 03:11
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

}

// 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 {
Copy link
Contributor

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.

@wizhaoredhat
Copy link
Contributor

/cc @pliurh

@github-actions github-actions bot requested a review from pliurh March 29, 2023 22:21
@vrindle vrindle force-pushed the fix_error_message branch from 1f9f03d to fda20b2 Compare April 6, 2023 00:57
@github-actions
Copy link

github-actions bot commented Apr 6, 2023

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from fda20b2 to aed33c3 Compare April 11, 2023 08:06
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from aed33c3 to f7c30d8 Compare April 11, 2023 08:09
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from f7c30d8 to 84eb8b7 Compare April 11, 2023 08:14
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from 84eb8b7 to b4dfa71 Compare April 11, 2023 08:17
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle requested a review from wizhaoredhat April 11, 2023 20:42
if validateNicModel(&policy.Spec.NicSelector, &iface, node) {
interfaceSelected = true
err := validateNicModel(&policy.Spec.NicSelector, &iface, node)
if err != nil {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@vrindle vrindle force-pushed the fix_error_message branch from b4dfa71 to e06ddd2 Compare April 13, 2023 05:40
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from e06ddd2 to d9c667c Compare April 13, 2023 06:07
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle requested a review from wizhaoredhat April 13, 2023 17:34
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from f45ecda to a37c9c5 Compare April 28, 2023 18:38
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from a37c9c5 to 5d94f17 Compare April 28, 2023 18:41
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from 5d94f17 to 0fa4b93 Compare May 9, 2023 19:55
@github-actions
Copy link

github-actions bot commented May 9, 2023

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from 0fa4b93 to 025c5a3 Compare May 23, 2023 02:41
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle vrindle force-pushed the fix_error_message branch from 025c5a3 to ee63e61 Compare May 23, 2023 16:11
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

}

func TestValidatePolicyForNodeStateWithValidVFAndNetFilter(t *testing.T) {
interfaceSelected = false
Copy link
Contributor

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?

Copy link
Contributor

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.

@vrindle vrindle force-pushed the fix_error_message branch from ee63e61 to ba91e19 Compare May 24, 2023 19:20
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

We use more expressive return types and also reduce cyclomatic complexity.
@vrindle vrindle force-pushed the fix_error_message branch from ba91e19 to bd6efc0 Compare May 24, 2023 19:24
@github-actions
Copy link

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@vrindle
Copy link
Contributor Author

vrindle commented May 24, 2023

g.Expect(err).NotTo(HaveOccurred())
g.Expect(ok).To(Equal(true))
g.Expect(interfaceSelected).To(Equal(true))
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@vrindle vrindle May 25, 2023

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok

@wizhaoredhat
Copy link
Contributor

LGTM

@bn222
Copy link
Collaborator

bn222 commented May 31, 2023

@adrianchiris

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,
Balazs

@adrianchiris
Copy link
Collaborator

This is a pretty small change that doesn't actually change functionality. CI is green and we already have an LGTM from RH.

did not see an LGTM from maintainer, @bn222 @SchSeba you should approve :)
will take a look at this later this week.

@bn222
Copy link
Collaborator

bn222 commented May 31, 2023

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)
Copy link
Collaborator

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.

@adrianchiris
Copy link
Collaborator

Thx @vrindle for this improvement !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants