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

Implement machine provider selection #17639

Merged
merged 1 commit into from May 1, 2023

Conversation

arixmkii
Copy link
Contributor

@arixmkii arixmkii commented Feb 27, 2023

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?

Enable Podman Machine provider configuration via config

@arixmkii
Copy link
Contributor Author

NO NEW TESTS NEEDED, because there are no alternative providers ready to be used as of the moment of creating this PR.

@arixmkii
Copy link
Contributor Author

arixmkii commented Feb 27, 2023

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). Please update the label. (bot did it 🎉 )

@Luap99
Copy link
Member

Luap99 commented Feb 27, 2023

@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.")
Copy link
Member

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.

Copy link
Contributor Author

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. 👍

Copy link
Contributor Author

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.

@TomSweeneyRedHat
Copy link
Member

One small comment and I have restarted the flakey swagger test. Otherwise LGTM.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

@baude PTAL

cmd/podman/machine/info.go Outdated Show resolved Hide resolved
cmd/podman/machine/platform.go Outdated Show resolved Hide resolved
cmd/podman/machine/platform_windows.go Outdated Show resolved Hide resolved
cmd/podman/machine/platform.go Outdated Show resolved Hide resolved
}
provider = strings.ToUpper(strings.TrimSpace(provider))
switch provider {
case "WSL":
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@baude
Copy link
Member

baude commented Mar 2, 2023

@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.

@baude
Copy link
Member

baude commented Mar 2, 2023

Oh and worse with something like the operating system, we also have fcos and fedora. so:

Linux -> QEMU -> FCOS
Windows -> WSL -> Special Fedora
Windows -> QEMU -> ? but assume FCOS
Windows -> HyperV -> FCOS
Apple -> QEMU -> FCOS
Apple -> AppleHV -> ?FCOS?

@arixmkii
Copy link
Contributor Author

arixmkii commented Mar 2, 2023

Windows -> QEMU -> ? but assume FCOS

Yes it is FCOS.

Oh and worse with something like the operating system, we also have fcos and fedora. so:

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.

@arixmkii
Copy link
Contributor Author

arixmkii commented Mar 2, 2023

@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.

@arixmkii
Copy link
Contributor Author

arixmkii commented Mar 20, 2023

Rebased to latest main and updated. Yet to test it locally (will update this comment, when it's done).

Update: tested on Windows build. Worked as expected - it is possible to configure provider using conf file and by overriding it using environment variable.

@arixmkii arixmkii force-pushed the provider-choice branch 4 times, most recently from 5410cf1 to 77588ee Compare March 20, 2023 20:18
@arixmkii
Copy link
Contributor Author

@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) {
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

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 ?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@arixmkii
Copy link
Contributor Author

arixmkii commented Apr 1, 2023

Applied requested changes and rebased to latest main.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 22, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 23, 2023
@baude
Copy link
Member

baude commented Apr 23, 2023

looks much better ... would you be wiling to slap a few logrus.debug's in that shows which provider is being used? else, tyvm!

@arixmkii
Copy link
Contributor Author

@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

@baude
Copy link
Member

baude commented Apr 24, 2023

/approve
LGTM

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 24, 2023

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 24, 2023
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 28, 2023
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>
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 28, 2023
@arixmkii
Copy link
Contributor Author

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).

@rhatdan
Copy link
Member

rhatdan commented May 1, 2023

/lgtm
Thanks @arixmkii

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label May 1, 2023
@openshift-merge-robot openshift-merge-robot merged commit f11ba8d into containers:main May 1, 2023
87 checks passed
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Aug 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2023
@arixmkii arixmkii deleted the provider-choice branch March 1, 2024 13:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Support Podman Machine provider selection using containers.conf
6 participants