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

Eviction admitter: Use KubeVirt generated clientset #11897

Merged
merged 5 commits into from
May 22, 2024

Conversation

orelmisan
Copy link
Member

@orelmisan orelmisan commented May 12, 2024

What this PR does

Before this PR:
PodEvictionAdmitter:

  1. Had exported (public) fields and could be instantiated incorrectly.
  2. Used the old kubecli.KubevirtClient clientset.
  3. Used gomock in unit tests.

After this PR:
PodEvictionAdmitter:

  1. Has a factory function and only unexported (private) fields.
  2. Uses kubernetes' official generated clientset.
  3. Uses KubeVirt's generated clientset.
  4. Uses KubeVirt's generated fake clientset in unit tests instead of gomock.

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

This is a follow up to #11380.

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

Currently, the fields of `PodEvictionAdmitter` are exported
(public), and are directly assigned by its users.
This has the potential to incorrectly instantiate the struct.

Introduce a factory function in order to:
1. Have a single way of instantiating `PodEvictionAdmitter`.
2. Make its fields unexported (private) in the next commit.

Signed-off-by: Orel Misan <omisan@redhat.com>
Following the introduction of the factory function in the
previous commit, it is now possible to unexport the fields
of `PodEvictionAdmitter`.

Signed-off-by: Orel Misan <omisan@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/L sig/buildsystem Denotes an issue or PR that relates to changes in the build system. labels May 12, 2024
@orelmisan
Copy link
Member Author

/cc @fossedihelm

Currently, `PodEvictionAdmitter` uses the `kubecli.KubevirtClient`
interface, which contains K8s clientset interface and KubeVirt's
manual clientset.

In order to use KubeVirt's generated clientset and fake clientset
in the following commit, separate the clientsets used by
`PodEvictionAdmitter` to:
1. kubeClient - to fetch pods
2. virtClient - to get and patch VMIs

In the unit tests, the fake K8s clientset is used directly.
There is no longer a need for virtClient to return the
fake K8s clientset.

Signed-off-by: Orel Misan <omisan@redhat.com>
@orelmisan orelmisan force-pushed the eviction-admitter-fake branch 2 times, most recently from d80218d to 24839d4 Compare May 12, 2024 19:15
@orelmisan
Copy link
Member Author

Change 1: Remove the permission of gomock to return the fake k8s clientset.
Change 2: Fix linter issue.

@orelmisan
Copy link
Member Author

/sig code-quality

Copy link
Contributor

@enp0s3 enp0s3 left a comment

Choose a reason for hiding this comment

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

@orelmisan Thank you!
/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 May 21, 2024
Copy link
Contributor

@fossedihelm fossedihelm left a comment

Choose a reason for hiding this comment

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

Thank you @orelmisan!
Even if the generated client(kubevirt.Interface) provides the same interface of our custom KubevirtClient kubecli.KubevirtClient we need to keep in mind that it currently does not implement all the custom (_expansion file) methods such as Pause, Freeze, etc...
A step ahead in this direction is provided by #11928, but it still does not implement some methods that require clientConfig.
Here we only use VirtualMachineInstances.Get() so everything works.
But we must be aware that the generated client that we are using with this patch still does not cover all the methods provided by the custom KubevirtClient.
@enp0s3 FYI

@enp0s3
Copy link
Contributor

enp0s3 commented May 21, 2024

@fossedihelm Thanks for the heads up! shouldn't the test fail in case the code will try to use the custom API calls that aren't implemented by the current client set?

@@ -541,6 +486,26 @@ func newDeniedAdmissionResponse(message string) *admissionv1.AdmissionResponse {
}
}

func newExpectedPatch(vmi *virtv1.VirtualMachineInstance) testing.PatchActionImpl {
Copy link
Contributor

@RamLavi RamLavi May 21, 2024

Choose a reason for hiding this comment

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

the name newExpectedPatch sounds generic, but the patch changes something very specific. Please consider renaming the function to be more specific, or add the patch as a input param.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for catching it.
I agree with you.
Done.

@fossedihelm
Copy link
Contributor

fossedihelm commented May 21, 2024

@fossedihelm Thanks for the heads up! shouldn't the test fail in case the code will try to use the custom API calls that aren't implemented by the current client set?

@enp0s3 Currently, the generated client will not return any error in such cases.
I will add a panic in #11928 as suggested in previous PR #11928.
If you agree I will wait for it to be merged first.

Use the generated KubeVirt clientset interface,
instead of the old manual one.

This allows us to use the generated fakeclient in unit tests,
instead of using gomock [1] (which has been archived).

[1] https://github.com/golang/mock

Signed-off-by: Orel Misan <omisan@redhat.com>
evictionStrategy was misspelled.

Signed-off-by: Orel Misan <omisan@redhat.com>
@orelmisan
Copy link
Member Author

Change: Address @RamLavi's comment.

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

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

Required labels detected, running phase 2 presubmits:
/test pull-kubevirt-e2e-windows2016
/test pull-kubevirt-e2e-kind-sriov
/test pull-kubevirt-e2e-k8s-1.30-ipv6-sig-network
/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
/test pull-kubevirt-e2e-k8s-1.29-sig-network
/test pull-kubevirt-e2e-k8s-1.29-sig-storage
/test pull-kubevirt-e2e-k8s-1.29-sig-compute
/test pull-kubevirt-e2e-k8s-1.29-sig-operator

@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@kubevirt-bot kubevirt-bot merged commit 3d7053c into kubevirt:main May 22, 2024
38 checks passed
@orelmisan orelmisan deleted the eviction-admitter-fake branch May 22, 2024 08:54
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 size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants