Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use libhvee instead of the current PowerShell cmdlet implementation
Browse files Browse the repository at this point in the history
This replaces the interaction of Hyper-V from our machine-drivers based
driver as used in Minikube/minishift to the libhvee library as used by
podman machine.
gbraad committed Sep 13, 2023
1 parent 45831b0 commit b34b1f0
Showing 86 changed files with 5,879 additions and 606 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ require (
golang.org/x/crypto v0.11.0
golang.org/x/net v0.12.0
golang.org/x/sync v0.3.0
golang.org/x/sys v0.10.0
golang.org/x/sys v0.11.0
golang.org/x/term v0.10.0
golang.org/x/text v0.11.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
@@ -78,6 +78,7 @@ require (
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/containers/libhvee v0.4.1-0.20230901182836-fcf1478fdd75 // indirect
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
github.com/containers/ocicrypt v1.1.7 // indirect
github.com/containers/storage v1.45.3 // indirect
45 changes: 45 additions & 0 deletions go.sum

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions pkg/crc/machine/driver_windows.go
Original file line number Diff line number Diff line change
@@ -4,29 +4,29 @@ import (
"encoding/json"
"errors"

"github.com/crc-org/crc/v2/pkg/crc/machine/config"
"github.com/crc-org/crc/v2/pkg/crc/machine/hyperv"
machineHyperv "github.com/crc-org/crc/v2/pkg/drivers/hyperv"
"github.com/crc-org/crc/v2/pkg/libmachine"
"github.com/crc-org/crc/v2/pkg/libmachine/host"
"github.com/crc-org/crc/pkg/crc/machine/config"
"github.com/crc-org/crc/pkg/crc/machine/libhvee"
machineLibhvee "github.com/crc-org/crc/pkg/drivers/libhvee"
"github.com/crc-org/crc/pkg/libmachine"
"github.com/crc-org/crc/pkg/libmachine/host"
)

func newHost(api libmachine.API, machineConfig config.MachineConfig) (*host.Host, error) {
json, err := json.Marshal(hyperv.CreateHost(machineConfig))
json, err := json.Marshal(libhvee.CreateHost(machineConfig))
if err != nil {
return nil, errors.New("Failed to marshal driver options")
}
return api.NewHost("hyperv", "", json)
}

func loadDriverConfig(host *host.Host) (*machineHyperv.Driver, error) {
var hypervDriver machineHyperv.Driver
err := json.Unmarshal(host.RawDriver, &hypervDriver)
func loadDriverConfig(host *host.Host) (*machineLibhvee.Driver, error) {
var libhveeDriver machineLibhvee.Driver
err := json.Unmarshal(host.RawDriver, &libhveeDriver)

return &hypervDriver, err
return &libhveeDriver, err
}

func updateDriverConfig(host *host.Host, driver *machineHyperv.Driver) error {
func updateDriverConfig(host *host.Host, driver *machineLibhvee.Driver) error {
driverData, err := json.Marshal(driver)
if err != nil {
return err
@@ -38,7 +38,7 @@ func updateKernelArgs(_ *virtualMachine) error {
return nil
}

func updateDriverStruct(host *host.Host, driver *machineHyperv.Driver) error {
func updateDriverStruct(host *host.Host, driver *machineLibhvee.Driver) error {
host.Driver = driver
return nil
}
6 changes: 0 additions & 6 deletions pkg/crc/machine/hyperv/constants_windows.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
package hyperv
package libhvee

import (
"path/filepath"
"strings"

"github.com/crc-org/crc/v2/pkg/crc/constants"
"github.com/crc-org/crc/v2/pkg/crc/machine/config"
"github.com/crc-org/crc/v2/pkg/crc/network"
"github.com/crc-org/crc/v2/pkg/drivers/hyperv"
winnet "github.com/crc-org/crc/v2/pkg/os/windows/network"
"github.com/crc-org/crc/pkg/crc/constants"
"github.com/crc-org/crc/pkg/crc/machine/config"
"github.com/crc-org/crc/pkg/drivers/libhvee"
"github.com/crc-org/machine/libmachine/drivers"
)

func CreateHost(machineConfig config.MachineConfig) *hyperv.Driver {
hypervDriver := hyperv.NewDriver(machineConfig.Name, constants.MachineBaseDir)
func CreateHost(machineConfig config.MachineConfig) *libhvee.Driver {
libhveeDriver := libhvee.NewDriver(machineConfig.Name, constants.MachineBaseDir)

config.InitVMDriverFromMachineConfig(machineConfig, hypervDriver.VMDriver)
config.InitVMDriverFromMachineConfig(machineConfig, libhveeDriver.VMDriver)

hypervDriver.DisableDynamicMemory = true

if machineConfig.NetworkMode == network.UserNetworkingMode {
hypervDriver.VirtualSwitch = ""
} else {
// Determine the Virtual Switch to be used
_, switchName := winnet.SelectSwitchByNameOrDefault(AlternativeNetwork)
hypervDriver.VirtualSwitch = switchName
}

hypervDriver.SharedDirs = configureShareDirs(machineConfig)
return hypervDriver
libhveeDriver.SharedDirs = configureShareDirs(machineConfig)
return libhveeDriver
}

// converts a path like c:\users\crc to /mnt/c/users/crc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hyperv
package libhvee

import (
"testing"
16 changes: 1 addition & 15 deletions pkg/crc/preflight/preflight_checks_windows.go
Original file line number Diff line number Diff line change
@@ -11,8 +11,7 @@ import (
winnet "github.com/crc-org/crc/v2/pkg/os/windows/network"
"github.com/crc-org/crc/v2/pkg/os/windows/powershell"

"github.com/crc-org/crc/v2/pkg/crc/constants"
"github.com/crc-org/crc/v2/pkg/crc/machine/hyperv"
"github.com/crc-org/crc/pkg/crc/constants"
)

const (
@@ -166,19 +165,6 @@ func fixUserPartOfCrcUsersAndHypervAdminsGroup() error {
return errReboot
}

func checkIfHyperVVirtualSwitchExists() error {
switchName := hyperv.AlternativeNetwork

// use winnet instead
exists, foundName := winnet.SelectSwitchByNameOrDefault(switchName)
if exists {
logging.Info("Found Virtual Switch to use: ", foundName)
return nil
}

return fmt.Errorf("Virtual Switch not found")
}

func checkIfRunningAsNormalUser() error {
if !powershell.IsAdmin() {
return nil
8 changes: 0 additions & 8 deletions pkg/crc/preflight/preflight_windows.go
Original file line number Diff line number Diff line change
@@ -55,14 +55,6 @@ var hypervPreflightChecks = []Check{

labels: labels{Os: Windows},
},
{
configKeySuffix: "check-hyperv-switch",
checkDescription: "Checking if the Hyper-V virtual switch exists",
check: checkIfHyperVVirtualSwitchExists,
flags: StartUpOnly,

labels: labels{Os: Windows, NetworkMode: System},
},
{
cleanupDescription: "Removing dns server from interface",
cleanup: removeDNSServerAddress,
Loading

0 comments on commit b34b1f0

Please sign in to comment.