提交 6d7d589a 编写于 作者: T Thomas Stromberg

Consolidate driver-interaction code into pkg/minikube/driver

上级 3161c4e8
......@@ -26,7 +26,7 @@ import (
)
var minikubeConfig = pkgConfig.MinikubeConfig{
"vm-driver": constants.DriverKvm2,
"vm-driver": constants.KVM2,
"cpus": 12,
"show-libmachine-logs": true,
}
......@@ -49,7 +49,7 @@ func TestFindSetting(t *testing.T) {
}
func TestSetString(t *testing.T) {
err := SetString(minikubeConfig, "vm-driver", constants.DriverVirtualbox)
err := SetString(minikubeConfig, "vm-driver", constants.VirtualBox)
if err != nil {
t.Fatalf("Couldn't set string: %v", err)
}
......
......@@ -28,8 +28,8 @@ import (
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/out"
)
......@@ -44,13 +44,11 @@ and then start minikube again with the following flags:
minikube start --container-runtime=containerd --docker-opt containerd=/var/run/containerd/containerd.sock`
// IsValidDriver checks if a driver is supported
func IsValidDriver(string, driver string) error {
for _, d := range constants.SupportedVMDrivers {
if driver == d {
return nil
}
func IsValidDriver(string, name string) error {
if driver.Supported(name) {
return nil
}
return fmt.Errorf("driver %q is not supported", driver)
return fmt.Errorf("driver %q is not supported", name)
}
// RequiresRestartMsg returns the "requires restart" message
......
......@@ -35,6 +35,7 @@ import (
"k8s.io/minikube/pkg/minikube/cluster"
pkg_config "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/kubeconfig"
"k8s.io/minikube/pkg/minikube/localpath"
......@@ -157,8 +158,7 @@ func deleteProfile(profile *pkg_config.Profile) error {
return DeletionError{Err: delErr, Errtype: MissingProfile}
}
// In the case of "none", we want to uninstall Kubernetes as there is no VM to delete
if err == nil && cc.MachineConfig.VMDriver == constants.DriverNone {
if err == nil && driver.BareMetal(cc.MachineConfig.VMDriver) {
if err := uninstallKubernetes(api, cc.KubernetesConfig, viper.GetString(cmdcfg.Bootstrapper)); err != nil {
deletionError, ok := err.(DeletionError)
if ok {
......
......@@ -35,7 +35,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
)
......@@ -343,7 +343,7 @@ var dockerEnvCmd = &cobra.Command{
if err != nil {
exit.WithError("Error getting host", err)
}
if host.Driver.DriverName() == constants.DriverNone {
if host.Driver.DriverName() == driver.None {
exit.UsageT(`'none' driver does not support 'minikube docker-env' command`)
}
hostSt, err := cluster.GetHostStatus(api)
......
......@@ -31,7 +31,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
......@@ -107,7 +107,7 @@ var mountCmd = &cobra.Command{
if err != nil {
exit.WithError("Error loading api", err)
}
if host.Driver.DriverName() == constants.DriverNone {
if host.Driver.DriverName() == driver.None {
exit.UsageT(`'none' driver does not support 'minikube mount' command`)
}
var ip net.IP
......
......@@ -25,7 +25,7 @@ import (
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
......@@ -46,7 +46,7 @@ var sshCmd = &cobra.Command{
if err != nil {
exit.WithError("Error getting host", err)
}
if host.Driver.DriverName() == constants.DriverNone {
if host.Driver.DriverName() == driver.None {
exit.UsageT("'none' driver does not support 'minikube ssh' command")
}
if viper.GetBool(nativeSSH) {
......
......@@ -45,7 +45,6 @@ import (
"github.com/spf13/viper"
"golang.org/x/sync/errgroup"
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/drivers"
"k8s.io/minikube/pkg/minikube/bootstrapper"
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/bootstrapper/kubeadm"
......@@ -54,7 +53,7 @@ import (
cfg "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/drivers/none"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/kubeconfig"
"k8s.io/minikube/pkg/minikube/localpath"
......@@ -203,7 +202,7 @@ func initKubernetesFlags() {
// initDriverFlags inits the commandline flags for vm drivers
func initDriverFlags() {
startCmd.Flags().String("vm-driver", "", fmt.Sprintf("Driver is one of: %v (defaults to virtualbox)", constants.SupportedVMDrivers))
startCmd.Flags().String("vm-driver", "", fmt.Sprintf("Driver is one of: %v (defaults to %s)", driver.SupportedDrivers(), driver.Default()))
startCmd.Flags().Bool(disableDriverMounts, false, "Disables the filesystem mounts provided by the hypervisors")
// kvm2
......@@ -297,24 +296,23 @@ func runStart(cmd *cobra.Command, args []string) {
exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", out.V{"error": err})
}
driver := selectDriver(oldConfig)
err = autoSetDriverOptions(driver)
driverName := selectDriver(oldConfig)
err = autoSetDriverOptions(cmd, driverName)
if err != nil {
glog.Errorf("Error autoSetOptions : %v", err)
}
validateFlags(driver)
validateUser(driver)
validateFlags(driverName)
validateUser(driverName)
_ = getMinikubeVersion(driver)
_ = getMinikubeVersion(driverName)
k8sVersion, isUpgrade := getKubernetesVersion(oldConfig)
config, err := generateCfgFromFlags(cmd, k8sVersion, driver)
config, err := generateCfgFromFlags(cmd, k8sVersion, driverName)
if err != nil {
exit.WithError("Failed to generate config", err)
}
// For non-"none", the ISO is required to boot, so block until it is downloaded
if driver != constants.DriverNone {
if !driver.BareMetal(driverName) {
if err := cluster.CacheISO(config.MachineConfig); err != nil {
exit.WithError("Failed to cache ISO", err)
}
......@@ -341,7 +339,7 @@ func runStart(cmd *cobra.Command, args []string) {
mRunner, preExists, machineAPI, host := startMachine(&config)
defer machineAPI.Close()
// configure the runtime (docker, containerd, crio)
cr := configureRuntimes(mRunner, driver, config.KubernetesConfig)
cr := configureRuntimes(mRunner, driverName, config.KubernetesConfig)
showVersionInfo(k8sVersion, cr)
waitCacheImages(&cacheGroup)
......@@ -370,8 +368,8 @@ func runStart(cmd *cobra.Command, args []string) {
out.T(out.FailureType, "Unable to load cached images from config file.")
}
// special ops for none driver, like change minikube directory.
if driver == constants.DriverNone {
// special ops for none , like change minikube directory.
if driverName == driver.None {
prepareNone()
}
if viper.GetBool(waitUntilHealthy) {
......@@ -537,46 +535,46 @@ func showKubectlConnectInfo(kcs *kubeconfig.Settings) {
}
func selectDriver(oldConfig *cfg.Config) string {
driver := viper.GetString("vm-driver")
name := viper.GetString("vm-driver")
// By default, the driver is whatever we used last time
if driver == "" {
driver = constants.DriverVirtualbox
if name == "" {
name = driver.Default()
if oldConfig != nil {
driver = oldConfig.MachineConfig.VMDriver
return oldConfig.MachineConfig.VMDriver
}
}
if err := cmdcfg.IsValidDriver(runtime.GOOS, driver); err != nil {
exit.WithCodeT(exit.Failure, "The driver '{{.driver}}' is not supported on {{.os}}", out.V{"driver": driver, "os": runtime.GOOS})
if !driver.Supported(name) {
exit.WithCodeT(exit.Failure, "The driver '{{.driver}}' is not supported on {{.os}}", out.V{"driver": name, "os": runtime.GOOS})
}
// Detect if our driver conflicts with a previously created VM. If we run into any errors, just move on.
api, err := machine.NewAPIClient()
if err != nil {
glog.Infof("selectDriver NewAPIClient: %v", err)
return driver
return name
}
exists, err := api.Exists(cfg.GetMachineName())
if err != nil {
glog.Infof("selectDriver api.Exists: %v", err)
return driver
return name
}
if !exists {
return driver
return name
}
h, err := api.Load(cfg.GetMachineName())
if err != nil {
glog.Infof("selectDriver api.Load: %v", err)
return driver
return name
}
if h.Driver.DriverName() == driver || h.Driver.DriverName() == "not-found" {
return driver
if h.Driver.DriverName() == name || h.Driver.DriverName() == "not-found" {
return name
}
out.ErrT(out.Conflict, `The existing "{{.profile_name}}" VM that was created using the "{{.old_driver}}" driver, and is incompatible with the "{{.driver}}" driver.`,
out.V{"profile_name": cfg.GetMachineName(), "driver": driver, "old_driver": h.Driver.DriverName()})
out.V{"profile_name": cfg.GetMachineName(), "driver": name, "old_driver": h.Driver.DriverName()})
out.ErrT(out.Workaround, `To proceed, either:
1) Delete the existing VM using: '{{.command}} delete'
......@@ -646,7 +644,7 @@ func minikubeCmd() string {
}
// validerUser validates minikube is run by the recommended user (privileged or regular)
func validateUser(driver string) {
func validateUser(drvName string) {
u, err := user.Current()
if err != nil {
glog.Errorf("Error getting the current user: %v", err)
......@@ -655,15 +653,15 @@ func validateUser(driver string) {
useForce := viper.GetBool(force)
if driver == constants.DriverNone && u.Uid != "0" && !useForce {
exit.WithCodeT(exit.Permissions, `The "{{.driver_name}}" driver requires root privileges. Please run minikube using 'sudo minikube --vm-driver={{.driver_name}}'.`, out.V{"driver_name": driver})
if driver.BareMetal(drvName) && u.Uid != "0" && !useForce {
exit.WithCodeT(exit.Permissions, `The "{{.driver_name}}" driver requires root privileges. Please run minikube using 'sudo minikube --vm-driver={{.driver_name}}'.`, out.V{"driver_name": drvName})
}
if driver == constants.DriverNone || u.Uid != "0" {
if driver.BareMetal(drvName) || u.Uid != "0" {
return
}
out.T(out.Stopped, `The "{{.driver_name}}" driver should not be used with root privileges.`, out.V{"driver_name": driver})
out.T(out.Stopped, `The "{{.driver_name}}" driver should not be used with root privileges.`, out.V{"driver_name": drvName})
out.T(out.Tip, "If you are running minikube within a VM, consider using --vm-driver=none:")
out.T(out.Documentation, " https://minikube.sigs.k8s.io/docs/reference/drivers/none/")
......@@ -680,7 +678,7 @@ func validateUser(driver string) {
}
// validateFlags validates the supplied flags against known bad combinations
func validateFlags(driver string) {
func validateFlags(drvName string) {
diskSizeMB := pkgutil.CalculateSizeInMB(viper.GetString(humanReadableDiskSize))
if diskSizeMB < pkgutil.CalculateSizeInMB(minimumDiskSize) && !viper.GetBool(force) {
exit.WithCodeT(exit.Config, "Requested disk size {{.requested_size}} is less than minimum of {{.minimum_size}}", out.V{"requested_size": diskSizeMB, "minimum_size": pkgutil.CalculateSizeInMB(minimumDiskSize)})
......@@ -696,7 +694,7 @@ func validateFlags(driver string) {
}
var cpuCount int
if driver == constants.DriverNone {
if driver.BareMetal(drvName) {
if cfg.GetMachineName() != constants.DefaultMachineName {
exit.WithCodeT(exit.Config, "The 'none' driver does not support multiple profiles: https://minikube.sigs.k8s.io/docs/reference/drivers/none/")
}
......@@ -771,7 +769,7 @@ func waitCacheImages(g *errgroup.Group) {
}
// generateCfgFromFlags generates cfg.Config based on flags and supplied arguments
func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, driver string) (cfg.Config, error) {
func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) (cfg.Config, error) {
r, err := cruntime.New(cruntime.Config{Type: viper.GetString(containerRuntime)})
if err != nil {
return cfg.Config{}, err
......@@ -823,7 +821,7 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, driver string)
Memory: pkgutil.CalculateSizeInMB(viper.GetString(memory)),
CPUs: viper.GetInt(cpus),
DiskSize: pkgutil.CalculateSizeInMB(viper.GetString(humanReadableDiskSize)),
VMDriver: driver,
VMDriver: drvName,
ContainerRuntime: viper.GetString(containerRuntime),
HyperkitVpnKitSock: viper.GetString(vpnkitSock),
HyperkitVSockPorts: viper.GetStringSlice(vsockPorts),
......@@ -887,12 +885,14 @@ func setDockerProxy() {
}
// autoSetDriverOptions sets the options needed for specific vm-driver automatically.
func autoSetDriverOptions(driver string) error {
if driver == constants.DriverNone {
if o := none.AutoOptions(); o != "" {
return extraOptions.Set(o)
}
viper.Set(cacheImages, false)
func autoSetDriverOptions(cmd *cobra.Command, drvName string) error {
hints := driver.FlagDefaults(drvName)
if !cmd.Flags().Changed("extra-config") && hints.ExtraOptions != "" {
return extraOptions.Set(hints.ExtraOptions)
}
if !cmd.Flags().Changed(cacheImages) {
viper.Set(cacheImages, hints.CacheImages)
}
return nil
}
......@@ -981,12 +981,12 @@ func validateNetwork(h *host.Host) string {
}
// getMinikubeVersion ensures that the driver binary is up to date
func getMinikubeVersion(driver string) string {
func getMinikubeVersion(drvName string) string {
v, err := version.GetSemverVersion()
if err != nil {
out.WarningT("Error parsing minikube version: {{.error}}", out.V{"error": err})
} else if err := drivers.InstallOrUpdate(driver, localpath.MakeMiniPath("bin"), v, viper.GetBool(interactive)); err != nil {
out.WarningT("Unable to update {{.driver}} driver: {{.error}}", out.V{"driver": driver, "error": err})
} else if err := driver.InstallOrUpdate(drvName, localpath.MakeMiniPath("bin"), v, viper.GetBool(interactive)); err != nil {
out.WarningT("Unable to update {{.driver}} driver: {{.error}}", out.V{"driver": drvName, "error": err})
}
return v.String()
}
......@@ -1068,7 +1068,7 @@ func setupKubeAdm(mAPI libmachine.API, kc cfg.KubernetesConfig) bootstrapper.Boo
}
// configureRuntimes does what needs to happen to get a runtime going.
func configureRuntimes(runner cruntime.CommandRunner, driver string, k8s cfg.KubernetesConfig) cruntime.Manager {
func configureRuntimes(runner cruntime.CommandRunner, drvName string, k8s cfg.KubernetesConfig) cruntime.Manager {
config := cruntime.Config{Type: viper.GetString(containerRuntime), Runner: runner, ImageRepository: k8s.ImageRepository, KubernetesVersion: k8s.KubernetesVersion}
cr, err := cruntime.New(config)
if err != nil {
......@@ -1076,7 +1076,7 @@ func configureRuntimes(runner cruntime.CommandRunner, driver string, k8s cfg.Kub
}
disableOthers := true
if driver == constants.DriverNone {
if driver.BareMetal(drvName) {
disableOthers = false
}
err = cr.Enable(disableOthers)
......
......@@ -25,7 +25,7 @@ require (
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/google/go-cmp v0.3.0
github.com/google/go-github/v25 v25.0.2
github.com/google/go-github/v25 v25.0.2 // indirect
github.com/gorilla/mux v1.7.1 // indirect
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect
github.com/hashicorp/go-getter v1.3.0
......@@ -69,7 +69,6 @@ require (
github.com/zchee/go-vmnet v0.0.0-20161021174912-97ebf9174097
golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb
golang.org/x/text v0.3.2
......
......@@ -17,31 +17,23 @@ limitations under the License.
package drivers
import (
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"syscall"
"github.com/blang/semver"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/mcnflag"
"github.com/docker/machine/libmachine/mcnutils"
"github.com/docker/machine/libmachine/ssh"
"github.com/golang/glog"
"github.com/hashicorp/go-getter"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/version"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/util"
)
// This file is for common code shared among internal machine drivers
// Code here should not be called from within minikube
// GetDiskPath returns the path of the machine disk image
func GetDiskPath(d *drivers.BaseDriver) string {
return filepath.Join(d.ResolveStorePath("."), d.GetMachineName()+".rawdisk")
......@@ -147,137 +139,3 @@ func fixMachinePermissions(path string) error {
}
return nil
}
// InstallOrUpdate downloads driver if it is not present, or updates it if there's a newer version
func InstallOrUpdate(driver string, directory string, v semver.Version, interactive bool) error {
if driver != constants.DriverKvm2 && driver != constants.DriverHyperkit {
return nil
}
executable := fmt.Sprintf("docker-machine-driver-%s", driver)
path, err := validateDriver(executable, v)
if err != nil {
glog.Warningf("%s: %v", executable, err)
path = filepath.Join(directory, executable)
derr := download(executable, path, v)
if derr != nil {
return derr
}
}
return fixDriverPermissions(driver, path, interactive)
}
// fixDriverPermissions fixes the permissions on a driver
func fixDriverPermissions(driver string, path string, interactive bool) error {
// This method only supports hyperkit so far (because it's complicated)
if driver != constants.DriverHyperkit {
return nil
}
// Using the find command for hyperkit is far easier than cross-platform uid checks in Go.
stdout, err := exec.Command("find", path, "-uid", "0", "-perm", "4755").Output()
glog.Infof("stdout: %s", stdout)
if err == nil && strings.TrimSpace(string(stdout)) == path {
glog.Infof("%s looks good", path)
return nil
}
cmds := []*exec.Cmd{
exec.Command("sudo", "chown", "root:wheel", path),
exec.Command("sudo", "chmod", "u+s", path),
}
var example strings.Builder
for _, c := range cmds {
example.WriteString(fmt.Sprintf(" $ %s \n", strings.Join(c.Args, " ")))
}
out.T(out.Permissions, "The '{{.driver}}' driver requires elevated permissions. The following commands will be executed:\n\n{{ .example }}\n", out.V{"driver": driver, "example": example.String()})
for _, c := range cmds {
testArgs := append([]string{"-n"}, c.Args[1:]...)
test := exec.Command("sudo", testArgs...)
glog.Infof("testing: %v", test.Args)
if err := test.Run(); err != nil {
glog.Infof("%v may require a password: %v", c.Args, err)
if !interactive {
return fmt.Errorf("%v requires a password, and --interactive=false", c.Args)
}
}
glog.Infof("running: %v", c.Args)
err := c.Run()
if err != nil {
return errors.Wrapf(err, "%v", c.Args)
}
}
return nil
}
// validateDriver validates if a driver appears to be up-to-date and installed properly
func validateDriver(driver string, v semver.Version) (string, error) {
glog.Infof("Validating %s, PATH=%s", driver, os.Getenv("PATH"))
path, err := exec.LookPath(driver)
if err != nil {
return path, err
}
output, err := exec.Command(path, "version").Output()
if err != nil {
return path, err
}
ev := extractVMDriverVersion(string(output))
if len(ev) == 0 {
return path, fmt.Errorf("%s: unable to extract version from %q", driver, output)
}
vmDriverVersion, err := semver.Make(ev)
if err != nil {
return path, errors.Wrap(err, "can't parse driver version")
}
if vmDriverVersion.LT(v) {
return path, fmt.Errorf("%s is version %s, want %s", driver, vmDriverVersion, v)
}
return path, nil
}
func driverWithChecksumURL(driver string, v semver.Version) string {
base := fmt.Sprintf("https://github.com/kubernetes/minikube/releases/download/v%s/%s", v, driver)
return fmt.Sprintf("%s?checksum=file:%s.sha256", base, base)
}
// download an arbitrary driver
func download(driver string, destination string, v semver.Version) error {
out.T(out.FileDownload, "Downloading driver {{.driver}}:", out.V{"driver": driver})
os.Remove(destination)
url := driverWithChecksumURL(driver, v)
client := &getter.Client{
Src: url,
Dst: destination,
Mode: getter.ClientModeFile,
Options: []getter.ClientOption{getter.WithProgress(util.DefaultProgressBar)},
}
glog.Infof("Downloading: %+v", client)
if err := client.Get(); err != nil {
return errors.Wrapf(err, "download failed: %s", url)
}
// Give downloaded drivers a baseline decent file permission
return os.Chmod(destination, 0755)
}
// extractVMDriverVersion extracts the driver version.
// KVM and Hyperkit drivers support the 'version' command, that display the information as:
// version: vX.X.X
// commit: XXXX
// This method returns the version 'vX.X.X' or empty if the version isn't found.
func extractVMDriverVersion(s string) string {
versionRegex := regexp.MustCompile(`version:(.*)`)
matches := versionRegex.FindStringSubmatch(s)
if len(matches) != 2 {
return ""
}
v := strings.TrimSpace(matches[1])
return strings.TrimPrefix(v, version.VersionPrefix)
}
......@@ -29,14 +29,11 @@ import (
"k8s.io/apimachinery/pkg/util/net"
pkgdrivers "k8s.io/minikube/pkg/drivers"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/vmpath"
"k8s.io/minikube/pkg/util/retry"
)
const driverName = constants.DriverNone
// cleanupPaths are paths to be removed by cleanup, and are used by both kubeadm and minikube.
var cleanupPaths = []string{
vmpath.GuestEphemeralDir,
......@@ -92,7 +89,7 @@ func (d *Driver) Create() error {
// DriverName returns the name of the driver
func (d *Driver) DriverName() string {
return driverName
return "none"
}
// GetIP returns an IP or hostname that this host is available at
......
......@@ -45,6 +45,7 @@ import (
"github.com/spf13/viper"
cfg "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/out"
......@@ -78,7 +79,7 @@ func init() {
// CacheISO downloads and caches ISO.
func CacheISO(config cfg.MachineConfig) error {
if localDriver(config.VMDriver) {
if driver.BareMetal(config.VMDriver) {
return nil
}
return config.Downloader.CacheMinikubeISOFromURL(config.MinikubeISO)
......@@ -136,13 +137,6 @@ func StartHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error)
return h, nil
}
// localDriver returns whether or not the driver should be considered local
func localDriver(name string) bool {
if name == constants.DriverNone || name == constants.DriverMock {
return true
}
return false
}
// configureHost handles any post-powerup configuration required
func configureHost(h *host.Host, e *engine.Options) error {
......@@ -165,7 +159,7 @@ func configureHost(h *host.Host, e *engine.Options) error {
}
}
if localDriver(h.Driver.DriverName()) {
if driver.BareMetal(h.Driver.DriverName()) {
glog.Infof("%s is a local driver, skipping auth/time setup", h.Driver.DriverName())
return nil
}
......@@ -251,7 +245,7 @@ func StopHost(api libmachine.API) error {
}
out.T(out.Stopping, `Stopping "{{.profile_name}}" in {{.driver_name}} ...`, out.V{"profile_name": cfg.GetMachineName(), "driver_name": host.DriverName})
if host.DriverName == constants.DriverHyperv {
if host.DriverName == driver.HyperV {
glog.Infof("As there are issues with stopping Hyper-V VMs using API, trying to shut down using SSH")
if err := trySSHPowerOff(host); err != nil {
return errors.Wrap(err, "ssh power off")
......@@ -285,7 +279,7 @@ func DeleteHost(api libmachine.API) error {
}
// This is slow if SSH is not responding, but HyperV hangs otherwise, See issue #2914
if host.Driver.DriverName() == constants.DriverHyperv {
if host.Driver.DriverName() == driver.HyperV {
if err := trySSHPowerOff(host); err != nil {
glog.Infof("Unable to power off minikube because the host was not found.")
}
......@@ -421,13 +415,13 @@ func showRemoteOsRelease(driver drivers.Driver) {
}
func createHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error) {
if config.VMDriver == constants.DriverVmwareFusion && viper.GetBool(cfg.ShowDriverDeprecationNotification) {
if config.VMDriver == driver.VMwareFusion && viper.GetBool(cfg.ShowDriverDeprecationNotification) {
out.WarningT(`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.
See https://minikube.sigs.k8s.io/docs/reference/drivers/vmware/ for more information.
To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`)
}
if !localDriver(config.VMDriver) {
if !driver.BareMetal(config.VMDriver) {
out.T(out.StartingVM, "Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"driver_name": config.VMDriver, "number_of_cpus": config.CPUs, "memory_size": config.Memory, "disk_size": config.DiskSize})
} else {
info, err := getHostInfo()
......@@ -444,8 +438,8 @@ func createHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error
return nil, errors.Wrap(err, "error getting driver")
}
driver := def.ConfigCreator(config)
data, err := json.Marshal(driver)
dd := def.ConfigCreator(config)
data, err := json.Marshal(dd)
if err != nil {
return nil, errors.Wrap(err, "marshal")
}
......@@ -465,7 +459,7 @@ func createHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error
return nil, errors.Wrap(err, "create")
}
if !localDriver(config.VMDriver) {
if !driver.BareMetal(config.VMDriver) {
showRemoteOsRelease(h.Driver)
// Ensure that even new VM's have proper time synchronization up front
// It's 2019, and I can't believe I am still dealing with time desync as a problem.
......@@ -507,9 +501,9 @@ func GetHostDockerEnv(api libmachine.API) (map[string]string, error) {
// GetVMHostIP gets the ip address to be used for mapping host -> VM and VM -> host
func GetVMHostIP(host *host.Host) (net.IP, error) {
switch host.DriverName {
case constants.DriverKvm2:
case driver.KVM2:
return net.ParseIP("192.168.39.1"), nil
case constants.DriverHyperv:
case driver.HyperV:
re := regexp.MustCompile(`"VSwitch": "(.*?)",`)
// TODO(aprindle) Change this to deserialize the driver instead
hypervVirtualSwitch := re.FindStringSubmatch(string(host.RawDriver))[1]
......@@ -518,8 +512,8 @@ func GetVMHostIP(host *host.Host) (net.IP, error) {
return []byte{}, errors.Wrap(err, fmt.Sprintf("ip for interface (%s)", hypervVirtualSwitch))
}
return ip, nil
case constants.DriverVirtualbox:
out, err := exec.Command(detectVBoxManageCmd(), "showvminfo", host.Name, "--machinereadable").Output()
case driver.VirtualBox:
out, err := exec.Command(driver.VBoxManagePath(), "showvminfo", host.Name, "--machinereadable").Output()
if err != nil {
return []byte{}, errors.Wrap(err, "vboxmanage")
}
......@@ -530,9 +524,9 @@ func GetVMHostIP(host *host.Host) (net.IP, error) {
return []byte{}, errors.Wrap(err, "Error getting VM/Host IP address")
}
return ip, nil
case constants.DriverHyperkit:
case driver.HyperKit:
return net.ParseIP("192.168.64.1"), nil
case constants.DriverVmware:
case driver.VMware:
vmIPString, err := host.Driver.GetIP()
if err != nil {
return []byte{}, errors.Wrap(err, "Error getting VM IP address")
......
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cluster
import (
"os/exec"
)
func detectVBoxManageCmd() string {
cmd := "VBoxManage"
if path, err := exec.LookPath(cmd); err == nil {
return path
}
return cmd
}
......@@ -28,6 +28,7 @@ import (
"github.com/docker/machine/libmachine/state"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/registry"
"k8s.io/minikube/pkg/minikube/tests"
)
......@@ -43,13 +44,13 @@ func createMockDriverHost(c config.MachineConfig) interface{} {
func RegisterMockDriver(t *testing.T) {
t.Helper()
_, err := registry.Driver(constants.DriverMock)
_, err := registry.Driver(driver.Mock)
// Already registered
if err == nil {
return
}
err = registry.Register(registry.DriverDef{
Name: constants.DriverMock,
Name: driver.Mock,
Builtin: true,
ConfigCreator: createMockDriverHost,
DriverCreator: func() drivers.Driver {
......@@ -62,7 +63,7 @@ func RegisterMockDriver(t *testing.T) {
}
var defaultMachineConfig = config.MachineConfig{
VMDriver: constants.DriverMock,
VMDriver: driver.Mock,
MinikubeISO: constants.DefaultISOURL,
Downloader: MockDownloader{},
DockerEnv: []string{"MOCK_MAKE_IT_PROVISION=true"},
......@@ -216,7 +217,7 @@ func TestStartHostConfig(t *testing.T) {
provision.SetDetector(md)
config := config.MachineConfig{
VMDriver: constants.DriverMock,
VMDriver: driver.Mock,
DockerEnv: []string{"FOO=BAR"},
DockerOpt: []string{"param=value"},
Downloader: MockDownloader{},
......
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cluster
import (
// Import all the default drivers
_ "k8s.io/minikube/pkg/minikube/drivers/hyperkit"
_ "k8s.io/minikube/pkg/minikube/drivers/hyperv"
_ "k8s.io/minikube/pkg/minikube/drivers/kvm2"
_ "k8s.io/minikube/pkg/minikube/drivers/none"
_ "k8s.io/minikube/pkg/minikube/drivers/parallels"
_ "k8s.io/minikube/pkg/minikube/drivers/virtualbox"
_ "k8s.io/minikube/pkg/minikube/drivers/vmware"
_ "k8s.io/minikube/pkg/minikube/drivers/vmwarefusion"
)
......@@ -51,7 +51,7 @@ var configTestCases = []configTestCase{
"vm-driver": "kvm2"
}`,
config: map[string]interface{}{
"vm-driver": constants.DriverKvm2,
"vm-driver": constants.KVM2,
"cpus": 4,
"disk-size": "20g",
"v": 5,
......@@ -132,7 +132,7 @@ func TestReadConfig(t *testing.T) {
}
expectedConfig := map[string]interface{}{
"vm-driver": constants.DriverKvm2,
"vm-driver": constants.KVM2,
"cpus": 4,
"disk-size": "20g",
"show-libmachine-logs": true,
......@@ -151,7 +151,7 @@ func TestWriteConfig(t *testing.T) {
}
cfg := map[string]interface{}{
"vm-driver": constants.DriverKvm2,
"vm-driver": constants.KVM2,
"cpus": 4,
"disk-size": "20g",
"show-libmachine-logs": true,
......
......@@ -35,33 +35,6 @@ const (
ClusterDNSDomain = "cluster.local"
)
// DriverMock is a mock driver.
const DriverMock = "mock-driver"
// DriverNone is the none driver.
const DriverNone = "none"
// DriverKvm2 is the kvm2 driver option name for in linux
const DriverKvm2 = "kvm2"
// DriverVirtualbox is the virtualbox driver option name
const DriverVirtualbox = "virtualbox"
// DriverHyperkit is the hyperkit driver option name for mac os
const DriverHyperkit = "hyperkit"
// DriverVmware is the vmware driver option name
const DriverVmware = "vmware"
// DriverVmwareFusion is the vmware fusion driver option
const DriverVmwareFusion = "vmwarefusion"
// DriverHyperv is the hyperv driver option for windows
const DriverHyperv = "hyperv"
// DriverParallels is the parallels driver option name
const DriverParallels = "parallels"
// DefaultMinipath is the default Minikube path (under the home directory)
var DefaultMinipath = filepath.Join(homedir.HomeDir(), ".minikube")
......
......@@ -20,12 +20,3 @@ package constants
// DefaultMountDir is the default mounting directory for Darwin
var DefaultMountDir = "/Users"
// SupportedVMDrivers is a list of supported drivers on Darwin.
var SupportedVMDrivers = [...]string{
DriverVirtualbox,
DriverParallels,
DriverVmwareFusion,
DriverHyperkit,
DriverVmware,
}
......@@ -19,15 +19,3 @@ limitations under the License.
package constants
var DefaultMountDir = "$HOME"
// SupportedVMDrivers is a list of supported drivers on all platforms.
var SupportedVMDrivers = [...]string{
DriverVirtualbox,
DriverParallels,
DriverVmwareFusion,
DriverHyperv,
DriverHyperkit,
DriverKvm2,
DriverVmware,
DriverNone,
}
......@@ -24,13 +24,3 @@ import (
// DefaultMountDir is the default mount dir
var DefaultMountDir = homedir.HomeDir()
// SupportedVMDrivers is a list of supported drivers on Linux.
var SupportedVMDrivers = [...]string{
DriverVirtualbox,
DriverParallels,
DriverVmwareFusion,
DriverKvm2,
DriverVmware,
DriverNone,
}
......@@ -23,11 +23,3 @@ import (
)
var DefaultMountDir = homedir.HomeDir()
// SupportedVMDrivers is a list of supported drivers on Windows.
var SupportedVMDrivers = [...]string{
DriverVirtualbox,
DriverVmwareFusion,
DriverHyperv,
DriverVmware,
}
package driver
const (
// Driver names
Mock = "mock-driver"
None = "none"
KVM2 = "kvm2"
VirtualBox = "virtualbox"
HyperKit = "hyperkit"
VMware = "vmware"
VMwareFusion = "vmwarefusion"
HyperV = "hyperv"
Parallels = "parallels"
)
package driver
import (
"fmt"
"os"
)
// SupportedDrivers returns a list of supported drivers
func SupportedDrivers() []string {
return supportedDrivers
}
// Supported returns if the driver is supported on this host.
func Supported(name string) bool {
for _, d := range supportedDrivers {
if name == d {
return true
}
}
return false
}
// BareMetal returns if this driver is unisolated
func BareMetal(name string) bool {
return name == None || name == Mock
}
// FlagHints are hints for what default options should be used for this driver
type FlagHints struct {
ExtraOptions string
CacheImages bool
}
// FlagDefaults returns suggested defaults based on a driver
func FlagDefaults(name string) FlagHints {
if name != None {
return FlagHints{}
}
// for more info see: https://github.com/kubernetes/minikube/issues/3511
f := "/run/systemd/resolve/resolv.conf"
extraOpts := ""
if _, err := os.Stat(f); err == nil {
extraOpts = fmt.Sprintf("kubelet.resolv-conf=%s", f)
}
return FlagHints{
ExtraOptions: extraOpts,
CacheImages: false,
}
}
// Default returns the default driver on this hos
func Default() string {
return VirtualBox
}
package driver
import "os/exec"
// supportedDrivers is a list of supported drivers on Darwin.
var supportedDrivers = []string{
VirtualBox,
Parallels,
VMwareFusion,
HyperKit,
VMware,
}
func VBoxManagePath() string {
cmd := "VBoxManage"
if path, err := exec.LookPath(cmd); err == nil {
return path
}
return cmd
}
......@@ -14,13 +14,23 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package cluster
package driver
import (
"os/exec"
)
func detectVBoxManageCmd() string {
// supportedDrivers is a list of supported drivers on Linux.
var supportedDrivers = []string{
VirtualBox,
Parallels,
VMwareFusion,
KVM2,
VMware,
None,
}
func VBoxManagePath() string {
cmd := "VBoxManage"
if path, err := exec.LookPath(cmd); err == nil {
return path
......
......@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package cluster
package driver
import (
"fmt"
......@@ -27,7 +27,15 @@ import (
"golang.org/x/sys/windows/registry"
)
func detectVBoxManageCmd() string {
// supportedDrivers is a list of supported drivers on Windows.
var supportedDrivers = []string{
VirtualBox,
VMwareFusion,
HyperV,
VMware,
}
func VBoxManagePath() string {
cmd := "VBoxManage"
if p := os.Getenv("VBOX_INSTALL_PATH"); p != "" {
if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
......
package driver
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"github.com/blang/semver"
"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/hashicorp/go-getter"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/util"
)
// InstallOrUpdate downloads driver if it is not present, or updates it if there's a newer version
func InstallOrUpdate(name string, directory string, v semver.Version, interactive bool) error {
if name != KVM2 && name != HyperKit {
return nil
}
executable := fmt.Sprintf("docker-machine-driver-%s", name)
path, err := validateDriver(executable, v)
if err != nil {
glog.Warningf("%s: %v", executable, err)
path = filepath.Join(directory, executable)
derr := download(executable, path, v)
if derr != nil {
return derr
}
}
return fixDriverPermissions(name, path, interactive)
}
// fixDriverPermissions fixes the permissions on a driver
func fixDriverPermissions(name string, path string, interactive bool) error {
if name != HyperKit {
return nil
}
// Using the find command for hyperkit is far easier than cross-platform uid checks in Go.
stdout, err := exec.Command("find", path, "-uid", "0", "-perm", "4755").Output()
glog.Infof("stdout: %s", stdout)
if err == nil && strings.TrimSpace(string(stdout)) == path {
glog.Infof("%s looks good", path)
return nil
}
cmds := []*exec.Cmd{
exec.Command("sudo", "chown", "root:wheel", path),
exec.Command("sudo", "chmod", "u+s", path),
}
var example strings.Builder
for _, c := range cmds {
example.WriteString(fmt.Sprintf(" $ %s \n", strings.Join(c.Args, " ")))
}
out.T(out.Permissions, "The '{{.driver}}' driver requires elevated permissions. The following commands will be executed:\n\n{{ .example }}\n", out.V{"driver": name, "example": example.String()})
for _, c := range cmds {
testArgs := append([]string{"-n"}, c.Args[1:]...)
test := exec.Command("sudo", testArgs...)
glog.Infof("testing: %v", test.Args)
if err := test.Run(); err != nil {
glog.Infof("%v may require a password: %v", c.Args, err)
if !interactive {
return fmt.Errorf("%v requires a password, and --interactive=false", c.Args)
}
}
glog.Infof("running: %v", c.Args)
err := c.Run()
if err != nil {
return errors.Wrapf(err, "%v", c.Args)
}
}
return nil
}
// validateDriver validates if a driver appears to be up-to-date and installed properly
func validateDriver(executable string, v semver.Version) (string, error) {
glog.Infof("Validating %s, PATH=%s", executable, os.Getenv("PATH"))
path, err := exec.LookPath(executable)
if err != nil {
return path, err
}
output, err := exec.Command(path, "version").Output()
if err != nil {
return path, err
}
ev := extractVMDriverVersion(string(output))
if len(ev) == 0 {
return path, fmt.Errorf("%s: unable to extract version from %q", executable, output)
}
vmDriverVersion, err := semver.Make(ev)
if err != nil {
return path, errors.Wrap(err, "can't parse driver version")
}
if vmDriverVersion.LT(v) {
return path, fmt.Errorf("%s is version %s, want %s", executable, vmDriverVersion, v)
}
return path, nil
}
func driverWithChecksumURL(name string, v semver.Version) string {
base := fmt.Sprintf("https://github.com/kubernetes/minikube/releases/download/v%s/%s", v, name)
return fmt.Sprintf("%s?checksum=file:%s.sha256", base, base)
}
// download an arbitrary driver
func download(name string, destination string, v semver.Version) error {
out.T(out.FileDownload, "Downloading driver {{.driver}}:", out.V{"driver": name})
os.Remove(destination)
url := driverWithChecksumURL(name, v)
client := &getter.Client{
Src: url,
Dst: destination,
Mode: getter.ClientModeFile,
Options: []getter.ClientOption{getter.WithProgress(util.DefaultProgressBar)},
}
glog.Infof("Downloading: %+v", client)
if err := client.Get(); err != nil {
return errors.Wrapf(err, "download failed: %s", url)
}
// Give downloaded drivers a baseline decent file permission
return os.Chmod(destination, 0755)
}
// extractVMDriverVersion extracts the driver version.
// KVM and Hyperkit drivers support the 'version' command, that display the information as:
// version: vX.X.X
// commit: XXXX
// This method returns the version 'vX.X.X' or empty if the version isn't found.
func extractVMDriverVersion(s string) string {
versionRegex := regexp.MustCompile(`version:(.*)`)
matches := versionRegex.FindStringSubmatch(s)
if len(matches) != 2 {
return ""
}
v := strings.TrimSpace(matches[1])
return strings.TrimPrefix(v, "v")
}
......@@ -41,7 +41,7 @@ import (
"github.com/docker/machine/libmachine/version"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/out"
......@@ -80,27 +80,27 @@ type LocalClient struct {
}
// NewHost creates a new Host
func (api *LocalClient) NewHost(driverName string, rawDriver []byte) (*host.Host, error) {
func (api *LocalClient) NewHost(drvName string, rawDriver []byte) (*host.Host, error) {
var def registry.DriverDef
var err error
if def, err = registry.Driver(driverName); err != nil {
if def, err = registry.Driver(drvName); err != nil {
return nil, err
} else if !def.Builtin || def.DriverCreator == nil {
return api.legacyClient.NewHost(driverName, rawDriver)
return api.legacyClient.NewHost(drvName, rawDriver)
}
driver := def.DriverCreator()
d := def.DriverCreator()
err = json.Unmarshal(rawDriver, driver)
err = json.Unmarshal(rawDriver, d)
if err != nil {
return nil, errors.Wrapf(err, "Error getting driver %s", string(rawDriver))
}
return &host.Host{
ConfigVersion: version.ConfigVersion,
Name: driver.GetMachineName(),
Driver: driver,
DriverName: driver.DriverName(),
Name: d.GetMachineName(),
Driver: d,
DriverName: d.DriverName(),
HostOptions: &host.Options{
AuthOptions: &auth.Options{
CertDir: api.certsDir,
......@@ -148,10 +148,10 @@ func (api *LocalClient) Close() error {
// CommandRunner returns best available command runner for this host
func CommandRunner(h *host.Host) (command.Runner, error) {
if h.DriverName == constants.DriverMock {
if h.DriverName == driver.Mock {
return &command.FakeCommandRunner{}, nil
}
if h.DriverName == constants.DriverNone {
if driver.BareMetal(h.Driver.DriverName()) {
return &command.ExecRunner{}, nil
}
client, err := sshutil.NewSSHClient(h.Driver)
......@@ -194,7 +194,7 @@ func (api *LocalClient) Create(h *host.Host) error {
{
"waiting",
func() error {
if h.Driver.DriverName() == constants.DriverNone {
if driver.BareMetal(h.Driver.DriverName()) {
return nil
}
return mcnutils.WaitFor(drivers.MachineInState(h.Driver, state.Running))
......@@ -203,7 +203,7 @@ func (api *LocalClient) Create(h *host.Host) error {
{
"provisioning",
func() error {
if h.Driver.DriverName() == constants.DriverNone {
if driver.BareMetal(h.Driver.DriverName()) {
return nil
}
pv := provision.NewBuildrootProvisioner(h.Driver)
......@@ -270,11 +270,11 @@ func (cg *CertGenerator) ValidateCertificate(addr string, authOptions *auth.Opti
return true, nil
}
func registerDriver(driverName string) {
def, err := registry.Driver(driverName)
func registerDriver(drvName string) {
def, err := registry.Driver(drvName)
if err != nil {
if err == registry.ErrDriverNotFound {
exit.UsageT("unsupported driver: {{.name}}", out.V{"name": driverName})
exit.UsageT("unsupported driver: {{.name}}", out.V{"name": drvName})
}
exit.WithError("error getting driver", err)
}
......
......@@ -77,12 +77,12 @@ func TestLocalClientNewHost(t *testing.T) {
}{
{
description: "host vbox correct",
driver: constants.DriverVirtualbox,
driver: constants.VirtualBox,
rawDriver: []byte(vboxConfig),
},
{
description: "host vbox incorrect",
driver: constants.DriverVirtualbox,
driver: constants.VirtualBox,
rawDriver: []byte("?"),
err: true,
},
......@@ -138,7 +138,7 @@ func TestRunDriver(t *testing.T) {
defer os.RemoveAll(tempDir)
os.Setenv(localbinary.PluginEnvKey, localbinary.PluginEnvVal)
os.Setenv(localbinary.PluginEnvDriverName, constants.DriverVirtualbox)
os.Setenv(localbinary.PluginEnvDriverName, constants.VirtualBox)
// Capture stdout and reset it later.
old := os.Stdout
......
......@@ -32,7 +32,7 @@ import (
func init() {
if err := registry.Register(registry.DriverDef{
Name: constants.DriverHyperkit,
Name: driver.HyperKit,
Builtin: false,
ConfigCreator: createHyperkitHost,
}); err != nil {
......
......@@ -29,7 +29,7 @@ import (
func init() {
registry.Register(registry.DriverDef{
Name: constants.DriverHyperv,
Name: driver.HyperV,
Builtin: true,
ConfigCreator: createHypervHost,
DriverCreator: func() drivers.Driver {
......
package drvs
import (
// Register all of the drvs we know of
_ "k8s.io/minikube/pkg/minikube/registry/drvs/hyperkit"
_ "k8s.io/minikube/pkg/minikube/registry/drvs/hyperv"
_ "k8s.io/minikube/pkg/minikube/registry/drvs/kvm2"
_ "k8s.io/minikube/pkg/minikube/registry/drvs/none"
_ "k8s.io/minikube/pkg/minikube/registry/drvs/parallels"
_ "k8s.io/minikube/pkg/minikube/registry/drvs/virtualbox"
_ "k8s.io/minikube/pkg/minikube/registry/drvs/vmware"
_ "k8s.io/minikube/pkg/minikube/registry/drvs/vmwarefusion"
)
......@@ -31,7 +31,7 @@ import (
func init() {
if err := registry.Register(registry.DriverDef{
Name: constants.DriverKvm2,
Name: constants.KVM2,
Builtin: false,
ConfigCreator: createKVM2Host,
}); err != nil {
......
......@@ -30,7 +30,7 @@ import (
func init() {
if err := registry.Register(registry.DriverDef{
Name: constants.DriverNone,
Name: constants.None,
Builtin: true,
ConfigCreator: createNoneHost,
DriverCreator: func() drivers.Driver {
......@@ -49,13 +49,4 @@ func createNoneHost(config cfg.MachineConfig) interface{} {
ContainerRuntime: config.ContainerRuntime,
})
}
// AutoOptions returns suggested extra options based on the current config
func AutoOptions() string {
// for more info see: https://github.com/kubernetes/minikube/issues/3511
f := "/run/systemd/resolve/resolv.conf"
if _, err := os.Stat(f); err != nil {
return ""
}
return fmt.Sprintf("kubelet.resolv-conf=%s", f)
}
0
\ No newline at end of file
......@@ -31,7 +31,7 @@ import (
func init() {
err := registry.Register(registry.DriverDef{
Name: constants.DriverParallels,
Name: constants.Parallels,
Builtin: true,
ConfigCreator: createParallelsHost,
DriverCreator: func() drivers.Driver {
......
......@@ -31,7 +31,7 @@ const defaultVirtualboxNicType = "virtio"
func init() {
err := registry.Register(registry.DriverDef{
Name: constants.DriverVirtualbox,
Name: constants.VirtualBox,
Builtin: true,
ConfigCreator: createVirtualboxHost,
DriverCreator: func() drivers.Driver {
......
......@@ -28,7 +28,7 @@ import (
func init() {
err := registry.Register(registry.DriverDef{
Name: constants.DriverVmware,
Name: constants.VMware,
Builtin: false,
ConfigCreator: createVMwareHost,
})
......
......@@ -31,7 +31,7 @@ import (
func init() {
if err := registry.Register(registry.DriverDef{
Name: constants.DriverVmwareFusion,
Name: constants.VMwareFusion,
Builtin: true,
ConfigCreator: createVMwareFusionHost,
DriverCreator: func() drivers.Driver {
......
......@@ -94,13 +94,13 @@ func TestRegistry2(t *testing.T) {
t.Skipf("error not expect but got: %v", err)
}
t.Run("Driver", func(t *testing.T) {
driverName := "foo"
driver, err := registry.Driver(driverName)
name := "foo"
d, err := registry.Driver(name)
if err != nil {
t.Fatalf("expect nil for registering foo driver, but got: %v", err)
}
if driver.Name != driverName {
t.Fatalf("expect registry.Driver(%s) returns registered driver, but got: %s", driverName, driver.Name)
if d.Name != name {
t.Fatalf("expect registry.Driver(%s) returns registered driver, but got: %s", name, d.Name)
}
})
t.Run("NotExistingDriver", func(t *testing.T) {
......
......@@ -67,14 +67,14 @@ func (api *MockAPI) Close() error {
}
// NewHost creates a new host.Host instance.
func (api *MockAPI) NewHost(driverName string, rawDriver []byte) (*host.Host, error) {
func (api *MockAPI) NewHost(drvName string, rawDriver []byte) (*host.Host, error) {
var driver MockDriver
if err := json.Unmarshal(rawDriver, &driver); err != nil {
return nil, errors.Wrap(err, "error unmarshalling json")
}
h := &host.Host{
DriverName: driverName,
DriverName: drvName,
RawDriver: rawDriver,
Driver: &MockDriver{},
Name: fmt.Sprintf("mock-machine-%.8f", rand.Float64()),
......
......@@ -146,5 +146,5 @@ func (driver *MockDriver) Stop() error {
// DriverName returns the name of the driver
func (driver *MockDriver) DriverName() string {
driver.Logf("MockDriver.Name")
return constants.DriverMock
return driver.Mock
}
......@@ -29,7 +29,7 @@ import (
"github.com/pkg/errors"
typed_core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
)
// tunnel represents the basic API for a tunnel: periodically the state of the tunnel
......@@ -150,7 +150,7 @@ func setupRoute(t *tunnel, h *host.Host) {
return
}
if h.DriverName == constants.DriverHyperkit {
if h.DriverName == driver.HyperKit {
// the virtio-net interface acts up with ip tunnels :(
setupBridge(t)
if t.status.RouteError != nil {
......
......@@ -89,8 +89,8 @@ func escapeSystemdDirectives(engineConfigContext *provision.EngineConfigContext)
func (p *BuildrootProvisioner) GenerateDockerOptions(dockerPort int) (*provision.DockerOptions, error) {
var engineCfg bytes.Buffer
driverNameLabel := fmt.Sprintf("provider=%s", p.Driver.DriverName())
p.EngineOptions.Labels = append(p.EngineOptions.Labels, driverNameLabel)
drvLabel := fmt.Sprintf("provider=%s", p.Driver.DriverName())
p.EngineOptions.Labels = append(p.EngineOptions.Labels, drvLabel)
noPivot := true
// Using pivot_root is not supported on fstype rootfs
......
......@@ -84,7 +84,7 @@ func TestKVMDriverInstallOrUpdate(t *testing.T) {
t.Fatalf("Expected new semver. test: %v, got: %v", tc.name, err)
}
err = drivers.InstallOrUpdate("kvm2", dir, newerVersion, true)
err = driver.InstallOrUpdate("kvm2", dir, newerVersion, true)
if err != nil {
t.Fatalf("Failed to update driver to %v. test: %s, got: %v", newerVersion, tc.name, err)
}
......@@ -147,7 +147,7 @@ func TestHyperKitDriverInstallOrUpdate(t *testing.T) {
t.Fatalf("Expected new semver. test: %v, got: %v", tc.name, err)
}
err = drivers.InstallOrUpdate("hyperkit", dir, newerVersion, true)
err = driver.InstallOrUpdate("hyperkit", dir, newerVersion, true)
if err != nil {
t.Fatalf("Failed to update driver to %v. test: %s, got: %v", newerVersion, tc.name, err)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册