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

net, admitter: Move (all) network validation admitters under network pkg. #11698

Merged
merged 14 commits into from Apr 26, 2024

Conversation

EdDev
Copy link
Member

@EdDev EdDev commented Apr 12, 2024

What this PR does

Move and when needed adjust network validation admitters to the network/admitter package.

The logic is now properly owned and organized for the sig-network.

Fixes #

Why we need it and why it was done in this way

The following tradeoffs were made:

The following alternatives were considered:

Links to places where the discussion took place:

Special notes for your reviewer

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note

NONE

Validators that check that the network name is unique and that each
network has a counterpart interface have been moved and adjusted to the
`network/admitter` package.

Signed-off-by: Edward Haas <edwardh@redhat.com>
Testing uniqueness of a port name between different interfaces is
irrelevant because there can be only a single pod network.

The existing validation checks the duplication for pod network
interfaces only.

Signed-off-by: Edward Haas <edwardh@redhat.com>
@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/XXL sig/buildsystem Denotes an issue or PR that relates to changes in the build system. sig/network labels Apr 12, 2024
@EdDev EdDev changed the title Admitters net move part3 net, admitter: Move (all) network validation admitters under network pkg. Apr 12, 2024
@EdDev
Copy link
Member Author

EdDev commented Apr 12, 2024

/test pull-kubevirt-e2e-k8s-1.29-ipv6-sig-network
/test pull-kubevirt-e2e-kind-sriov

Copy link
Contributor

@ormergi ormergi left a comment

Choose a reason for hiding this comment

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

Thanks for this clean up PR, awesome work

