Skip to content

Commit

Permalink
macos: Switch from hyperkit to vfkit
Browse files Browse the repository at this point in the history
vfkit is a hypervisor using macOS virtualization framework, which means
it has a much smaller codebase.
qcow-tool is no longer used, though a replacement will be needed when we
implement disk resizing.
A lot of this commit is hyperkit->vfkit renaming

After this commit, crc will require macOS 11 or newer.
  • Loading branch information
cfergeau authored and praveenkumar committed May 4, 2022
1 parent 7ad7b51 commit 25ccb91
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 296 deletions.
1 change: 0 additions & 1 deletion .github/workflows/macos-installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
fail-fast: false
matrix:
os:
- macOS-10.15
- macOS-11
go:
- 1.16
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/make-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
fail-fast: false
matrix:
os:
- macOS-10.15
- macOS-11
- ubuntu-latest
- ubuntu-18.04
Expand Down
6 changes: 2 additions & 4 deletions cmd/crc-embedder/cmd/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/code-ready/crc/pkg/crc/logging"
"github.com/code-ready/crc/pkg/download"

"github.com/code-ready/crc/pkg/crc/machine/hyperkit"
"github.com/code-ready/crc/pkg/crc/machine/libvirt"
"github.com/code-ready/crc/pkg/crc/machine/vfkit"

