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

Mo hit hyperkit mount fix #2337

Merged
merged 5 commits into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const (
humanReadableDiskSize = "disk-size"
vmDriver = "vm-driver"
xhyveDiskDriver = "xhyve-disk-driver"
NFSSharesRoot = "nfs-shares-root"
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs some indicator that its macOS specific
@dlorenc

NFSShare = "nfs-share"
kubernetesVersion = "kubernetes-version"
hostOnlyCIDR = "host-only-cidr"
containerRuntime = "container-runtime"
Expand Down Expand Up @@ -130,6 +132,8 @@ func runStart(cmd *cobra.Command, args []string) {
DiskSize: diskSizeMB,
VMDriver: viper.GetString(vmDriver),
XhyveDiskDriver: viper.GetString(xhyveDiskDriver),
NFSShare: viper.GetStringSlice(NFSShare),
NFSSharesRoot: viper.GetString(NFSSharesRoot),
DockerEnv: dockerEnv,
DockerOpt: dockerOpt,
InsecureRegistry: insecureRegistry,
Expand Down Expand Up @@ -367,6 +371,8 @@ func init() {
startCmd.Flags().String(hypervVirtualSwitch, "", "The hyperv virtual switch name. Defaults to first found. (only supported with HyperV driver)")
startCmd.Flags().String(kvmNetwork, "default", "The KVM network name. (only supported with KVM driver)")
startCmd.Flags().String(xhyveDiskDriver, "ahci-hd", "The disk driver to use [ahci-hd|virtio-blk] (only supported with xhyve driver)")
startCmd.Flags().StringSlice(NFSShare, []string{}, "Local folders to share with Guest via NFS mounts (Only supported on with hyperkit now)")
startCmd.Flags().String(NFSSharesRoot, "/nfsshares", "Where to root the NFS Shares (defaults to /nfsshares, only supported with hyperkit now)")
startCmd.Flags().StringArrayVar(&dockerEnv, "docker-env", nil, "Environment variables to pass to the Docker daemon. (format: key=value)")
startCmd.Flags().StringArrayVar(&dockerOpt, "docker-opt", nil, "Specify arbitrary flags to pass to the Docker daemon. (format: key=value)")
startCmd.Flags().String(apiServerName, constants.APIServerName, "The apiserver name which is used in the generated certificate for localkube/kubernetes. This can be used if you want to make the apiserver available from outside the machine")
Expand Down
68 changes: 68 additions & 0 deletions pkg/drivers/hyperkit/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ import (
"encoding/json"
"fmt"
"os"
"os/user"
"path"
"path/filepath"
"strings"
"syscall"
"time"

"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/state"
nfsexports "github.com/johanneswuerbach/nfsexports"
hyperkit "github.com/moby/hyperkit/go"
"github.com/pborman/uuid"
"github.com/pkg/errors"
Expand All @@ -53,6 +57,8 @@ type Driver struct {
CPU int
Memory int
Cmdline string
NFSShares []string
NFSSharesRoot string
}

func NewDriver(hostName, storePath string) *Driver {
Expand Down Expand Up @@ -207,6 +213,18 @@ func (d *Driver) Start() error {
if err := commonutil.RetryAfter(30, getIP, 2*time.Second); err != nil {
return fmt.Errorf("IP address never found in dhcp leases file %v", err)
}

if len(d.NFSShares) > 0 {
log.Info("Setting up NFS mounts")
// takes some time here for ssh / nfsd to work properly
time.Sleep(time.Second * 30)
err = d.setupNFSShare()
if err != nil {
log.Errorf("NFS setup failed: %s", err.Error())
return err
}
}

return nil
}

Expand All @@ -232,6 +250,56 @@ func (d *Driver) extractKernel(isoPath string) error {
return nil
}

func (d *Driver) setupNFSShare() error {
user, err := user.Current()
if err != nil {
return err
}

hostIP, err := GetNetAddr()
if err != nil {
return err
}

mountCommands := fmt.Sprintf("#/bin/bash\\n")
log.Info(d.IPAddress)

for _, share := range d.NFSShares {
if !path.IsAbs(share) {
share = d.ResolveStorePath(share)
}
nfsConfig := fmt.Sprintf("%s %s -alldirs -mapall=%s", share, d.IPAddress, user.Username)

if _, err := nfsexports.Add("", d.nfsExportIdentifier(share), nfsConfig); err != nil {
if strings.Contains(err.Error(), "conflicts with existing export") {
log.Info("Conflicting NFS Share not setup and ignored:", err)
continue
}
return err
}

root := d.NFSSharesRoot
mountCommands += fmt.Sprintf("sudo mkdir -p %s/%s\\n", root, share)
mountCommands += fmt.Sprintf("sudo mount -t nfs -o noacl,async %s:%s %s/%s\\n", hostIP, share, root, share)
}

if err := nfsexports.ReloadDaemon(); err != nil {
return err
}

writeScriptCmd := fmt.Sprintf("echo -e \"%s\" | sh", mountCommands)

if _, err := drivers.RunSSHCommandFromDriver(d, writeScriptCmd); err != nil {
return err
}

return nil
}

func (d *Driver) nfsExportIdentifier(path string) string {
return fmt.Sprintf("minikube-hyperkit %s-%s", d.MachineName, path)
}

func (d *Driver) sendSignal(s os.Signal) error {
pid := d.getPid()
proc, err := os.FindProcess(pid)
Expand Down
21 changes: 21 additions & 0 deletions pkg/drivers/hyperkit/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import (
"bufio"
"fmt"
"io"
"net"
"os"
"os/exec"
"regexp"
"strings"
)

const (
DHCPLeasesFile = "/var/db/dhcpd_leases"
CONFIG_PLIST = "/Library/Preferences/SystemConfiguration/com.apple.vmnet"
NET_ADDR_KEY = "Shared_Net_Address"
)

type DHCPEntry struct {
Expand Down Expand Up @@ -108,3 +112,20 @@ func trimMacAddress(rawUUID string) string {

return mac
}

func GetNetAddr() (net.IP, error) {
_, err := os.Stat(CONFIG_PLIST + ".plist")
if err != nil {
return nil, fmt.Errorf("Does not exist %s", CONFIG_PLIST+".plist")
}

out, err := exec.Command("defaults", "read", CONFIG_PLIST, NET_ADDR_KEY).Output()
if err != nil {
return nil, err
}
ip := net.ParseIP(strings.TrimSpace(string(out)))
if ip == nil {
return nil, fmt.Errorf("Could not get the network address for vmnet")
}
return ip, nil
}
4 changes: 3 additions & 1 deletion pkg/drivers/hyperkit/vmnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ limitations under the License.

package hyperkit

import vmnet "github.com/zchee/go-vmnet"
import (
vmnet "github.com/zchee/go-vmnet"
)

func GetMACAddressFromUUID(UUID string) (string, error) {
return vmnet.GetMACAddressFromUUID(UUID)
Expand Down
4 changes: 3 additions & 1 deletion pkg/drivers/hyperkit/vmnet_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ limitations under the License.

package hyperkit

import "errors"
import (
"errors"
)

func GetMACAddressFromUUID(UUID string) (string, error) {
return "", errors.New("Function not supported on CGO_ENABLED=0 binaries")
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/cluster/cluster_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func createHyperkitHost(config MachineConfig) *hyperkit.Driver {
DiskSize: config.DiskSize,
Memory: config.Memory,
CPU: config.CPUs,
NFSShares: config.NFSShare,
NFSSharesRoot: config.NFSSharesRoot,
Cmdline: "loglevel=3 user=docker console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10 systemd.legacy_systemd_cgroup_controller=yes base host=" + cfg.GetMachineName(),
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/cluster/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type MachineConfig struct {
Downloader util.ISODownloader `json:"-"`
DockerOpt []string // Each entry is formatted as KEY=VALUE.
DisableDriverMounts bool // Only used by virtualbox and xhyve
NFSShare []string
NFSSharesRoot string
}

// Config contains machine and k8s config
Expand Down
10 changes: 10 additions & 0 deletions vendor/github.com/johanneswuerbach/nfsexports/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions vendor/github.com/johanneswuerbach/nfsexports/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions vendor/github.com/johanneswuerbach/nfsexports/nfsexports.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/spf13/viper/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.