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

virt-api, admitter: Refactor & move network validation admitters to the network package #11511

Merged
merged 6 commits into from Mar 27, 2024

Conversation

EdDev
Copy link
Member

@EdDev EdDev commented Mar 14, 2024

What this PR does

Validation admitters related to network spec are moved under the network package in order to decouple them from the other admitters and allow the sig-network to properly own them.

In addition, work on simplifying the validation code and its tests has been included in this effort.

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

@kubevirt-bot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@kubevirt-bot kubevirt-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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. sig/buildsystem Denotes an issue or PR that relates to changes in the build system. sig/network size/L labels Mar 14, 2024
@EdDev
Copy link
Member Author

EdDev commented Mar 14, 2024

/test pull-kubevirt-build
/test pull-kubevirt-unit-test
/test pull-kubevirt-code-lint
/test pull-kubevirt-generate

@EdDev
Copy link
Member Author

EdDev commented Mar 14, 2024

/test pull-kubevirt-build
/test pull-kubevirt-unit-test
/test pull-kubevirt-code-lint
/test pull-kubevirt-generate

@EdDev
Copy link
Member Author

EdDev commented Mar 14, 2024

/test pull-kubevirt-build
/test pull-kubevirt-unit-test
/test pull-kubevirt-code-lint
/test pull-kubevirt-generate

1 similar comment
@EdDev
Copy link
Member Author

EdDev commented Mar 14, 2024

/test pull-kubevirt-build
/test pull-kubevirt-unit-test
/test pull-kubevirt-code-lint
/test pull-kubevirt-generate

@EdDev
Copy link
Member Author

EdDev commented Mar 14, 2024

Flaky unit test unrelated to this change: https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_kubevirt/11511/pull-kubevirt-unit-test/1768243142961664000

/test pull-kubevirt-unit-test

@EdDev EdDev marked this pull request as ready for review March 14, 2024 12:16
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 14, 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.

Hi Edy, thanks for the PR

I the network related addmiters code is moved to pkg/network, how about keep it under pkg/virt-api/webhooks/validating-webhook/admitters/ but in new dir for network: pkg/virt-api/webhooks/validating-webhook/admitters/network?

Since the code is tightly related to the webhook and slirp/ iface APIs, I think it make more sense leaving it closer to to the consuming package.
It may also encourage other sigs who doesn't aggregate all related code under pkg/ move their related content in similar why to what I suggest.

pkg/network/admitter/slirp.go Outdated Show resolved Hide resolved
@EdDev
Copy link
Member Author

EdDev commented Mar 14, 2024

Hi Edy, thanks for the PR

I the network related addmiters code is moved to pkg/network, how about keep it under pkg/virt-api/webhooks/validating-webhook/admitters/ but in new dir for network: pkg/virt-api/webhooks/validating-webhook/admitters/network?

Since the code is tightly related to the webhook and slirp/ iface APIs, I think it make more sense leaving it closer to to the consuming package. It may also encourage other sigs who doesn't aggregate all related code under pkg/ move their related content in similar why to what I suggest.

This decision was already made when the admitter package was introduced under the network root package. What change that needs this to be reexamined?

Most of the current network sub-packages are used by many components in Kubevirt, I see no special thing about the admission ones.

@EdDev
Copy link
Member Author

EdDev commented Mar 14, 2024

change: Fix a bug detected during the review.

@ormergi
Copy link
Contributor

ormergi commented Mar 14, 2024

This decision was already made when the admitter package was introduced under the network root package. What change that needs this to be reexamined?

I was under the impression this PR introduce addmiter package, I missed that one.

@kubevirt-bot kubevirt-bot added lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 14, 2024
@kubevirt-bot kubevirt-bot removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 19, 2024
@EdDev
Copy link
Member Author

EdDev commented Mar 19, 2024

change: Rebase

pkg/network/admitter/slirp.go Outdated Show resolved Hide resolved
@@ -284,6 +284,7 @@ func validateNetworksMatchInterfaces(field *k8sfield.Path, spec *v1.VirtualMachi

networkData, networkExists := networkNameMap[iface.Name]

causes = append(causes, netadmitter.ValidateSlirpBinding(field, spec, config)...)
Copy link
Member

Choose a reason for hiding this comment

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

The method should be outside of the for loop.

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

}

if net.Pod == nil {
causes = append(causes, metav1.StatusCause{
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it also support multus network with default true?
Well, if it wasn't supported till now I believe we shouldn't start supporting it now the feature is going to be deprecated.

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 was not supported per what I understand.

@EdDev
Copy link
Member Author

EdDev commented Mar 25, 2024

change: Answered a review comment to move out the slirp validation outside the for-loop.

Signed-off-by: Edward Haas <edwardh@redhat.com>
Signed-off-by: Edward Haas <edwardh@redhat.com>
Signed-off-by: Edward Haas <edwardh@redhat.com>
Relocate the slirp admitter validations to the network/admitter package.

Simplify the implementation and provide clear unit tests to the various
checks.

Signed-off-by: Edward Haas <edwardh@redhat.com>
Signed-off-by: Edward Haas <edwardh@redhat.com>
Use interfaces on the validation function to ease its testing.

By using a focused interface, the tests now can use a simple stub
instead of a complex fake.

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

EdDev commented Mar 25, 2024

change: Rebase

@AlonaKaplan
Copy link
Member

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AlonaKaplan

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 Mar 25, 2024
@RamLavi
Copy link
Contributor

RamLavi commented Mar 26, 2024

/sig code-quality

Copy link
Contributor

@RamLavi RamLavi left a comment

Choose a reason for hiding this comment

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

/lgtm

@@ -15,11 +15,15 @@ go_library(

go_test(
name = "go_default_test",
srcs = ["admit_test.go"],
srcs = [
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: please consider moving this commit to before the test is moved.

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Mar 26, 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 Mar 26, 2024

/test pull-kubevirt-e2e-k8s-1.29-sig-compute-migrations

@kubevirt-bot kubevirt-bot merged commit b1d9476 into kubevirt:main Mar 27, 2024
39 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/code-quality sig/network size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants