Skip to content

Commit

Permalink
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.
  • Loading branch information
gbraad committed Sep 7, 2023
1 parent 233df0e commit 9c10def
Show file tree
Hide file tree
Showing 86 changed files with 5,877 additions and 606 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
45 changes: 45 additions & 0 deletions go.sum

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions pkg/crc/machine/driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ import (
"errors"

"github.com/crc-org/crc/pkg/crc/machine/config"
"github.com/crc-org/crc/pkg/crc/machine/hyperv"
machineHyperv "github.com/crc-org/crc/pkg/drivers/hyperv"
"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
Expand All @@ -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/pkg/crc/constants"
"github.com/crc-org/crc/pkg/crc/machine/config"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/drivers/hyperv"
winnet "github.com/crc-org/crc/pkg/os/windows/network"
"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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hyperv
package libhvee

import (
"testing"
Expand Down
14 changes: 0 additions & 14 deletions pkg/crc/preflight/preflight_checks_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/crc-org/crc/pkg/os/windows/powershell"

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

const (
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions pkg/crc/preflight/preflight_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 9c10def

Please sign in to comment.