-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Implement machine provider selection #17639
Implement machine provider selection #17639
Conversation
NO NEW TESTS NEEDED, because there are no alternative providers ready to be used as of the moment of creating this PR. |
cff7d69
to
80811c7
Compare
I edited release note, because I realized that this thing is worth mentioning (the config option made itself available with the pull of common, but now it is actually exposed to user). |
@baude PTAL |
case "WSL": | ||
return wsl.GetWSLProvider() | ||
case "QEMU": | ||
logrus.Info("QEMU provider is work in progress https://github.com/containers/podman/issues/13006. Will use default provider.") |
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.
This line is good now, but this is the kind of line that can suffer bit rot in the not-too-distant future.
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.
Agreed. This was ok for a concept, but I'm ok to change this. 👍
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.
Removed QEMU part on Windows, will not be part of this PR. It was included only for demo purposes and now we have HyperV to play this role.
One small comment and I have restarted the flakey swagger test. Otherwise LGTM. |
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.
@baude PTAL
} | ||
provider = strings.ToUpper(strings.TrimSpace(provider)) | ||
switch provider { | ||
case "WSL": |
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.
I'm sitting on a PR where I strong typed all providers. My preference is we do something like that for sure. Should I yank that out of my PR and submit it?
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.
I'm sitting on a PR where I strong typed all providers
I have no objections about this. Strong typed is often a better option. If this will be split between common and podman repos it would make things slightly more difficult for external contributors, but I believe that typed version is still better.
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.
Reworked into typed version. I really don't like that I had to implement nullability with a pointer, because there is no Undefined value in the enum. Still thinking about reworking API into 2 separate functions - one taking enum parameter and another one w/o any parameters and then handling nullability in the private function.
@arixmkii i'm going through a similar activity as you are here in work I am actively doing to add HyperV support. And as a team we discussed this issue and how it related to containers-common, essentially that containers-common is ignorant of "providers" and is only by OS ... where podman now basically needs both. |
Oh and worse with something like the operating system, we also have fcos and fedora. so: Linux -> QEMU -> FCOS |
Yes it is FCOS.
And it is even worse. Working on QEMU implementation I had hard times to provide out of the box working defaults for machine init command as they are hardcoded based on OS and WSL an QEMU doesn't share the OS and the default user at least. |
@baude I'm open to withdraw this one (and keep it for my rebuilds only for now) and wait for a solution provided by the Podman team as I see this feature is more suitable for internal team rather than to external community contributors. I'm still open to some code work or needed assistance, but I don't think this should be driven by external people (w/o extensive communications) as this is pretty much integral to the Podman. I did this only, because I believed that work on applehv was either on hold or halt due to the situation with vfkit and this is why I created implementation myself. |
80811c7
to
761832c
Compare
Rebased to latest main and updated. Update: tested on Windows build. Worked as expected - it is possible to configure provider using conf file and by overriding it using environment variable. |
5410cf1
to
77588ee
Compare
@baude Could you take a look if this fits how you see that feature for Hyper-v implementation? |
// TODO this needs to be changed back | ||
if _, exists := os.LookupEnv("HYPERV"); exists { | ||
return hyperv.GetVirtualizationProvider() | ||
func GetSystemProvider(vmType *machine.VMType) (machine.VirtProvider, error) { |
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.
What is the reason for the argument? Is there a case where we need it? or worst case, write it unexported with a exported caller?
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.
Open extension point to support override passed via command line parameter. This is what I had in mind and why it is an exported func. I don't know if there will be a need/desire to have command line parameter, though.
Can remove it, if you see that simplification is more important and the use case is too artificial.
resolvedVMType := machine.QemuVirt | ||
if vmType != nil { | ||
resolvedVMType = *vmType | ||
} else { |
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.
in the same thought here, my understanding is that the containers.conf file would dictate the vm type. is that what you remember @Luap99 ?
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.
If the config file is the only source of truth for this setting, this can be simplified.
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.
that was the decision that was made .. i had hoped to also honor environment variables for development and testing. VMTYPE="qemu" ... wwyt about that too?
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.
There is EnvVar support implemented as part of this PR https://github.com/containers/podman/pull/17639/files#diff-1f6113c3d215be90ffaa1c5cc73b7da30d7c6583c49cbae89c4132858478ebf6R25 So, there is an option for development purposes. I just wasn't aware if every configuration should have matching command line parameter override or not.
I will remove extra function from the PR and resubmit.
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.
Parameter removed and related branching eliminated from the function.
77588ee
to
b76cfe0
Compare
Applied requested changes and rebased to latest main. |
b76cfe0
to
a4490df
Compare
looks much better ... would you be wiling to slap a few logrus.debug's in that shows which provider is being used? else, tyvm! |
a4490df
to
af88ad6
Compare
@baude Applied this diff to the same commit: diff --git a/cmd/podman/machine/platform.go b/cmd/podman/machine/platform.go
index 9d0ee1ca7..67b554306 100644
--- a/cmd/podman/machine/platform.go
+++ b/cmd/podman/machine/platform.go
@@ -10,6 +10,7 @@ import (
"github.com/containers/common/pkg/config"
"github.com/containers/podman/v4/pkg/machine"
"github.com/containers/podman/v4/pkg/machine/qemu"
+ "github.com/sirupsen/logrus"
)
func GetSystemProvider() (machine.VirtProvider, error) {
@@ -26,6 +27,7 @@ func GetSystemProvider() (machine.VirtProvider, error) {
return nil, err
}
+ logrus.Debugf("Using Podman machine with `%s` virtualization provider", resolvedVMType.String())
switch resolvedVMType {
case machine.QemuVirt:
return qemu.GetVirtualizationProvider(), nil
diff --git a/cmd/podman/machine/platform_windows.go b/cmd/podman/machine/platform_windows.go
index a50f0efd0..88a5a3531 100644
--- a/cmd/podman/machine/platform_windows.go
+++ b/cmd/podman/machine/platform_windows.go
@@ -8,6 +8,7 @@ import (
"github.com/containers/podman/v4/pkg/machine"
"github.com/containers/podman/v4/pkg/machine/hyperv"
"github.com/containers/podman/v4/pkg/machine/wsl"
+ "github.com/sirupsen/logrus"
)
func GetSystemProvider() (machine.VirtProvider, error) {
@@ -24,6 +25,7 @@ func GetSystemProvider() (machine.VirtProvider, error) {
return nil, err
}
+ logrus.Debugf("Using Podman machine with `%s` virtualization provider", resolvedVMType.String())
switch resolvedVMType {
case machine.WSLVirt:
return wsl.GetWSLProvider(), nil |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: arixmkii, baude 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 |
GetSystemDefaultProvider reworked to fetch provider value from the config file. Additional environment variable CONTAINERS_MACHINE_PROVIDER is supported to override the config for testing purposes. Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
af88ad6
to
b5ef955
Compare
Rebased to latest main. Had to change https://github.com/containers/podman/pull/17639/files#diff-f1ce6e45ecdde3df18c58e0a3a779f2736b14bf91edb510e868562588559b7a9L33 I didn't track the origin of this change, but this only worked before the getProvider introduced error possibility (returning error on misconfiguration). |
/lgtm |
Fixes #17116
GetSystemDefaultProvider reworked to accept input parameter with the desired virtualization provider. All callers adjusted to read this from the config before requesting virtualization provider instance.
Additional environment variable CONTAINERS_MACHINE_PROVIDER is supported to override the config for testing purposes.
Motivation for this signature is that it could be later extended to not only using config, but also to accept CLI switches. It could be changed to have config reading inside platform method to remove it from every caller, but this will not significantly reduce code lines in the callers, because this would change the signature of the method in platform to report possible errors and then callers should still check and handle the errors.
[NO NEW TESTS NEEDED]
Does this PR introduce a user-facing change?