type check for drivers

pull/4580/head
Medya Gh 2019-06-24 14:39:21 -07:00
parent 550218e7ee
commit c7bf1ce7cd
12 changed files with 62 additions and 39 deletions

View File

@ -21,6 +21,7 @@ import (
"k8s.io/minikube/pkg/minikube/assets" "k8s.io/minikube/pkg/minikube/assets"
pkgConfig "k8s.io/minikube/pkg/minikube/config" pkgConfig "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
) )
var minikubeConfig = pkgConfig.MinikubeConfig{ var minikubeConfig = pkgConfig.MinikubeConfig{
@ -47,7 +48,7 @@ func TestFindSetting(t *testing.T) {
} }
func TestSetString(t *testing.T) { func TestSetString(t *testing.T) {
err := SetString(minikubeConfig, "vm-driver", "virtualbox") err := SetString(minikubeConfig, "vm-driver", constants.DriverVirtualbox)
if err != nil { if err != nil {
t.Fatalf("Couldnt set string: %v", err) t.Fatalf("Couldnt set string: %v", err)
} }

View File

@ -175,14 +175,7 @@ func runStart(cmd *cobra.Command, args []string) {
console.OutStyle(console.Happy, "minikube %s on %s (%s)", version.GetVersion(), runtime.GOOS, runtime.GOARCH) console.OutStyle(console.Happy, "minikube %s on %s (%s)", version.GetVersion(), runtime.GOOS, runtime.GOARCH)
validateConfig() validateConfig()
currentUser, err := user.Current() validateUser()
// Display warning if minikube is being started with root and vmDriver is not HyperV
if err != nil {
glog.Errorf("Error getting the current user: %v", err)
} else if currentUser.Name == "root" && !(viper.GetString(vmDriver) == "hyperv" || viper.GetString(vmDriver) == "none") {
console.OutStyle(console.WarningType, "Please don't run minikube as root or with 'sudo' privileges. It isn't necessary.")
}
oldConfig, err := cfg.Load() oldConfig, err := cfg.Load()
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
@ -231,11 +224,12 @@ func runStart(cmd *cobra.Command, args []string) {
host, preexisting := startHost(m, config.MachineConfig) host, preexisting := startHost(m, config.MachineConfig)
ip := validateNetwork(host) ip := validateNetwork(host)
// Makes minikube node ip to bypass http(s) proxy. since it is local traffic. // Bypass proxy for minikube's vm ip
err = proxy.ExcludeIP(ip) err = proxy.ExcludeIP(ip)
if err != nil { if err != nil {
console.ErrStyle(console.FailureType, "Failed to set NO_PROXY Env. Please use `export NO_PROXY=$NO_PROXY,%s`.", ip) console.ErrStyle(console.FailureType, "Failed to set NO_PROXY Env. Please use `export NO_PROXY=$NO_PROXY,%s`.", ip)
} }
// Save IP to configuration file for subsequent use // Save IP to configuration file for subsequent use
config.KubernetesConfig.NodeIP = ip config.KubernetesConfig.NodeIP = ip
if err := saveConfig(config); err != nil { if err := saveConfig(config); err != nil {
@ -364,6 +358,18 @@ func selectImageRepository(mirrorCountry string, k8sVersion string) (bool, strin
return false, fallback, nil return false, fallback, nil
} }
// validerUser validates minikube is run by the recommended user (privileged or regular)
func validateUser() {
currentUser, err := user.Current()
// Display warning if minikube is being started with root and vmDriver is not HyperV
if err != nil {
glog.Errorf("Error getting the current user: %v", err)
} else if currentUser.Name == "root" && !(viper.GetString(vmDriver) == "hyperv" || viper.GetString(vmDriver) == "none") {
console.OutStyle(console.WarningType, "Please don't run minikube as root or with 'sudo' privileges. It isn't necessary.")
}
}
// validateConfig validates the supplied configuration against known bad combinations // validateConfig validates the supplied configuration against known bad combinations
func validateConfig() { func validateConfig() {
diskSizeMB := pkgutil.CalculateDiskSizeInMB(viper.GetString(humanReadableDiskSize)) diskSizeMB := pkgutil.CalculateDiskSizeInMB(viper.GetString(humanReadableDiskSize))
@ -371,11 +377,11 @@ func validateConfig() {
exit.WithCode(exit.Config, "Requested disk size (%dMB) is less than minimum of %dMB", diskSizeMB, constants.MinimumDiskSizeMB) exit.WithCode(exit.Config, "Requested disk size (%dMB) is less than minimum of %dMB", diskSizeMB, constants.MinimumDiskSizeMB)
} }
if viper.GetBool(gpu) && viper.GetString(vmDriver) != "kvm2" { if viper.GetBool(gpu) && viper.GetString(vmDriver) != constants.DriverKvm2 {
exit.Usage("Sorry, the --gpu feature is currently only supported with --vm-driver=kvm2") exit.Usage("Sorry, the --gpu feature is currently only supported with --vm-driver=%s", constants.DriverKvm2)
} }
if viper.GetBool(hidden) && viper.GetString(vmDriver) != "kvm2" { if viper.GetBool(hidden) && viper.GetString(vmDriver) != constants.DriverKvm2 {
exit.Usage("Sorry, the --hidden feature is currently only supported with --vm-driver=kvm2") exit.Usage("Sorry, the --hidden feature is currently only supported with --vm-driver=%s", constants.DriverKvm2)
} }
err := autoSetOptions(viper.GetString(vmDriver)) err := autoSetOptions(viper.GetString(vmDriver))

View File

@ -118,7 +118,7 @@ func (d *Driver) Create() error {
// DriverName returns the name of the driver // DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "hyperkit" return constants.DriverHyperkit
} }
// GetSSHHostname returns hostname for use with ssh // GetSSHHostname returns hostname for use with ssh
@ -223,7 +223,7 @@ func (d *Driver) Start() error {
h.Memory = d.Memory h.Memory = d.Memory
h.UUID = d.UUID h.UUID = d.UUID
// This should stream logs from hyperkit, but doesn't seem to work. // This should stream logs from hyperkit, but doesn't seem to work.
logger := golog.New(os.Stderr, "hyperkit", golog.LstdFlags) logger := golog.New(os.Stderr, constants.DriverHyperkit, golog.LstdFlags)
h.SetLogger(logger) h.SetLogger(logger)
if vsockPorts, err := d.extractVSockPorts(); err != nil { if vsockPorts, err := d.extractVSockPorts(); err != nil {

View File

@ -220,7 +220,7 @@ func (d *Driver) GetSSHHostname() (string, error) {
// DriverName returns the name of the driver // DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "kvm2" return constants.DriverKvm2
} }
// Kill stops a host forcefully, including any containers that we are managing. // Kill stops a host forcefully, including any containers that we are managing.

View File

@ -409,7 +409,7 @@ func GetVMHostIP(host *host.Host) (net.IP, error) {
switch host.DriverName { switch host.DriverName {
case "kvm": case "kvm":
return net.ParseIP("192.168.42.1"), nil return net.ParseIP("192.168.42.1"), nil
case "kvm2": case constants.DriverKvm2:
return net.ParseIP("192.168.39.1"), nil return net.ParseIP("192.168.39.1"), nil
case "hyperv": case "hyperv":
re := regexp.MustCompile(`"VSwitch": "(.*?)",`) re := regexp.MustCompile(`"VSwitch": "(.*?)",`)
@ -420,7 +420,7 @@ func GetVMHostIP(host *host.Host) (net.IP, error) {
return []byte{}, errors.Wrap(err, fmt.Sprintf("ip for interface (%s)", hypervVirtualSwitch)) return []byte{}, errors.Wrap(err, fmt.Sprintf("ip for interface (%s)", hypervVirtualSwitch))
} }
return ip, nil return ip, nil
case "virtualbox": case constants.DriverVirtualbox:
out, err := exec.Command(detectVBoxManageCmd(), "showvminfo", host.Name, "--machinereadable").Output() out, err := exec.Command(detectVBoxManageCmd(), "showvminfo", host.Name, "--machinereadable").Output()
if err != nil { if err != nil {
return []byte{}, errors.Wrap(err, "vboxmanage") return []byte{}, errors.Wrap(err, "vboxmanage")
@ -432,9 +432,9 @@ func GetVMHostIP(host *host.Host) (net.IP, error) {
return []byte{}, errors.Wrap(err, "Error getting VM/Host IP address") return []byte{}, errors.Wrap(err, "Error getting VM/Host IP address")
} }
return ip, nil return ip, nil
case "xhyve", "hyperkit": case "xhyve", constants.DriverHyperkit:
return net.ParseIP("192.168.64.1"), nil return net.ParseIP("192.168.64.1"), nil
case "vmware": case constants.DriverVmware:
vmIPString, err := host.Driver.GetIP() vmIPString, err := host.Driver.GetIP()
if err != nil { if err != nil {
return []byte{}, errors.Wrap(err, "Error getting VM IP address") return []byte{}, errors.Wrap(err, "Error getting VM IP address")

View File

@ -59,19 +59,37 @@ func ArchTag(hasTag bool) string {
return "-" + runtime.GOARCH + ":" return "-" + runtime.GOARCH + ":"
} }
// DriverNone is the none driver.
const DriverNone = "none"
// DriverKvmOld is the old kvm driver option
const DriverKvmOld = "kvm"
// DriverKvm2 is the kvm2 driver option used in linux
const DriverKvm2 = "kvm2"
// DriverVirtualbox is the virtualbox driver option
const DriverVirtualbox = "virtualbox"
// DriverHyperkit is the hyperkit driver option for mac os
const DriverHyperkit = "hyperkit"
// DriverVmware is the hyperkit driver option for mac os
const DriverVmware = "vmware"
// SupportedVMDrivers is a list of supported drivers on all platforms. Currently // SupportedVMDrivers is a list of supported drivers on all platforms. Currently
// used in gendocs. // used in gendocs.
var SupportedVMDrivers = [...]string{ var SupportedVMDrivers = [...]string{
"virtualbox", DriverVirtualbox,
"parallels", "parallels",
"vmwarefusion", "vmwarefusion",
"kvm", DriverKvmOld,
"xhyve", "xhyve",
"hyperv", "hyperv",
"hyperkit", DriverHyperkit,
"kvm2", DriverKvm2,
"vmware", DriverVmware,
"none", DriverNone,
} }
// DefaultMinipath is the default Minikube path (under the home directory) // DefaultMinipath is the default Minikube path (under the home directory)
@ -130,7 +148,7 @@ const (
// MinimumDiskSizeMB is the minimum disk image size, in megabytes // MinimumDiskSizeMB is the minimum disk image size, in megabytes
MinimumDiskSizeMB = 2000 MinimumDiskSizeMB = 2000
// DefaultVMDriver is the default virtual machine driver name // DefaultVMDriver is the default virtual machine driver name
DefaultVMDriver = "virtualbox" DefaultVMDriver = DriverVirtualbox
// DefaultStatusFormat is the default format of a host // DefaultStatusFormat is the default format of a host
DefaultStatusFormat = `host: {{.Host}} DefaultStatusFormat = `host: {{.Host}}
kubelet: {{.Kubelet}} kubelet: {{.Kubelet}}
@ -235,9 +253,6 @@ func GetKubernetesReleaseURLSHA1(binaryName, version, osName, archName string) s
// IsMinikubeChildProcess is the name of "is minikube child process" variable // IsMinikubeChildProcess is the name of "is minikube child process" variable
const IsMinikubeChildProcess = "IS_MINIKUBE_CHILD_PROCESS" const IsMinikubeChildProcess = "IS_MINIKUBE_CHILD_PROCESS"
// DriverNone is the none driver
const DriverNone = "none"
// FileScheme is the file scheme // FileScheme is the file scheme
const FileScheme = "file" const FileScheme = "file"

View File

@ -31,7 +31,7 @@ import (
func init() { func init() {
if err := registry.Register(registry.DriverDef{ if err := registry.Register(registry.DriverDef{
Name: "hyperkit", Name: constants.DriverHyperkit,
Builtin: false, Builtin: false,
ConfigCreator: createHyperkitHost, ConfigCreator: createHyperkitHost,
}); err != nil { }); err != nil {

View File

@ -30,7 +30,7 @@ import (
func init() { func init() {
if err := registry.Register(registry.DriverDef{ if err := registry.Register(registry.DriverDef{
Name: "kvm2", Name: constants.DriverKvm2,
Builtin: false, Builtin: false,
ConfigCreator: createKVM2Host, ConfigCreator: createKVM2Host,
}); err != nil { }); err != nil {

View File

@ -30,7 +30,7 @@ const defaultVirtualboxNicType = "virtio"
func init() { func init() {
err := registry.Register(registry.DriverDef{ err := registry.Register(registry.DriverDef{
Name: "virtualbox", Name: constants.DriverVirtualbox,
Builtin: true, Builtin: true,
ConfigCreator: createVirtualboxHost, ConfigCreator: createVirtualboxHost,
DriverCreator: func() drivers.Driver { DriverCreator: func() drivers.Driver {

View File

@ -27,7 +27,7 @@ import (
func init() { func init() {
err := registry.Register(registry.DriverDef{ err := registry.Register(registry.DriverDef{
Name: "vmware", Name: constants.DriverVmware,
Builtin: false, Builtin: false,
ConfigCreator: createVMwareHost, ConfigCreator: createVMwareHost,
}) })

View File

@ -76,12 +76,12 @@ func TestLocalClientNewHost(t *testing.T) {
}{ }{
{ {
description: "host vbox correct", description: "host vbox correct",
driver: "virtualbox", driver: constants.DriverVirtualbox,
rawDriver: []byte(vboxConfig), rawDriver: []byte(vboxConfig),
}, },
{ {
description: "host vbox incorrect", description: "host vbox incorrect",
driver: "virtualbox", driver: constants.DriverVirtualbox,
rawDriver: []byte("?"), rawDriver: []byte("?"),
err: true, err: true,
}, },
@ -137,7 +137,7 @@ func TestRunDriver(t *testing.T) {
defer os.RemoveAll(tempDir) defer os.RemoveAll(tempDir)
os.Setenv(localbinary.PluginEnvKey, localbinary.PluginEnvVal) os.Setenv(localbinary.PluginEnvKey, localbinary.PluginEnvVal)
os.Setenv(localbinary.PluginEnvDriverName, "virtualbox") os.Setenv(localbinary.PluginEnvDriverName, constants.DriverVirtualbox)
// Capture stdout and reset it later. // Capture stdout and reset it later.
old := os.Stdout old := os.Stdout

View File

@ -29,6 +29,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
typed_core "k8s.io/client-go/kubernetes/typed/core/v1" typed_core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
) )
//tunnel represents the basic API for a tunnel: periodically the state of the tunnel //tunnel represents the basic API for a tunnel: periodically the state of the tunnel
@ -149,7 +150,7 @@ func setupRoute(t *tunnel, h *host.Host) {
return return
} }
if h.DriverName == "hyperkit" { if h.DriverName == constants.DriverHyperkit {
//the virtio-net interface acts up with ip tunnels :( //the virtio-net interface acts up with ip tunnels :(
setupBridge(t) setupBridge(t)
if t.status.RouteError != nil { if t.status.RouteError != nil {