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

machine: Add provider detection API #22479

Merged

Conversation

jakecorrenti
Copy link
Member

Extends the pkg/machine/provider package to add an API which includes provider detection based on the host operating system.

Does this PR introduce a user-facing change?

None

Copy link
Contributor

openshift-ci bot commented Apr 23, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jakecorrenti

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 23, 2024
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

1 similar comment
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@mheon
Copy link
Member

mheon commented Apr 24, 2024

Code LGTM

}

var outBuf bytes.Buffer
cmd := exec.Command("powershell", "Get-WindowsOptionalFeature", "-FeatureName", "Microsoft-Hyper-V-All", "-Online")
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to query this without executing powershell?
Output parsing is fragile in my experience given windows likes to prints output in different locales which caused problems for us before.

Copy link
Member Author

Choose a reason for hiding this comment

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

When researching it seemed that running some sort of command in the terminal and parsing the output was the most common solution. I'll try and find a better way to do this, I didn't think of locale issues coming up

Copy link
Member

Choose a reason for hiding this comment

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

Well I am not sure if Get-WindowsOptionalFeature has locale issues, I know we has similar check for WSL that caused did wsl --version that caused problems #20240

If the powershell command does not has the problems then this might be fine, but I wonder do we not have something like this in libhvee already?

@baude @n1hility can we call something like https://github.com/containers/libhvee/blob/0698042e8c753a95c349a2c45f8a6b04a5aa2e3a/pkg/hypervctl/vmm.go#L28 to know if hyperV is supported or not?

Copy link
Member

Choose a reason for hiding this comment

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

i think there is but offhand I don't recall ... @n1hility kind of knew this before @l0rd might also remember.

Copy link
Member

@l0rd l0rd Apr 24, 2024

Choose a reason for hiding this comment

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

Installer side I avoided parsing the PowerShell command output. I used the Win32 API QueryServiceStatusEx to query for the status of the vmcompute service. But that's in C.

Copy link
Member Author

@jakecorrenti jakecorrenti May 2, 2024

Choose a reason for hiding this comment

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

Using the libhvee snippet that @Luap99 sent seems to work

pkg/machine/provider/platform_windows.go Outdated Show resolved Hide resolved
pkg/machine/provider/platform_darwin.go Outdated Show resolved Hide resolved
@jakecorrenti jakecorrenti force-pushed the provider-detection branch from 7fc5ae0 to 6960685 Compare May 2, 2024 14:49
Extends the `pkg/machine/provider` package to add an API which includes
provider detection based on the host operating system.

Signed-off-by: Jake Correnti <[email protected]>
@jakecorrenti jakecorrenti force-pushed the provider-detection branch from 6960685 to 431cbff Compare May 6, 2024 13:42
func InstalledProviders() ([]define.VMType, error) {
var outBuf bytes.Buffer
// Apple's Virtualization.Framework is only supported on MacOS 11.0+
const SupportedMacOSVersion = 11
Copy link
Member

Choose a reason for hiding this comment

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

We might need to bump this to version 13 instead.
#22121 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Other than this though, LGTM.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, podman machine's use of vfkit+uefi requires macos 13

return nil, fmt.Errorf("unable to check current macOS version using `sw_vers --productVersion`: %s", err)
}

// the output will be in the format of MAJOR.MINOR.PATCH
Copy link
Contributor

Choose a reason for hiding this comment

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

This code is similar to what crc is doing https://github.com/crc-org/crc/blob/main/pkg/os/darwin/release_info.go
Maybe using a semver package would make the version parsing/checking simpler.

func InstalledProviders() ([]define.VMType, error) {
var outBuf bytes.Buffer
// Apple's Virtualization.Framework is only supported on MacOS 11.0+
const SupportedMacOSVersion = 11
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, podman machine's use of vfkit+uefi requires macos 13

@baude
Copy link
Member

baude commented May 7, 2024

im going to merge but @jakecorrenti , perhaps you can consider a semver update

@baude
Copy link
Member

baude commented May 7, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label May 7, 2024
@cfergeau
Copy link
Contributor

cfergeau commented May 7, 2024

Regarding macos version checks, you could also add a check to the installer, something like cfergeau@f5c5f4a which I haven't tested.

@openshift-merge-bot openshift-merge-bot bot merged commit 97f3f9c into containers:main May 7, 2024
91 checks passed
@stale-locking-app stale-locking-app 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 6, 2024
@stale-locking-app stale-locking-app bot locked as resolved and limited conversation to collaborators Aug 6, 2024
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. machine release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants