Skip to content

Commit

Permalink
Issue minishift#1326 Enable hyperkit as driver for MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkumar committed Mar 9, 2018
1 parent 2b3e3a2 commit 97fce62
Show file tree
Hide file tree
Showing 8 changed files with 421 additions and 46 deletions.
344 changes: 316 additions & 28 deletions Gopkg.lock

Large diffs are not rendered by default.

48 changes: 32 additions & 16 deletions cmd/minishift/cmd/start_preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (
stringUtils "github.com/minishift/minishift/pkg/util/strings"
)

const (
StorageDisk = "/mnt/sda1"
var (
storageDisk = []string{"/mnt/sda1", "/mnt/vda1"}
)

// preflightChecksBeforeStartingHost is executed before the startHost function.
Expand Down Expand Up @@ -444,14 +444,14 @@ func checkHttpConnectivity(driver drivers.Driver) bool {
// checkStorageMounted checks if the persistent storage volume, storageDisk, is
// mounted to the VM instance
func checkStorageMounted(driver drivers.Driver) bool {
mounted, _ := isMounted(driver, StorageDisk)
mounted, _ := isMounted(driver, storageDisk)
return mounted
}

// checkStorageUsage checks if the persistent storage volume has enough storage
// space available.
func checkStorageUsage(driver drivers.Driver) bool {
_, usedPercentage := getDiskUsage(driver, StorageDisk)
_, usedPercentage := getDiskUsage(driver, storageDisk)
fmt.Printf("%s used ", usedPercentage)
usage, err := strconv.Atoi(stringUtils.GetOnlyNumbers(usedPercentage))
if err != nil {
Expand All @@ -468,12 +468,20 @@ func checkStorageUsage(driver drivers.Driver) bool {
}

// isMounted checks returns usage of mountpoint known to the VM instance
func getDiskUsage(driver drivers.Driver, mountpoint string) (string, string) {
cmd := fmt.Sprintf(
"df -h %s | awk 'FNR > 1 {print $2,$5}'",
mountpoint)

out, err := drivers.RunSSHCommandFromDriver(driver, cmd)
func getDiskUsage(driver drivers.Driver, mountpoints []string) (string, string) {
var err error
var out string

for _, mountpoint := range mountpoints {
cmd := fmt.Sprintf(
"df -h %s | awk 'FNR > 1 {print $2,$5}'",
mountpoint)

out, err = drivers.RunSSHCommandFromDriver(driver, cmd)
if !strings.Contains(out, " No such file") {
break
}
}

if err != nil {
return "", "ERR"
Expand All @@ -485,12 +493,20 @@ func getDiskUsage(driver drivers.Driver, mountpoint string) (string, string) {
}

// isMounted checks if mountpoint is mounted to the VM instance
func isMounted(driver drivers.Driver, mountpoint string) (bool, error) {
cmd := fmt.Sprintf(
"if grep -qs %s /proc/mounts; then echo '1'; else echo '0'; fi",
mountpoint)

out, err := drivers.RunSSHCommandFromDriver(driver, cmd)
func isMounted(driver drivers.Driver, mountpoints []string) (bool, error) {
var err error
var out string

for _, mountpoint := range mountpoints {
cmd := fmt.Sprintf(
"if grep -qs %s /proc/mounts; then echo '1'; else echo '0'; fi",
mountpoint)

out, err = drivers.RunSSHCommandFromDriver(driver, cmd)
if strings.Trim(out, "\n") == "1" {
break
}
}

if err != nil {
return false, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/minishift/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func runStatus(cmd *cobra.Command, args []string) {
openshiftStatus = fmt.Sprintf("Running (%s)", strings.Split(openshiftVersion, "\n")[0])
}

diskSize, diskUse := getDiskUsage(host.Driver, StorageDisk)
diskSize, diskUse := getDiskUsage(host.Driver, storageDisk)
diskUsage = fmt.Sprintf("%s of %s", diskUse, diskSize)
}

Expand Down
7 changes: 6 additions & 1 deletion docs/source/getting-started/installing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ macOS::
====
xhyve requires specific installation and configuration steps that are described in the xref:../getting-started/setting-up-driver-plugin.adoc#[Setting Up the Driver Plug-in] section.
====

- link:https://github.com/moby/hyperkit[hyperkit]
+
[NOTE]
====
hyperkit requires specific installation and configuration steps that are described in the xref:../getting-started/setting-up-driver-plugin.adoc#[Setting Up the Driver Plug-in] section.
====
- link:https://www.virtualbox.org/wiki/Downloads[VirtualBox]

Linux::
Expand Down
46 changes: 46 additions & 0 deletions docs/source/getting-started/setting-up-driver-plugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,52 @@ $ sudo chmod u+s /usr/local/bin/docker-machine-driver-xhyve
For more information, see the link:https://github.com/zchee/docker-machine-driver-xhyve#install[xhyve driver] documentation on GitHub.
====

[[hyperkit-driver-install]]
== hyperkit Driver

{project} is currently tested against *docker-machine-driver-hyperkit* version 1.0.0.


To install the hyperkit driver, you need to download and install the *docker-machine-driver-hyperkit* binary and place it in a directory which is on your `PATH` environment variable.
The directory *_/usr/local/bin_* is most likely a good choice, since it is the default installation directory for Docker Machine binaries.

The following steps explain the installation of the *docker-machine-driver-hyperkit* binary to the *_/usr/local/bin/_* directory:

. Download the *docker-machine-driver-hyperkit* binary using:
+
----
$ sudo curl -L https://github.com/machine-drivers/docker-machine-driver-hyperkit/releases/download/v1.0.0/docker-machine-driver-hyperkit -o /usr/local/bin/docker-machine-driver-hyperkit
----

. Enable root access for the *docker-machine-driver-hyperkit* binary and add it to the default *wheel* group:
+
----
$ sudo chown root:wheel /usr/local/bin/docker-machine-driver-hyperkit
----

. Set owner User ID (SUID) for the binary as follows:
+
----
$ sudo chmod u+s,+x /usr/local/bin/docker-machine-driver-hyperkit
----

[NOTE]
====
The downloaded *docker-machine-driver-hyperkit* binary is compiled against a specific version of macOS.
It is possible that the driver will fail to work after a macOS version upgrade.
In this case you can try to compile the driver from source:
----
$ go get -u -d github.com/machine-drivers/docker-machine-driver-hyperkit
$ cd $GOPATH/src/github.com/machine-drivers/docker-machine-driver-hyperkit
# Install docker-machine-driver-hyperkit binary into /usr/local/bin
$ make build
----
For more information, see the link: https://github.com/machine-drivers/docker-machine-driver-hyperkit/blob/master/README.md[hyperkit driver] documentation on GitHub.
====

== Hyper-V Driver
To use {project} with Hyper-V:

Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ func getDriverOptions(config MachineConfig) interface{} {
driver = createXhyveHost(config)
case "hyperv":
driver = createHypervHost(config)
case "hyperkit":
driver = createHyperkitHost(config)
default:
atexit.ExitWithMessage(1, fmt.Sprintf("Unsupported driver: %s", config.VMDriver))
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/minikube/cluster/cluster_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package cluster
import (
"github.com/docker/machine/drivers/vmwarefusion"
"github.com/docker/machine/libmachine/drivers"
"github.com/machine-drivers/docker-machine-driver-hyperkit/pkg/hyperkit"
"github.com/minishift/minishift/pkg/minikube/constants"
"github.com/pborman/uuid"
)

func createVMwareFusionHost(config MachineConfig) drivers.Driver {
Expand Down Expand Up @@ -67,3 +69,18 @@ func createXhyveHost(config MachineConfig) *xhyveDriver {
QCow2: false,
}
}

func createHyperkitHost(config MachineConfig) *hyperkit.Driver {
return &hyperkit.Driver{
BaseDriver: &drivers.BaseDriver{
MachineName: constants.MachineName,
StorePath: constants.Minipath,
SSHUser: "docker",
},
Boot2DockerURL: config.GetISOFileURI(),
DiskSize: config.DiskSize,
Memory: config.Memory,
CPU: config.CPUs,
UUID: uuid.NewUUID().String(),
}
}
1 change: 1 addition & 0 deletions pkg/minikube/constants/constants_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var SupportedVMDrivers = [...]string{
"virtualbox",
"vmwarefusion",
"xhyve",
"hyperkit",
}

const DefaultVMDriver = "xhyve"
Expand Down

0 comments on commit 97fce62

Please sign in to comment.