-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
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>
/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>
d80218d
to
24839d4
Compare
/sig code-quality |
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.
@orelmisan Thank you!
/approve
[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 |
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.
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
@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 { |
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.
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.
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.
Thank you for catching it.
I agree with you.
Done.
@enp0s3 Currently, the generated client will not return any error in such cases. |
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>
ca710a5
to
edd8ed0
Compare
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.
/lgtm
Required labels detected, running phase 2 presubmits: |
/retest-required |
What this PR does
Before this PR:
PodEvictionAdmitter:
kubecli.KubevirtClient
clientset.After this PR:
PodEvictionAdmitter:
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