"github.com/YourFin/binappend"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -98,9 +98,7 @@ type remoteFileInfo struct {
var (
dataFileUrls = map[string][]remoteFileInfo{
"darwin": {
{hyperkit.MachineDriverDownloadURL, 0755},
{hyperkit.HyperKitDownloadURL, 0755},
{hyperkit.QcowToolDownloadURL, 0755},
{vfkit.VfkitDownloadURL, 0755},
{constants.GetCRCMacTrayDownloadURL(), 0644},
{constants.GetAdminHelperURLForOs("darwin"), 0755},
},
Expand Down
58 changes: 5 additions & 53 deletions pkg/crc/cache/cache_darwin.go
Original file line number Diff line number Diff line change
@@ -1,61 +1,13 @@
package cache

import (
"bufio"
"fmt"
"io"
"strings"

"github.com/code-ready/crc/pkg/crc/machine/hyperkit"
crcos "github.com/code-ready/crc/pkg/os"
"github.com/code-ready/crc/pkg/crc/machine/vfkit"
)

func NewMachineDriverHyperKitCache() *Cache {
return New(hyperkit.MachineDriverCommand, hyperkit.MachineDriverDownloadURL, hyperkit.MachineDriverVersion, getHyperKitMachineDriverVersion)
}

func NewQcowToolCache() *Cache {
return New(hyperkit.QcowToolCommand, hyperkit.QcowToolDownloadURL, hyperkit.QcowToolVersion, getQcowToolVersion)
}

func NewHyperKitCache() *Cache {
return New(hyperkit.HyperKitCommand, hyperkit.HyperKitDownloadURL, hyperkit.HyperKitVersion, getHyperKitVersion)
}

func getHyperKitMachineDriverVersion(executablePath string) (string, error) {
return getVersionGeneric(executablePath, "version")
}

func getQcowToolVersion(executablePath string) (string, error) {
stdout, _, err := crcos.RunWithDefaultLocale(executablePath, "--version")
return strings.TrimSpace(stdout), err
func NewVfkitCache() *Cache {
return New(vfkit.VfkitCommand, vfkit.VfkitDownloadURL, vfkit.VfkitVersion, getVfkitVersion)
}

/* This is very similar to cache.getVersionGeneric, except that it's reading from stderr instead of
* stdout, and it needs to deal with multiline output
*/
func getHyperKitVersion(executablePath string) (string, error) {
_, stderr, err := crcos.RunWithDefaultLocale(executablePath, "-v")
if err != nil {
return "", err
}
stderr, err = getFirstLine(stderr)
if err != nil {
return "", err
}
parsedOutput := strings.Split(stderr, ":")
if len(parsedOutput) < 2 {
return "", fmt.Errorf("Unable to parse the version information of %s", executablePath)
}
return strings.TrimSpace(parsedOutput[1]), err
}

func getFirstLine(s string) (line string, err error) {
reader := bufio.NewReader(strings.NewReader(s))
line, err = reader.ReadString('\n')
if err != nil && err != io.EOF {
return "", err
}

return line, nil
func getVfkitVersion(executablePath string) (string, error) {
return getVersionGeneric(executablePath, "-v")
}
2 changes: 1 addition & 1 deletion pkg/crc/machine/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type MachineConfig struct {
SSHKeyPath string
KubeConfig string

// HyperKit specific configuration
// macOS specific configuration
KernelCmdLine string
Initramfs string
Kernel string
Expand Down
18 changes: 9 additions & 9 deletions pkg/crc/machine/driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ import (

"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/machine/config"
"github.com/code-ready/crc/pkg/crc/machine/hyperkit"
"github.com/code-ready/crc/pkg/crc/machine/vfkit"
machineVf "github.com/code-ready/crc/pkg/drivers/vfkit"
"github.com/code-ready/crc/pkg/libmachine"
"github.com/code-ready/crc/pkg/libmachine/host"
machineHyperkit "github.com/code-ready/machine/drivers/hyperkit"
)

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

func loadDriverConfig(host *host.Host) (*machineHyperkit.Driver, error) {
var hyperkitDriver machineHyperkit.Driver
err := json.Unmarshal(host.RawDriver, &hyperkitDriver)
func loadDriverConfig(host *host.Host) (*machineVf.Driver, error) {
var vfDriver machineVf.Driver
err := json.Unmarshal(host.RawDriver, &vfDriver)

return &hyperkitDriver, err
return &vfDriver, err
}

func updateDriverConfig(host *host.Host, driver *machineHyperkit.Driver) error {
func updateDriverConfig(host *host.Host, driver *machineVf.Driver) error {
driverData, err := json.Marshal(driver)
if err != nil {
return err
Expand Down
23 changes: 0 additions & 23 deletions pkg/crc/machine/hyperkit/constants.go

This file was deleted.

27 changes: 0 additions & 27 deletions pkg/crc/machine/hyperkit/driver_darwin.go

This file was deleted.

18 changes: 18 additions & 0 deletions pkg/crc/machine/vfkit/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build darwin || build
// +build darwin build

package vfkit

import (
"fmt"
"runtime"
)

const (
VfkitVersion = "0.0.1"
)

var (
VfkitCommand = fmt.Sprintf("vfkit-%s", runtime.GOARCH)
VfkitDownloadURL = fmt.Sprintf("https://github.com/code-ready/vfkit/releases/download/v%s/%s", VfkitVersion, VfkitCommand)
)
26 changes: 26 additions & 0 deletions pkg/crc/machine/vfkit/driver_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package vfkit

import (
"path/filepath"

"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/machine/config"
"github.com/code-ready/crc/pkg/crc/network"
"github.com/code-ready/crc/pkg/drivers/vfkit"
)

func CreateHost(machineConfig config.MachineConfig) *vfkit.Driver {
vfDriver := vfkit.NewDriver(machineConfig.Name, constants.MachineBaseDir)

config.InitVMDriverFromMachineConfig(machineConfig, vfDriver.VMDriver)

vfDriver.Cmdline = machineConfig.KernelCmdLine
vfDriver.VmlinuzPath = machineConfig.Kernel
vfDriver.InitrdPath = machineConfig.Initramfs
vfDriver.VfkitPath = filepath.Join(constants.BinDir(), VfkitCommand)

vfDriver.VirtioNet = machineConfig.NetworkMode == network.SystemNetworkingMode
vfDriver.VsockPath = constants.TapSocketPath

return vfDriver
}
Loading

0 comments on commit 25ccb91

Please sign in to comment.