Overall looks good to me please see my comments.
nit are not a must.

},
},
{
Name: "default",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I suggest to not duplicate the network test here, its a bit confusing becuase this test is about interfaces name duplication but it can also fail due to network name duplications.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not better and not worse than placing here a single network or two networks of a different name. In all scenarios we will get a combination or failures.

Therefore, I chose this one which seems simple enough.

Comment on lines 85 to 88
{
Name: "default",
InterfaceBindingMethod: v1.InterfaceBindingMethod{Bridge: &v1.InterfaceBridge{}},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Mix and match using v1.DefaultBridgeNetworkInterface and having in-place interface definition is a bit confusing.
You can simulate duplication by using *v1.DefaultBridgeNetworkInterface(), twice.
If you like to reflect the interface names better, I think it better to have additional in place interface definition (as in lines 84-88).

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines 45 to 46
if iface.Binding != nil {
if hasInterfaceBindingMethod(iface) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think we can reduce if clauses here:

Suggested change
if iface.Binding != nil {
if hasInterfaceBindingMethod(iface) {
if iface.Binding != nil && hasInterfaceBindingMethod(iface) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -52,3 +62,22 @@ func hasInterfaceBindingMethod(iface v1.Interface) bool {
iface.InterfaceBindingMethod.Macvtap != nil ||
iface.InterfaceBindingMethod.Passt != nil
}

func validateMasqueradeBinding(fieldPath *field.Path, idx int, iface v1.Interface, net v1.Network) []metav1.StatusCause {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think checking the iface use masquerade binding can be asked once and reused.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I do not understand what you mean by this.

Copy link
Contributor

Choose a reason for hiding this comment

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

The masquerade binding check, at lines 66 and 73.

v1 "kubevirt.io/api/core/v1"
)

func validatePasstBinding(
Copy link
Contributor

Choose a reason for hiding this comment

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

Since passt iface API is deprecated in favor of Passt network binding plugin, I think it will be nice if this validation function would reflect it, and maybe recommend using the plugin.
Changing it on a follow up PR may be a better fit.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is part of the passt core binding check, not about the binding plugin which is not specific to passt or any other binding. When we remove passt core binding, we will remove these as well.

Comment on lines 251 to 261
//networkNameMap := vmispec.IndexNetworkSpecByName(spec.Networks)

// Make sure the port name is unique across all the interfaces
portForwardMap := make(map[string]struct{})
//portForwardMap := make(map[string]struct{})

// Validate that each interface has a matching network
for idx, iface := range spec.Domain.Devices.Interfaces {

networkData, networkExists := networkNameMap[iface.Name]
//networkData, networkExists := networkNameMap[iface.Name]

causes = append(causes, validatePortConfiguration(field, networkExists, &networkData, iface, idx, portForwardMap)...)
//causes = append(causes, validatePortConfiguration(field, networkExists, &networkData, iface, idx, portForwardMap)...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the commented line be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like leftovers, thanks.
Done.

causes = append(causes, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueInvalid,
Message: "Macvtap feature gate is not enabled",
Field: fieldPath.Child("domain", "devices", "interfaces").Index(idx).Child("name").String(),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think the field path string can be reused

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case, we will loose context in favor of a negligible optimization.
I think it is more readable this way and it is consistent with how we use it all over.

causes = append(causes, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueInvalid,
Message: "Passt feature gate is not enabled",
Field: fieldPath.Child("domain", "devices", "interfaces").Index(idx).Child("name").String(),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think the field path string can be reused

Copy link
Member Author

Choose a reason for hiding this comment

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

Same answer as before.

field.Child("domain", "devices", "interfaces").Index(idx).Child("name").String(),
iface.MacAddress,
),
Field: field.Child("domain", "devices", "interfaces").Index(idx).Child("macAddress").String(),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think the field path string can be reused

Copy link
Member Author

Choose a reason for hiding this comment

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

Same answer as before.

causes = append(causes, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueDuplicate,
Message: fmt.Sprintf("Duplicate name of the port: %s", forwardPort.Name),
Field: field.Child("domain", "devices", "interfaces").Index(idx).Child("ports").Index(portIdx).Child("name").String(),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Field path string can be reused

Copy link
Member Author

Choose a reason for hiding this comment

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

Same answer as before

EdDev added 12 commits April 17, 2024 20:52
Signed-off-by: Edward Haas <edwardh@redhat.com>
Signed-off-by: Edward Haas <edwardh@redhat.com>
Two masquerade binding validations, that check it is set with pod
network and is not using the reserved mac address, have been moved to
the `network/admitter` package.

Signed-off-by: Edward Haas <edwardh@redhat.com>
The unit tests have been using a cluster-config-checker stub that was
originally focused on SLIRP tests. Later it was used to just satisfy
other scenarios which had nothing to do with SLIRP.

As new cluster-config methods are needed for other scenarios, the
current stub is generalized by name and location.

Signed-off-by: Edward Haas <edwardh@redhat.com>
The validation that checks an interface with bridge binding set on a pod
network is moved to the `network/admitter` package.

Signed-off-by: Edward Haas <edwardh@redhat.com>
Signed-off-by: Edward Haas <edwardh@redhat.com>
The passt core binding has a validation that checks that it is defined
without any other interface in the spec.

We support only L2 bindings on the secondary interfaces which use
bridging to ling the pod interface to the VM. Therefore, there is no
real limitation to have additional interfaces to passt.

In addition, passt is targeted for removal after declared as deprecated
in favor of the binding plugin version of it.

Therefore, this single interface validation is removed.

Signed-off-by: Edward Haas <edwardh@redhat.com>
Signed-off-by: Edward Haas <edwardh@redhat.com>
Signed-off-by: Edward Haas <edwardh@redhat.com>
Move interface fields validation to the `network/admitter` package and
adjust them to the new location.

The following validations have been moved in this change:
- Interface name format.
- Interface model.
- Interface mac address.
- Interface PCI address.

Signed-off-by: Edward Haas <edwardh@redhat.com>
The interface port validations are moved to `network/admitter` and
refactored there to use test tables.

Signed-off-by: Edward Haas <edwardh@redhat.com>
Tests have been converted to test tables and duplicate tests removed.

Signed-off-by: Edward Haas <edwardh@redhat.com>
@EdDev
Copy link
Member Author

EdDev commented Apr 18, 2024

change: Answered review.

@enp0s3
Copy link
Contributor

enp0s3 commented Apr 25, 2024

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: enp0s3

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 25, 2024
Copy link
Contributor

@ormergi ormergi left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -52,3 +62,22 @@ func hasInterfaceBindingMethod(iface v1.Interface) bool {
iface.InterfaceBindingMethod.Macvtap != nil ||
iface.InterfaceBindingMethod.Passt != nil
}

func validateMasqueradeBinding(fieldPath *field.Path, idx int, iface v1.Interface, net v1.Network) []metav1.StatusCause {
Copy link
Contributor

Choose a reason for hiding this comment

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

The masquerade binding check, at lines 66 and 73.

if iface.Binding != nil && !config.NetworkBindingPlugingsEnabled() {
return []metav1.StatusCause{{
Type: metav1.CauseTypeFieldValueInvalid,
Message: "Binding plugins feature gate is not enabled",
Copy link
Contributor

Choose a reason for hiding this comment

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

The original is wrong, this is a good opportunity to fix.

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 25, 2024
@kubevirt-commenter-bot
Copy link

Required labels detected, running phase 2 presubmits:
/test pull-kubevirt-e2e-windows2016
/test pull-kubevirt-e2e-kind-1.27-vgpu
/test pull-kubevirt-e2e-kind-sriov
/test pull-kubevirt-e2e-k8s-1.29-ipv6-sig-network
/test pull-kubevirt-e2e-k8s-1.27-sig-network
/test pull-kubevirt-e2e-k8s-1.27-sig-storage
/test pull-kubevirt-e2e-k8s-1.27-sig-compute
/test pull-kubevirt-e2e-k8s-1.27-sig-operator
/test pull-kubevirt-e2e-k8s-1.28-sig-network
/test pull-kubevirt-e2e-k8s-1.28-sig-storage
/test pull-kubevirt-e2e-k8s-1.28-sig-compute
/test pull-kubevirt-e2e-k8s-1.28-sig-operator

@EdDev
Copy link
Member Author

EdDev commented Apr 25, 2024

/test pull-kubevirt-e2e-k8s-1.27-sig-compute

@EdDev
Copy link
Member Author

EdDev commented Apr 26, 2024

/retest-required

@EdDev
Copy link
Member Author

EdDev commented Apr 26, 2024

/test pull-kubevirt-e2e-k8s-1.27-sig-network

@kubevirt-bot
Copy link
Contributor

kubevirt-bot commented Apr 26, 2024

@EdDev: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubevirt-conformance-arm64 f42ccc0 link false /test pull-kubevirt-conformance-arm64

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.

@kubevirt-bot kubevirt-bot merged commit 570e503 into kubevirt:main Apr 26, 2024
37 of 38 checks passed
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. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/buildsystem Denotes an issue or PR that relates to changes in the build system. sig/network size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants