Improve typecheck for driver options
parent
c7bf1ce7cd
commit
34fda98f4e
|
@ -20,6 +20,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
type configTestCase struct {
|
type configTestCase struct {
|
||||||
|
@ -47,7 +49,7 @@ var configTestCases = []configTestCase{
|
||||||
"vm-driver": "kvm"
|
"vm-driver": "kvm"
|
||||||
}`,
|
}`,
|
||||||
config: map[string]interface{}{
|
config: map[string]interface{}{
|
||||||
"vm-driver": "kvm",
|
"vm-driver": constants.DriverKvmOld,
|
||||||
"cpus": 4,
|
"cpus": 4,
|
||||||
"disk-size": "20g",
|
"disk-size": "20g",
|
||||||
"v": 5,
|
"v": 5,
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var minikubeConfig = pkgConfig.MinikubeConfig{
|
var minikubeConfig = pkgConfig.MinikubeConfig{
|
||||||
"vm-driver": "kvm",
|
"vm-driver": constants.DriverKvmOld,
|
||||||
"cpus": 12,
|
"cpus": 12,
|
||||||
"show-libmachine-logs": true,
|
"show-libmachine-logs": true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -365,7 +365,7 @@ func validateUser() {
|
||||||
// Display warning if minikube is being started with root and vmDriver is not HyperV
|
// Display warning if minikube is being started with root and vmDriver is not HyperV
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error getting the current user: %v", err)
|
glog.Errorf("Error getting the current user: %v", err)
|
||||||
} else if currentUser.Name == "root" && !(viper.GetString(vmDriver) == "hyperv" || viper.GetString(vmDriver) == "none") {
|
} else if currentUser.Name == "root" && !(viper.GetString(vmDriver) == constants.DriverHyperv || viper.GetString(vmDriver) == constants.DriverNone) {
|
||||||
console.OutStyle(console.WarningType, "Please don't run minikube as root or with 'sudo' privileges. It isn't necessary.")
|
console.OutStyle(console.WarningType, "Please don't run minikube as root or with 'sudo' privileges. It isn't necessary.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,7 +254,7 @@ func DeleteHost(api libmachine.API) error {
|
||||||
return errors.Wrap(err, "load")
|
return errors.Wrap(err, "load")
|
||||||
}
|
}
|
||||||
// This is slow if SSH is not responding, but HyperV hangs otherwise, See issue #2914
|
// This is slow if SSH is not responding, but HyperV hangs otherwise, See issue #2914
|
||||||
if host.Driver.DriverName() == "hyperv" {
|
if host.Driver.DriverName() == constants.DriverHyperv {
|
||||||
trySSHPowerOff(host)
|
trySSHPowerOff(host)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,21 +320,21 @@ func engineOptions(config cfg.MachineConfig) *engine.Options {
|
||||||
|
|
||||||
func preCreateHost(config *cfg.MachineConfig) {
|
func preCreateHost(config *cfg.MachineConfig) {
|
||||||
switch config.VMDriver {
|
switch config.VMDriver {
|
||||||
case "kvm":
|
case constants.DriverKvmOld:
|
||||||
if viper.GetBool(cfg.ShowDriverDeprecationNotification) {
|
if viper.GetBool(cfg.ShowDriverDeprecationNotification) {
|
||||||
console.Warning(`The kvm driver is deprecated and support for it will be removed in a future release.
|
console.Warning(`The kvm driver is deprecated and support for it will be removed in a future release.
|
||||||
Please consider switching to the kvm2 driver, which is intended to replace the kvm driver.
|
Please consider switching to the kvm2 driver, which is intended to replace the kvm driver.
|
||||||
See https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#kvm2-driver for more information.
|
See https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#kvm2-driver for more information.
|
||||||
To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`)
|
To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`)
|
||||||
}
|
}
|
||||||
case "xhyve":
|
case constants.DriverXhyve:
|
||||||
if viper.GetBool(cfg.ShowDriverDeprecationNotification) {
|
if viper.GetBool(cfg.ShowDriverDeprecationNotification) {
|
||||||
console.Warning(`The xhyve driver is deprecated and support for it will be removed in a future release.
|
console.Warning(`The xhyve driver is deprecated and support for it will be removed in a future release.
|
||||||
Please consider switching to the hyperkit driver, which is intended to replace the xhyve driver.
|
Please consider switching to the hyperkit driver, which is intended to replace the xhyve driver.
|
||||||
See https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperkit-driver for more information.
|
See https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperkit-driver for more information.
|
||||||
To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`)
|
To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`)
|
||||||
}
|
}
|
||||||
case "vmwarefusion":
|
case constants.DriverVmwareFusion:
|
||||||
if viper.GetBool(cfg.ShowDriverDeprecationNotification) {
|
if viper.GetBool(cfg.ShowDriverDeprecationNotification) {
|
||||||
console.Warning(`The vmwarefusion driver is deprecated and support for it will be removed in a future release.
|
console.Warning(`The vmwarefusion driver is deprecated and support for it will be removed in a future release.
|
||||||
Please consider switching to the new vmware unified driver, which is intended to replace the vmwarefusion driver.
|
Please consider switching to the new vmware unified driver, which is intended to replace the vmwarefusion driver.
|
||||||
|
@ -407,11 +407,11 @@ func GetHostDockerEnv(api libmachine.API) (map[string]string, error) {
|
||||||
// GetVMHostIP gets the ip address to be used for mapping host -> VM and VM -> host
|
// GetVMHostIP gets the ip address to be used for mapping host -> VM and VM -> host
|
||||||
func GetVMHostIP(host *host.Host) (net.IP, error) {
|
func GetVMHostIP(host *host.Host) (net.IP, error) {
|
||||||
switch host.DriverName {
|
switch host.DriverName {
|
||||||
case "kvm":
|
case constants.DriverKvmOld:
|
||||||
return net.ParseIP("192.168.42.1"), nil
|
return net.ParseIP("192.168.42.1"), nil
|
||||||
case constants.DriverKvm2:
|
case constants.DriverKvm2:
|
||||||
return net.ParseIP("192.168.39.1"), nil
|
return net.ParseIP("192.168.39.1"), nil
|
||||||
case "hyperv":
|
case constants.DriverHyperv:
|
||||||
re := regexp.MustCompile(`"VSwitch": "(.*?)",`)
|
re := regexp.MustCompile(`"VSwitch": "(.*?)",`)
|
||||||
// TODO(aprindle) Change this to deserialize the driver instead
|
// TODO(aprindle) Change this to deserialize the driver instead
|
||||||
hypervVirtualSwitch := re.FindStringSubmatch(string(host.RawDriver))[1]
|
hypervVirtualSwitch := re.FindStringSubmatch(string(host.RawDriver))[1]
|
||||||
|
@ -432,7 +432,7 @@ 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", constants.DriverHyperkit:
|
case constants.DriverXhyve, constants.DriverHyperkit:
|
||||||
return net.ParseIP("192.168.64.1"), nil
|
return net.ParseIP("192.168.64.1"), nil
|
||||||
case constants.DriverVmware:
|
case constants.DriverVmware:
|
||||||
vmIPString, err := host.Driver.GetIP()
|
vmIPString, err := host.Driver.GetIP()
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
type configTestCase struct {
|
type configTestCase struct {
|
||||||
|
@ -47,7 +49,7 @@ var configTestCases = []configTestCase{
|
||||||
"vm-driver": "kvm"
|
"vm-driver": "kvm"
|
||||||
}`,
|
}`,
|
||||||
config: map[string]interface{}{
|
config: map[string]interface{}{
|
||||||
"vm-driver": "kvm",
|
"vm-driver": constants.DriverKvmOld,
|
||||||
"cpus": 4,
|
"cpus": 4,
|
||||||
"disk-size": "20g",
|
"disk-size": "20g",
|
||||||
"v": 5,
|
"v": 5,
|
||||||
|
|
|
@ -62,30 +62,42 @@ func ArchTag(hasTag bool) string {
|
||||||
// DriverNone is the none driver.
|
// DriverNone is the none driver.
|
||||||
const DriverNone = "none"
|
const DriverNone = "none"
|
||||||
|
|
||||||
// DriverKvmOld is the old kvm driver option
|
// DriverKvmOld is the depricated kvm driver option name
|
||||||
const DriverKvmOld = "kvm"
|
const DriverKvmOld = "kvm"
|
||||||
|
|
||||||
// DriverKvm2 is the kvm2 driver option used in linux
|
// DriverKvm2 is the kvm2 driver option name for in linux
|
||||||
const DriverKvm2 = "kvm2"
|
const DriverKvm2 = "kvm2"
|
||||||
|
|
||||||
// DriverVirtualbox is the virtualbox driver option
|
// DriverVirtualbox is the virtualbox driver option name
|
||||||
const DriverVirtualbox = "virtualbox"
|
const DriverVirtualbox = "virtualbox"
|
||||||
|
|
||||||
// DriverHyperkit is the hyperkit driver option for mac os
|
// DriverHyperkit is the hyperkit driver option name for mac os
|
||||||
const DriverHyperkit = "hyperkit"
|
const DriverHyperkit = "hyperkit"
|
||||||
|
|
||||||
// DriverVmware is the hyperkit driver option for mac os
|
// DriverVmware is the vmware driver option name
|
||||||
const DriverVmware = "vmware"
|
const DriverVmware = "vmware"
|
||||||
|
|
||||||
|
// DriverVmwareFusion is the vmware fusion driver option
|
||||||
|
const DriverVmwareFusion = "vmwarefusion"
|
||||||
|
|
||||||
|
// DriverHyperv is the hyperv driver option for windows
|
||||||
|
const DriverHyperv = "hyperv"
|
||||||
|
|
||||||
|
// DriverXhyve is the depricated xhyve driver option name
|
||||||
|
const DriverXhyve = "xhyve"
|
||||||
|
|
||||||
|
// DriverParallels is the parallels driver option name
|
||||||
|
const DriverParallels = "parallels"
|
||||||
|
|
||||||
// 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{
|
||||||
DriverVirtualbox,
|
DriverVirtualbox,
|
||||||
"parallels",
|
DriverParallels,
|
||||||
"vmwarefusion",
|
DriverVmwareFusion,
|
||||||
DriverKvmOld,
|
DriverKvmOld,
|
||||||
"xhyve",
|
DriverXhyve,
|
||||||
"hyperv",
|
DriverHyperv,
|
||||||
DriverHyperkit,
|
DriverHyperkit,
|
||||||
DriverKvm2,
|
DriverKvm2,
|
||||||
DriverVmware,
|
DriverVmware,
|
||||||
|
|
|
@ -28,7 +28,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Register(registry.DriverDef{
|
registry.Register(registry.DriverDef{
|
||||||
Name: "hyperv",
|
Name: constants.DriverHyperv,
|
||||||
Builtin: true,
|
Builtin: true,
|
||||||
ConfigCreator: createHypervHost,
|
ConfigCreator: createHypervHost,
|
||||||
DriverCreator: func() drivers.Driver {
|
DriverCreator: func() drivers.Driver {
|
||||||
|
|
|
@ -30,7 +30,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := registry.Register(registry.DriverDef{
|
if err := registry.Register(registry.DriverDef{
|
||||||
Name: "kvm",
|
Name: constants.DriverKvmOld,
|
||||||
Builtin: false,
|
Builtin: false,
|
||||||
ConfigCreator: createKVMHost,
|
ConfigCreator: createKVMHost,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
|
|
@ -30,7 +30,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
err := registry.Register(registry.DriverDef{
|
err := registry.Register(registry.DriverDef{
|
||||||
Name: "parallels",
|
Name: constants.DriverParallels,
|
||||||
Builtin: true,
|
Builtin: true,
|
||||||
ConfigCreator: createParallelsHost,
|
ConfigCreator: createParallelsHost,
|
||||||
DriverCreator: func() drivers.Driver {
|
DriverCreator: func() drivers.Driver {
|
||||||
|
|
|
@ -30,7 +30,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := registry.Register(registry.DriverDef{
|
if err := registry.Register(registry.DriverDef{
|
||||||
Name: "vmwarefusion",
|
Name: constants.DriverVmwareFusion,
|
||||||
Builtin: true,
|
Builtin: true,
|
||||||
ConfigCreator: createVMwareFusionHost,
|
ConfigCreator: createVMwareFusionHost,
|
||||||
DriverCreator: func() drivers.Driver {
|
DriverCreator: func() drivers.Driver {
|
||||||
|
|
|
@ -35,7 +35,7 @@ https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#xhyve-driver
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := registry.Register(registry.DriverDef{
|
if err := registry.Register(registry.DriverDef{
|
||||||
Name: "xhyve",
|
Name: constants.DriverXhyve,
|
||||||
Builtin: false,
|
Builtin: false,
|
||||||
ConfigCreator: createXhyveHost,
|
ConfigCreator: createXhyveHost,
|
||||||
DriverCreator: func() drivers.Driver {
|
DriverCreator: func() drivers.Driver {
|
||||||
|
|
Loading…
Reference in New Issue