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

Abstract Command Client #10992

Closed
wants to merge 2 commits into from
Closed

Abstract Command Client #10992

wants to merge 2 commits into from

Conversation

xpivarc
Copy link
Member

@xpivarc xpivarc commented Jan 9, 2024

What this PR does / why we need it:
This PR is abstracting two things.
The first being is the creation of a client for the Command Server. The following interface is introduced:

type ClientManager interface {
	Create(vmi *v1.VirtualMachineInstance) (LauncherClient, error)
	Socket(vmi *v1.VirtualMachineInstance) (string, error)
	IsNotResponsive(socketPath string) bool
}

This allows us to write simpler tests in the future and resue one implementation in multiple places (search for FindSocketOnHost).

The second thing that is handled here is the usage of FindPodDirOnHost which has the same drawbacks. For this, we simply extend PodIsolationDetector, see below:

type PodIsolationDetector interface {
        ...
	DetectPod(vmi *v1.VirtualMachineInstance) error
        ...

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:
Note: This PR doesn't convert everything into a new abstraction and does not leverage it for tests. This will be follow-up work. The implementation is almost identical to the old one. We use the real implementation for the tests and that ensures we do not break tests and production code as well.

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 kubevirt-bot added the release-note-none Denotes a PR that doesn't merit a release note. label Jan 9, 2024
@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from xpivarc. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@orelmisan
Copy link
Member

/cc

@kubevirt-bot kubevirt-bot added the dco-signoff: yes Indicates the PR's author has DCO signed all their commits. label Jan 9, 2024
pkg/virt-handler/cmd-client/manager.go Show resolved Hide resolved
pkg/virt-handler/cmd-client/manager.go Outdated Show resolved Hide resolved
pkg/virt-handler/cmd-client/manager.go Outdated Show resolved Hide resolved
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.

Thanks @xpivarc Some comments below

pkg/virt-handler/vm.go Outdated Show resolved Hide resolved
pkg/virt-handler/cmd-client/manager.go Show resolved Hide resolved
pkg/virt-handler/isolation/detector.go Outdated Show resolved Hide resolved
@@ -50,6 +50,10 @@ type PodIsolationDetector interface {

DetectForSocket(vm *v1.VirtualMachineInstance, socket string) (IsolationResult, error)

// Detects if there is a Pod on the host for given vm
// Returns error otherwise
DetectPod(vmi *v1.VirtualMachineInstance) error
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 this return the socketPodDir, error otherwise?
Otherwise I would tend to switch to something like:
DoesPodExists(vmi *v1.VirtualMachineInstance) (bool, error)

Copy link
Member Author

Choose a reason for hiding this comment

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

The socketPodDir is unused. In fact FindPodDirOnHost is now only used once, here.
I thought about (bool, error) but I am not sure if there is any value. For now, I like that it preserves the behavior and I don't need to add additional coverage.

I am open to suggestions for names but I do reserve to keep the logic in this PR as close as it was and only follow up with improvements to the logic once we cover this with more unit tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's ok to me to leave the things as you proposed, with the promise that FindPodDirOnHost will be refactored in the future to drop the socketPodDir, if is not needed at all.
IOW my only concern is that we will forget that FindPodDirOnHost is returning an unused value.

}

func (cm *clientManager) Socket(vmi *v1.VirtualMachineInstance) (string, error) {
return FindSocketOnHost(vmi)
Copy link
Member

Choose a reason for hiding this comment

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

Could the socket path found inCreate() be saved as a member and returned here?

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 would require also cleaning it later. I have reverted the first commit to a simpler solution, please revisit.

As of now we directly search the filesystem
to find the socket and then initialize
a client for the command server in the launcher.

This is harder to test and change than it could be.

This commit encapsulates this into a simple yet effective
abstraction. The next step will be to use this abstraction
in all places that require the command client.

Signed-off-by: Luboslav Pivarc <lpivarc@redhat.com>
FindPodDirOnHost is a simple function that goes
through the file system to determine if there
is a Pod for a given VMI.

This direct approach makes testing problematic and
therefore we are extending the Isolation Detector to
cover this logic instead.

Signed-off-by: Luboslav Pivarc <lpivarc@redhat.com>
@xpivarc
Copy link
Member Author

xpivarc commented Jan 9, 2024

@fossedihelm @orelmisan PTAL

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.

Thanks @xpivarc!
I like the new simplified logic in the first commit.
One small last nit :)

*
* Copyright 2023 The KubeVirt Authors.
*
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missing newline
(sorry to be pedantic) 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

I adjust if any changes are requested.

@fossedihelm
Copy link
Contributor

Please, also, adjust the PR description with the new function name for ClientManager

@xpivarc
Copy link
Member Author

xpivarc commented Jan 10, 2024

Please, also, adjust the PR description with the new function name for ClientManager

Done

@fossedihelm
Copy link
Contributor

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2024
@orelmisan
Copy link
Member

orelmisan commented Jan 10, 2024

/hold

@xpivarc and I had an offline discussion, we agreed that this PR could be simplified if rebased on top of #10837.
Furthermore we found some issues with the suggested ClientManager abstraction that are worth revisiting.

@kubevirt-bot kubevirt-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 10, 2024
@kubevirt-bot kubevirt-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 20, 2024
@kubevirt-bot
Copy link
Contributor

PR needs rebase.

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.

@kubevirt-bot
Copy link
Contributor

@xpivarc: The following tests 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-e2e-k8s-1.28-sig-compute-migrations be74906 link true /test pull-kubevirt-e2e-k8s-1.28-sig-compute-migrations
pull-kubevirt-e2e-k8s-1.29-sig-compute-migrations be74906 link true /test pull-kubevirt-e2e-k8s-1.29-sig-compute-migrations
pull-kubevirt-e2e-k8s-1.29-sig-monitoring be74906 link true /test pull-kubevirt-e2e-k8s-1.29-sig-monitoring
pull-kubevirt-e2e-k8s-1.27-sig-performance be74906 link true /test pull-kubevirt-e2e-k8s-1.27-sig-performance
pull-kubevirt-e2e-k8s-1.29-sig-performance be74906 link true /test pull-kubevirt-e2e-k8s-1.29-sig-performance
pull-kubevirt-e2e-k8s-1.30-sig-compute-serial be74906 link true /test pull-kubevirt-e2e-k8s-1.30-sig-compute-serial

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

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@kubevirt-bot kubevirt-bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 2, 2024
@kubevirt-bot
Copy link
Contributor

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

/lifecycle rotten

@kubevirt-bot kubevirt-bot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Sep 1, 2024
@kubevirt-bot
Copy link
Contributor

Pull requests that are marked with lgtm should receive a review
from an approver within 1 week.

After that period the bot marks them with the label needs-approver-review.

/label needs-approver-review

@kubevirt-bot
Copy link
Contributor

@kubevirt-bot: The label(s) needs-approver-review cannot be applied, because the repository doesn't have them.

In response to this:

Pull requests that are marked with lgtm should receive a review
from an approver within 1 week.

After that period the bot marks them with the label needs-approver-review.

/label needs-approver-review

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-sigs/prow repository.

@dhiller dhiller added the needs-approver-review Indicates that a PR requires a review from an approver. label Sep 23, 2024
@kubevirt-bot
Copy link
Contributor

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

/close

@kubevirt-bot
Copy link
Contributor

@kubevirt-bot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

/close

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-sigs/prow repository.

@kubevirt-bot
Copy link
Contributor

/remove-label needs-approver-review

@kubevirt-bot kubevirt-bot removed the needs-approver-review Indicates that a PR requires a review from an approver. label Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has DCO signed all their commits. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants