From 264072b59046b20f25b48732501b88f3d545615d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Wed, 10 Jul 2019 21:44:26 +0200 Subject: [PATCH 01/23] Add minikube support for the "generic" VM driver This driver connects to an already existing virtual machine, using the provided IP address and SSH user/key/port parameters. On this machine, libmachine will provision the docker daemon and minikube will bootstrap the kubernetes cluster (as usual). --- cmd/minikube/cmd/start_flags.go | 15 +++++ pkg/minikube/cluster/ip.go | 6 ++ pkg/minikube/config/types.go | 4 ++ pkg/minikube/driver/driver.go | 2 + pkg/minikube/registry/drvs/generic/generic.go | 62 +++++++++++++++++++ pkg/minikube/registry/drvs/init.go | 1 + site/content/en/docs/commands/start.md | 4 ++ 7 files changed, 94 insertions(+) create mode 100644 pkg/minikube/registry/drvs/generic/generic.go diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 922248bae84c..d32a7a6321e3 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -22,6 +22,7 @@ import ( "time" "github.com/blang/semver" + "github.com/docker/machine/libmachine/drivers" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -108,6 +109,10 @@ const ( kicBaseImage = "base-image" startOutput = "output" ports = "ports" + genericIPAddress = "generic-ip-address" + genericSSHUser = "generic-ssh-user" + genericSSHKey = "generic-ssh-key" + genericSSHPort = "generic-ssh-port" ) // initMinikubeFlags includes commandline flags for minikube. @@ -212,6 +217,12 @@ func initNetworkingFlags() { startCmd.Flags().String(serviceCIDR, constants.DefaultServiceCIDR, "The CIDR to be used for service cluster IPs.") startCmd.Flags().StringArrayVar(&config.DockerEnv, "docker-env", nil, "Environment variables to pass to the Docker daemon. (format: key=value)") startCmd.Flags().StringArrayVar(&config.DockerOpt, "docker-opt", nil, "Specify arbitrary flags to pass to the Docker daemon. (format: key=value)") + + // generic + startCmd.Flags().String(genericIPAddress, "", "IP address (generic)") + startCmd.Flags().String(genericSSHUser, drivers.DefaultSSHUser, "SSH user (generic)") + startCmd.Flags().String(genericSSHKey, "", "SSH key (generic)") + startCmd.Flags().Int(genericSSHPort, drivers.DefaultSSHPort, "SSH port (generic)") } // ClusterFlagValue returns the current cluster name based on flags @@ -321,6 +332,10 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k NatNicType: viper.GetString(natNicType), StartHostTimeout: viper.GetDuration(waitTimeout), ExposedPorts: viper.GetStringSlice(ports), + GenericIPAddress: viper.GetString(genericIPAddress), + GenericSSHUser: viper.GetString(genericSSHUser), + GenericSSHKey: viper.GetString(genericSSHKey), + GenericSSHPort: viper.GetInt(genericSSHPort), KubernetesConfig: config.KubernetesConfig{ KubernetesVersion: k8sVersion, ClusterName: ClusterFlagValue(), diff --git a/pkg/minikube/cluster/ip.go b/pkg/minikube/cluster/ip.go index 891705e60c73..6a3522e67a61 100644 --- a/pkg/minikube/cluster/ip.go +++ b/pkg/minikube/cluster/ip.go @@ -40,6 +40,12 @@ func HostIP(host *host.Host, clusterName string) (net.IP, error) { return oci.RoutableHostIPFromInside(oci.Docker, clusterName, host.Name) case driver.Podman: return oci.RoutableHostIPFromInside(oci.Podman, clusterName, host.Name) + case driver.Generic: + ip, err := host.Driver.GetIP() + if err != nil { + return []byte{}, errors.Wrap(err, "Error getting VM/Host IP address") + } + return net.ParseIP(ip), nil case driver.KVM2: return net.ParseIP("192.168.39.1"), nil case driver.HyperV: diff --git a/pkg/minikube/config/types.go b/pkg/minikube/config/types.go index e56086b96007..4b4631159fa6 100644 --- a/pkg/minikube/config/types.go +++ b/pkg/minikube/config/types.go @@ -66,6 +66,10 @@ type ClusterConfig struct { HostDNSResolver bool // Only used by virtualbox HostOnlyNicType string // Only used by virtualbox NatNicType string // Only used by virtualbox + GenericIPAddress string // Only used by generic + GenericSSHUser string // Only used by generic + GenericSSHKey string // Only used by generic + GenericSSHPort int // Only used by generic KubernetesConfig KubernetesConfig Nodes []Node Addons map[string]bool diff --git a/pkg/minikube/driver/driver.go b/pkg/minikube/driver/driver.go index 8d876f1c8302..ce2333594ae4 100644 --- a/pkg/minikube/driver/driver.go +++ b/pkg/minikube/driver/driver.go @@ -39,6 +39,8 @@ const ( Mock = "mock" // None driver None = "none" + // Generic driver + Generic = "generic" // KVM2 driver KVM2 = "kvm2" // VirtualBox driver diff --git a/pkg/minikube/registry/drvs/generic/generic.go b/pkg/minikube/registry/drvs/generic/generic.go new file mode 100644 index 000000000000..93afecc13355 --- /dev/null +++ b/pkg/minikube/registry/drvs/generic/generic.go @@ -0,0 +1,62 @@ +/* +Copyright 2019 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 generic + +import ( + "fmt" + + "github.com/docker/machine/drivers/generic" + "github.com/docker/machine/libmachine/drivers" + "github.com/pkg/errors" + + "k8s.io/minikube/pkg/minikube/config" + "k8s.io/minikube/pkg/minikube/driver" + "k8s.io/minikube/pkg/minikube/localpath" + "k8s.io/minikube/pkg/minikube/registry" +) + +func init() { + err := registry.Register(registry.DriverDef{ + Name: driver.Generic, + Config: configure, + Status: status, + Priority: registry.Fallback, + Init: func() drivers.Driver { return generic.NewDriver("", "") }, + }) + if err != nil { + panic(fmt.Sprintf("unable to register: %v", err)) + } +} + +func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) { + d := generic.NewDriver(driver.MachineName(cc, n), localpath.MiniPath()) + + if cc.GenericIPAddress == "" { + return nil, errors.Errorf("please provide an IP address") + } + + d.(*generic.Driver).IPAddress = cc.GenericIPAddress + d.(*generic.Driver).SSHUser = cc.GenericSSHUser + d.(*generic.Driver).SSHKey = cc.GenericSSHKey + d.(*generic.Driver).SSHPort = cc.GenericSSHPort + + return d, nil +} + +func status() registry.State { + return registry.State{Installed: true, Healthy: true} +} diff --git a/pkg/minikube/registry/drvs/init.go b/pkg/minikube/registry/drvs/init.go index bca12775c3ff..2bd36761e79c 100644 --- a/pkg/minikube/registry/drvs/init.go +++ b/pkg/minikube/registry/drvs/init.go @@ -19,6 +19,7 @@ package drvs import ( // Register all of the drvs we know of _ "k8s.io/minikube/pkg/minikube/registry/drvs/docker" + _ "k8s.io/minikube/pkg/minikube/registry/drvs/generic" _ "k8s.io/minikube/pkg/minikube/registry/drvs/hyperkit" _ "k8s.io/minikube/pkg/minikube/registry/drvs/hyperv" _ "k8s.io/minikube/pkg/minikube/registry/drvs/kvm2" diff --git a/site/content/en/docs/commands/start.md b/site/content/en/docs/commands/start.md index 43c6c5108135..48ebbca90da8 100644 --- a/site/content/en/docs/commands/start.md +++ b/site/content/en/docs/commands/start.md @@ -51,6 +51,10 @@ minikube start [flags] --feature-gates string A set of key=value pairs that describe feature gates for alpha/experimental features. --force Force minikube to perform possibly dangerous operations --force-systemd If set, force the container runtime to use sytemd as cgroup manager. Currently available for docker and crio. Defaults to false. + --generic-ip-address string IP address (generic) + --generic-ssh-key string SSH key (generic) + --generic-ssh-port int SSH port (generic) (default 22) + --generic-ssh-user string SSH user (generic) (default "root") -h, --help help for start --host-dns-resolver Enable host resolver for NAT DNS requests (virtualbox driver only) (default true) --host-only-cidr string The CIDR to be used for the minikube VM (virtualbox driver only) (default "192.168.99.1/24") From 63e6c66413ded7a816a5931c47ec7fcecfaa9607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 14 Jul 2019 16:03:28 +0200 Subject: [PATCH 02/23] Don't download ISO for the generic VM driver --- cmd/minikube/cmd/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 909b37d7340e..11bc40764784 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -299,7 +299,7 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing * os.Exit(0) } - if driver.IsVM(driverName) { + if driver.IsVM(driverName) && driverName != driver.Generic { url, err := download.ISO(viper.GetStringSlice(isoURL), cmd.Flags().Changed(isoURL)) if err != nil { return node.Starter{}, errors.Wrap(err, "Failed to cache ISO") From d8712cdec42e91ae050cbffbad7a8ffffb5a8506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 14 Jul 2019 16:34:24 +0200 Subject: [PATCH 03/23] Generic driver does not add user to docker group --- pkg/minikube/machine/fix.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/minikube/machine/fix.go b/pkg/minikube/machine/fix.go index 1f83f96583eb..13ca5222600c 100644 --- a/pkg/minikube/machine/fix.go +++ b/pkg/minikube/machine/fix.go @@ -95,6 +95,12 @@ func fixHost(api libmachine.API, cc *config.ClusterConfig, n *config.Node) (*hos return h, nil } + if h.Driver.DriverName() == driver.Generic { + if _, err := h.RunSSHCommand(fmt.Sprintf("sudo usermod -aG docker %s", h.Driver.GetSSHUsername())); err != nil { + return h, errors.Wrap(err, "usermod") + } + } + return h, ensureSyncedGuestClock(h, driverName) } From 19918ca66b80e71854a1b9372e30aa30481839f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 14 Jul 2019 19:11:48 +0200 Subject: [PATCH 04/23] Try to uninstall kubernetes on delete, for generic --- cmd/minikube/cmd/delete.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index a4c2b08ec8d3..bfd0ffba9faf 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -309,7 +309,7 @@ func deleteProfile(profile *config.Profile) error { return DeletionError{Err: delErr, Errtype: MissingProfile} } - if err == nil && driver.BareMetal(cc.Driver) { + if err == nil && (driver.BareMetal(cc.Driver) || cc.Driver == driver.Generic) { if err := uninstallKubernetes(api, *cc, cc.Nodes[0], viper.GetString(cmdcfg.Bootstrapper)); err != nil { deletionError, ok := err.(DeletionError) if ok { From d53a0d373726843d954bd7bd76dfd7e45eecbacb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Mon, 15 Jul 2019 16:14:58 +0200 Subject: [PATCH 05/23] Don't try to start/stop drivers without VMs It is not supported anyway, and just throws errors. There is no use to restart or to retry, just give up. This should never be a problem with "none", though. That always return running, while generic tests ssh. --- pkg/minikube/machine/fix.go | 42 +++++++++++++++++++++--------------- pkg/minikube/machine/stop.go | 16 ++++++++------ 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/pkg/minikube/machine/fix.go b/pkg/minikube/machine/fix.go index 13ca5222600c..a35c3eeaf194 100644 --- a/pkg/minikube/machine/fix.go +++ b/pkg/minikube/machine/fix.go @@ -135,26 +135,34 @@ func recreateIfNeeded(api libmachine.API, cc *config.ClusterConfig, n *config.No } } - if serr != constants.ErrMachineMissing { - klog.Warningf("unexpected machine state, will restart: %v", serr) - } + if h.Driver.DriverName() != driver.Generic { + if serr != constants.ErrMachineMissing { + klog.Warningf("unexpected machine state, will restart: %v", serr) + } - if s == state.Running { - if !recreated { - out.T(style.Running, `Updating the running {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": machineName, "machine_type": machineType}) + if s == state.Running { + if !recreated { + out.T(style.Running, `Updating the running {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": machineName, "machine_type": machineType}) + } + return h, nil } - return h, nil - } - if !recreated { - out.T(style.Restarting, `Restarting existing {{.driver_name}} {{.machine_type}} for "{{.cluster}}" ...`, out.V{"driver_name": cc.Driver, "cluster": machineName, "machine_type": machineType}) - } - if err := h.Driver.Start(); err != nil { - MaybeDisplayAdvice(err, h.DriverName) - return h, errors.Wrap(err, "driver start") - } - if err := saveHost(api, h, cc, n); err != nil { - return h, err + if !recreated { + out.T(style.Restarting, `Restarting existing {{.driver_name}} {{.machine_type}} for "{{.cluster}}" ...`, out.V{"driver_name": cc.Driver, "cluster": machineName, "machine_type": machineType}) + } + if err := h.Driver.Start(); err != nil { + MaybeDisplayAdvice(err, h.DriverName) + return h, errors.Wrap(err, "driver start") + } + if err := saveHost(api, h, cc, n); err != nil { + return h, err + } + } else { + if s == state.Running { + out.T(style.Running, `Using the {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType}) + } else { + return h, errors.Errorf("not running") + } } return h, nil diff --git a/pkg/minikube/machine/stop.go b/pkg/minikube/machine/stop.go index 4309a8cdae04..02ffd0f3b005 100644 --- a/pkg/minikube/machine/stop.go +++ b/pkg/minikube/machine/stop.go @@ -55,14 +55,16 @@ func stop(h *host.Host) error { } } - if err := h.Stop(); err != nil { - klog.Infof("stop err: %v", err) - st, ok := err.(mcnerror.ErrHostAlreadyInState) - if ok && st.State == state.Stopped { - klog.Infof("host is already stopped") - return nil + if h.DriverName != driver.Generic { + if err := h.Stop(); err != nil { + klog.Infof("stop err: %v", err) + st, ok := err.(mcnerror.ErrHostAlreadyInState) + if ok && st.State == state.Stopped { + klog.Infof("host is already stopped") + return nil + } + return &retry.RetriableError{Err: errors.Wrap(err, "stop")} } - return &retry.RetriableError{Err: errors.Wrap(err, "stop")} } klog.Infof("duration metric: stop complete within %s", time.Since(start)) return nil From 71e9dc1f5c2f92f28bd4295aa6a7ebda5a3430e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Wed, 28 Oct 2020 19:45:26 +0100 Subject: [PATCH 06/23] Flip the driver logic to make code easier to read --- pkg/minikube/machine/fix.go | 47 ++++++++++++++++++------------------ pkg/minikube/machine/stop.go | 20 ++++++++------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/pkg/minikube/machine/fix.go b/pkg/minikube/machine/fix.go index a35c3eeaf194..fa8167b30e5f 100644 --- a/pkg/minikube/machine/fix.go +++ b/pkg/minikube/machine/fix.go @@ -135,34 +135,35 @@ func recreateIfNeeded(api libmachine.API, cc *config.ClusterConfig, n *config.No } } - if h.Driver.DriverName() != driver.Generic { - if serr != constants.ErrMachineMissing { - klog.Warningf("unexpected machine state, will restart: %v", serr) - } - - if s == state.Running { - if !recreated { - out.T(style.Running, `Updating the running {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": machineName, "machine_type": machineType}) - } - return h, nil - } - - if !recreated { - out.T(style.Restarting, `Restarting existing {{.driver_name}} {{.machine_type}} for "{{.cluster}}" ...`, out.V{"driver_name": cc.Driver, "cluster": machineName, "machine_type": machineType}) - } - if err := h.Driver.Start(); err != nil { - MaybeDisplayAdvice(err, h.DriverName) - return h, errors.Wrap(err, "driver start") - } - if err := saveHost(api, h, cc, n); err != nil { - return h, err - } - } else { + if h.Driver.DriverName() == driver.Generic { if s == state.Running { out.T(style.Running, `Using the {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType}) } else { return h, errors.Errorf("not running") } + return h, nil + } + + if serr != constants.ErrMachineMissing { + klog.Warningf("unexpected machine state, will restart: %v", serr) + } + + if s == state.Running { + if !recreated { + out.T(style.Running, `Updating the running {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": machineName, "machine_type": machineType}) + } + return h, nil + } + + if !recreated { + out.T(style.Restarting, `Restarting existing {{.driver_name}} {{.machine_type}} for "{{.cluster}}" ...`, out.V{"driver_name": cc.Driver, "cluster": machineName, "machine_type": machineType}) + } + if err := h.Driver.Start(); err != nil { + MaybeDisplayAdvice(err, h.DriverName) + return h, errors.Wrap(err, "driver start") + } + if err := saveHost(api, h, cc, n); err != nil { + return h, err } return h, nil diff --git a/pkg/minikube/machine/stop.go b/pkg/minikube/machine/stop.go index 02ffd0f3b005..213fb6a1fcdb 100644 --- a/pkg/minikube/machine/stop.go +++ b/pkg/minikube/machine/stop.go @@ -55,16 +55,18 @@ func stop(h *host.Host) error { } } - if h.DriverName != driver.Generic { - if err := h.Stop(); err != nil { - klog.Infof("stop err: %v", err) - st, ok := err.(mcnerror.ErrHostAlreadyInState) - if ok && st.State == state.Stopped { - klog.Infof("host is already stopped") - return nil - } - return &retry.RetriableError{Err: errors.Wrap(err, "stop")} + if h.DriverName == driver.Generic { + return nil + } + + if err := h.Stop(); err != nil { + klog.Infof("stop err: %v", err) + st, ok := err.(mcnerror.ErrHostAlreadyInState) + if ok && st.State == state.Stopped { + klog.Infof("host is already stopped") + return nil } + return &retry.RetriableError{Err: errors.Wrap(err, "stop")} } klog.Infof("duration metric: stop complete within %s", time.Since(start)) return nil From d35d00c413f0ea75f529ef7611e31012dbd13025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Wed, 28 Oct 2020 22:08:45 +0100 Subject: [PATCH 07/23] Allow actually using the generic driver All drivers *must* be in "supportedDrivers" Delete Podman on Darwin (Mac), not available --- pkg/minikube/driver/driver_darwin.go | 2 +- pkg/minikube/driver/driver_linux.go | 1 + pkg/minikube/driver/driver_windows.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/minikube/driver/driver_darwin.go b/pkg/minikube/driver/driver_darwin.go index f951177677c2..24a6e56d6c3d 100644 --- a/pkg/minikube/driver/driver_darwin.go +++ b/pkg/minikube/driver/driver_darwin.go @@ -26,7 +26,7 @@ var supportedDrivers = []string{ HyperKit, VMware, Docker, - Podman, + Generic, } func VBoxManagePath() string { diff --git a/pkg/minikube/driver/driver_linux.go b/pkg/minikube/driver/driver_linux.go index 16e7b5e706de..05784f946e08 100644 --- a/pkg/minikube/driver/driver_linux.go +++ b/pkg/minikube/driver/driver_linux.go @@ -29,6 +29,7 @@ var supportedDrivers = []string{ None, Docker, Podman, + Generic, } // VBoxManagePath returns the path to the VBoxManage command diff --git a/pkg/minikube/driver/driver_windows.go b/pkg/minikube/driver/driver_windows.go index 80ff83b825b2..8a2f5a6a2a5f 100644 --- a/pkg/minikube/driver/driver_windows.go +++ b/pkg/minikube/driver/driver_windows.go @@ -33,6 +33,7 @@ var supportedDrivers = []string{ HyperV, VMware, Docker, + Generic, } // TODO: medyagh add same check for kic docker From 55e8e332dbcf8fd2928831a853b45727a1408302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Wed, 28 Oct 2020 22:23:29 +0100 Subject: [PATCH 08/23] Call DetectProvisioner for the generic driver It was failing to install the "docker" package Since the provisioning was defaulting to ISO --- pkg/minikube/machine/machine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/machine/machine.go b/pkg/minikube/machine/machine.go index d382041f6a04..cf27e81655d6 100644 --- a/pkg/minikube/machine/machine.go +++ b/pkg/minikube/machine/machine.go @@ -104,7 +104,7 @@ func fastDetectProvisioner(h *host.Host) (libprovision.Provisioner, error) { switch { case driver.IsKIC(d): return provision.NewUbuntuProvisioner(h.Driver), nil - case driver.BareMetal(d): + case driver.BareMetal(d), d == driver.Generic: return libprovision.DetectProvisioner(h.Driver) default: return provision.NewBuildrootProvisioner(h.Driver), nil From 41979352b927b85e12574cb3bbbf4917ef1a06a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Thu, 29 Oct 2020 07:23:51 +0100 Subject: [PATCH 09/23] Show remote host info and proper progress --- cmd/minikube/cmd/start.go | 2 +- pkg/minikube/machine/info.go | 43 +++++++++++++++++++++++++-- pkg/minikube/machine/start.go | 24 +++++++++++++-- pkg/minikube/out/register/register.go | 2 ++ pkg/minikube/style/style.go | 1 + pkg/minikube/style/style_enum.go | 1 + pkg/util/utils.go | 42 ++++++++++++++++++++++++++ 7 files changed, 109 insertions(+), 6 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 11bc40764784..bebac130b607 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -812,7 +812,7 @@ func validateUser(drvName string) { // memoryLimits returns the amount of memory allocated to the system and hypervisor, the return value is in MiB func memoryLimits(drvName string) (int, int, error) { - info, cpuErr, memErr, diskErr := machine.CachedHostInfo() + info, cpuErr, memErr, diskErr := machine.LocalHostInfo() if cpuErr != nil { klog.Warningf("could not get system cpu info while verifying memory limits, which might be okay: %v", cpuErr) } diff --git a/pkg/minikube/machine/info.go b/pkg/minikube/machine/info.go index 9b39635d52c5..40c5ab47f7e5 100644 --- a/pkg/minikube/machine/info.go +++ b/pkg/minikube/machine/info.go @@ -19,6 +19,8 @@ package machine import ( "io/ioutil" "os/exec" + "strconv" + "strings" "github.com/docker/machine/libmachine/provision" "github.com/shirou/gopsutil/cpu" @@ -39,8 +41,8 @@ type HostInfo struct { DiskSize int64 } -// CachedHostInfo returns system information such as memory,CPU, DiskSize -func CachedHostInfo() (*HostInfo, error, error, error) { +// LocalHostInfo returns system information such as memory,CPU, DiskSize +func LocalHostInfo() (*HostInfo, error, error, error) { var cpuErr, memErr, diskErr error i, cpuErr := cachedCPUInfo() if cpuErr != nil { @@ -63,6 +65,43 @@ func CachedHostInfo() (*HostInfo, error, error, error) { return &info, cpuErr, memErr, diskErr } +// RemoteHostInfo returns system information such as memory,CPU, DiskSize +func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) { + rr, cpuErr := r.RunCmd(exec.Command("nproc")) + if cpuErr != nil { + klog.Warningf("Unable to get CPU info: %v", cpuErr) + } + nproc := rr.Stdout.String() + ncpus, err := strconv.Atoi(strings.TrimSpace(nproc)) + if err != nil { + klog.Warningf("Failed to parse CPU info: %v", err) + } + rr, memErr := r.RunCmd(exec.Command("free", "-m")) + if memErr != nil { + klog.Warningf("Unable to get mem info: %v", memErr) + } + free := rr.Stdout.String() + memory, err := util.ParseMemFree(free) + if err != nil { + klog.Warningf("Unable to parse mem info: %v", err) + } + rr, diskErr := r.RunCmd(exec.Command("df", "-m")) + if diskErr != nil { + klog.Warningf("Unable to get disk info: %v", diskErr) + } + df := rr.Stdout.String() + disksize, err := util.ParseDiskFree(df) + if err != nil { + klog.Warningf("Unable to parse disk info: %v", err) + } + + var info HostInfo + info.CPUs = ncpus + info.Memory = memory + info.DiskSize = disksize + return &info, cpuErr, memErr, diskErr +} + // showLocalOsRelease shows systemd information about the current linux distribution, on the local host func showLocalOsRelease() { osReleaseOut, err := ioutil.ReadFile("/etc/os-release") diff --git a/pkg/minikube/machine/start.go b/pkg/minikube/machine/start.go index 16034e6e0bb8..cb1d74a1844c 100644 --- a/pkg/minikube/machine/start.go +++ b/pkg/minikube/machine/start.go @@ -136,7 +136,9 @@ func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) ( See https://minikube.sigs.k8s.io/docs/reference/drivers/vmware/ for more information. To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`) } - showHostInfo(*cfg) + if cfg.Driver != driver.Generic { + showHostInfo(nil, *cfg) + } def := registry.Driver(cfg.Driver) if def.Empty() { return nil, fmt.Errorf("unsupported/missing driver: %s", cfg.Driver) @@ -170,6 +172,9 @@ func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) ( return nil, errors.Wrap(err, "creating host") } klog.Infof("duration metric: libmachine.API.Create for %q took %s", cfg.Name, time.Since(cstart)) + if cfg.Driver == driver.Generic { + showHostInfo(h, *cfg) + } if err := postStartSetup(h, *cfg); err != nil { return h, errors.Wrap(err, "post-start") @@ -321,16 +326,29 @@ func acquireMachinesLock(name string, drv string) (mutex.Releaser, error) { } // showHostInfo shows host information -func showHostInfo(cfg config.ClusterConfig) { +func showHostInfo(h *host.Host, cfg config.ClusterConfig) { machineType := driver.MachineType(cfg.Driver) if driver.BareMetal(cfg.Driver) { - info, cpuErr, memErr, DiskErr := CachedHostInfo() + info, cpuErr, memErr, DiskErr := LocalHostInfo() if cpuErr == nil && memErr == nil && DiskErr == nil { register.Reg.SetStep(register.RunningLocalhost) out.T(style.StartingNone, "Running on localhost (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize}) } return } + if cfg.Driver == driver.Generic { + r, err := CommandRunner(h) + if err != nil { + klog.Warningf("error getting command runner: %v", err) + return + } + info, cpuErr, memErr, DiskErr := RemoteHostInfo(r) + if cpuErr == nil && memErr == nil && DiskErr == nil { + register.Reg.SetStep(register.RunningRemotely) + out.T(style.StartingGeneric, "Running remotely (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize}) + } + return + } if driver.IsKIC(cfg.Driver) { // TODO:medyagh add free disk space on docker machine register.Reg.SetStep(register.CreatingContainer) out.T(style.StartingVM, "Creating {{.driver_name}} {{.machine_type}} (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB) ...", out.V{"driver_name": cfg.Driver, "number_of_cpus": cfg.CPUs, "memory_size": cfg.Memory, "machine_type": machineType}) diff --git a/pkg/minikube/out/register/register.go b/pkg/minikube/out/register/register.go index f5e316c1cbfb..1cc7c7de51c5 100644 --- a/pkg/minikube/out/register/register.go +++ b/pkg/minikube/out/register/register.go @@ -29,6 +29,7 @@ const ( DownloadingArtifacts RegStep = "Downloading Artifacts" StartingNode RegStep = "Starting Node" RunningLocalhost RegStep = "Running on Localhost" + RunningRemotely RegStep = "Running Remotely" LocalOSRelease RegStep = "Local OS Release" CreatingContainer RegStep = "Creating Container" CreatingVM RegStep = "Creating VM" @@ -71,6 +72,7 @@ func init() { LocalOSRelease, CreatingContainer, CreatingVM, + RunningRemotely, PreparingKubernetes, ConfiguringLHEnv, VerifyingKubernetes, diff --git a/pkg/minikube/style/style.go b/pkg/minikube/style/style.go index cc722796b056..3bcfee946588 100644 --- a/pkg/minikube/style/style.go +++ b/pkg/minikube/style/style.go @@ -122,6 +122,7 @@ var Config = map[Enum]Options{ Resetting: {Prefix: "๐Ÿ”„ "}, Shutdown: {Prefix: "๐Ÿ›‘ "}, StartingNone: {Prefix: "๐Ÿคน "}, + StartingGeneric: {Prefix: "๐Ÿ”— "}, StartingVM: {Prefix: "๐Ÿ”ฅ "}, Tip: {Prefix: "๐Ÿ’ก "}, Unmount: {Prefix: "๐Ÿ”ฅ "}, diff --git a/pkg/minikube/style/style_enum.go b/pkg/minikube/style/style_enum.go index 6489e1ab3b09..9f2636910ac8 100644 --- a/pkg/minikube/style/style_enum.go +++ b/pkg/minikube/style/style_enum.go @@ -81,6 +81,7 @@ const ( Shutdown Sparkle StartingNone + StartingGeneric StartingVM Stopped Stopping diff --git a/pkg/util/utils.go b/pkg/util/utils.go index f5fe5a3b226a..e68d3b93daeb 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -22,6 +22,7 @@ import ( "os/user" "path/filepath" "strconv" + "strings" "github.com/blang/semver" units "github.com/docker/go-units" @@ -62,6 +63,47 @@ func ConvertUnsignedBytesToMB(byteSize uint64) int64 { return int64(byteSize / units.MiB) } +// ParseMemFree parses the output of the `free -m` command +func ParseMemFree(out string) (int64, error) { + // total used free shared buff/cache available + //Mem: 1987 706 194 1 1086 1173 + //Swap: 0 0 0 + outlines := strings.Split(out, "\n") + l := len(outlines) + for _, line := range outlines[1 : l-1] { + parsedLine := strings.Fields(line) + t, err := strconv.ParseInt(parsedLine[1], 10, 64) + if err != nil { + return 0, err + } + m := strings.Trim(parsedLine[0], ":") + if m == "Mem" { + return t, nil + } + } + return 0, nil +} + +// ParseDiskFree parses the output of the `df -m` command +func ParseDiskFree(out string) (int64, error) { + // Filesystem 1M-blocks Used Available Use% Mounted on + // /dev/sda1 39643 3705 35922 10% / + outlines := strings.Split(out, "\n") + l := len(outlines) + for _, line := range outlines[1 : l-1] { + parsedLine := strings.Fields(line) + t, err := strconv.ParseInt(parsedLine[1], 10, 64) + if err != nil { + return 0, err + } + m := parsedLine[5] + if m == "/" { + return t, nil + } + } + return 0, nil +} + // GetBinaryDownloadURL returns a suitable URL for the platform func GetBinaryDownloadURL(version, platform string) string { switch platform { From dc08bd8cbb22651bb86c408196ff4a2dd6386cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Thu, 29 Oct 2020 07:39:22 +0100 Subject: [PATCH 10/23] Fix failing unit test for MachineType Since we don't know the remote machine type anyway, it could be a virtual machine or a physical server. But we don't add any _extra_ isolation for minikube, so go with "bare metal machine" machine type for now. --- pkg/minikube/driver/driver.go | 4 ++++ pkg/minikube/driver/driver_test.go | 1 + 2 files changed, 5 insertions(+) diff --git a/pkg/minikube/driver/driver.go b/pkg/minikube/driver/driver.go index ce2333594ae4..1b92d38d1c6e 100644 --- a/pkg/minikube/driver/driver.go +++ b/pkg/minikube/driver/driver.go @@ -96,6 +96,10 @@ func MachineType(name string) string { return "container" } + if name == Generic { + return "bare metal machine" + } + if IsVM(name) { return "VM" } diff --git a/pkg/minikube/driver/driver_test.go b/pkg/minikube/driver/driver_test.go index 1f6ab86f7446..79e6b77893e2 100644 --- a/pkg/minikube/driver/driver_test.go +++ b/pkg/minikube/driver/driver_test.go @@ -65,6 +65,7 @@ func TestMachineType(t *testing.T) { Docker: "container", Mock: "bare metal machine", None: "bare metal machine", + Generic: "bare metal machine", KVM2: "VM", VirtualBox: "VM", HyperKit: "VM", From 9e7739e692867c25470005eda45fc15523942fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Thu, 29 Oct 2020 12:17:37 +0100 Subject: [PATCH 11/23] Log the os-release also for the generic driver --- pkg/minikube/machine/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/machine/start.go b/pkg/minikube/machine/start.go index cb1d74a1844c..0d33d299f5ae 100644 --- a/pkg/minikube/machine/start.go +++ b/pkg/minikube/machine/start.go @@ -295,7 +295,7 @@ func postStartSetup(h *host.Host, mc config.ClusterConfig) error { if driver.BareMetal(mc.Driver) { showLocalOsRelease() } - if driver.IsVM(mc.Driver) || driver.IsKIC(mc.Driver) { + if driver.IsVM(mc.Driver) || driver.IsKIC(mc.Driver) || mc.Driver == driver.Generic { logRemoteOsRelease(r) } return syncLocalAssets(r) From 3b594c31694c2e3a4c6ae1cea824064a586e4be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Thu, 29 Oct 2020 12:18:49 +0100 Subject: [PATCH 12/23] Need to set up docker group in start - not in fix It was only called for existing machines, not for new. But other commands expect to be able to run "docker". --- pkg/minikube/machine/fix.go | 6 ------ pkg/minikube/machine/start.go | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/minikube/machine/fix.go b/pkg/minikube/machine/fix.go index fa8167b30e5f..fd0e1580e4e8 100644 --- a/pkg/minikube/machine/fix.go +++ b/pkg/minikube/machine/fix.go @@ -95,12 +95,6 @@ func fixHost(api libmachine.API, cc *config.ClusterConfig, n *config.Node) (*hos return h, nil } - if h.Driver.DriverName() == driver.Generic { - if _, err := h.RunSSHCommand(fmt.Sprintf("sudo usermod -aG docker %s", h.Driver.GetSSHUsername())); err != nil { - return h, errors.Wrap(err, "usermod") - } - } - return h, ensureSyncedGuestClock(h, driverName) } diff --git a/pkg/minikube/machine/start.go b/pkg/minikube/machine/start.go index 0d33d299f5ae..a3dad3010e87 100644 --- a/pkg/minikube/machine/start.go +++ b/pkg/minikube/machine/start.go @@ -180,6 +180,12 @@ func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) ( return h, errors.Wrap(err, "post-start") } + if h.Driver.DriverName() == driver.Generic { + if _, err := h.RunSSHCommand(fmt.Sprintf("sudo usermod -aG docker %s", h.Driver.GetSSHUsername())); err != nil { + return h, errors.Wrap(err, "usermod") + } + } + if err := saveHost(api, h, cfg, n); err != nil { return h, err } From be770af47860abbdad1519908192593df17bf84c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Fri, 30 Oct 2020 12:05:24 +0100 Subject: [PATCH 13/23] Also parse the available, in addition to the total --- pkg/minikube/machine/info.go | 4 ++-- pkg/util/utils.go | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pkg/minikube/machine/info.go b/pkg/minikube/machine/info.go index 40c5ab47f7e5..3d18b74341e0 100644 --- a/pkg/minikube/machine/info.go +++ b/pkg/minikube/machine/info.go @@ -81,7 +81,7 @@ func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) { klog.Warningf("Unable to get mem info: %v", memErr) } free := rr.Stdout.String() - memory, err := util.ParseMemFree(free) + memory, _, err := util.ParseMemFree(free) if err != nil { klog.Warningf("Unable to parse mem info: %v", err) } @@ -90,7 +90,7 @@ func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) { klog.Warningf("Unable to get disk info: %v", diskErr) } df := rr.Stdout.String() - disksize, err := util.ParseDiskFree(df) + disksize, _, err := util.ParseDiskFree(df) if err != nil { klog.Warningf("Unable to parse disk info: %v", err) } diff --git a/pkg/util/utils.go b/pkg/util/utils.go index e68d3b93daeb..642bd1cb38e2 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -64,7 +64,8 @@ func ConvertUnsignedBytesToMB(byteSize uint64) int64 { } // ParseMemFree parses the output of the `free -m` command -func ParseMemFree(out string) (int64, error) { +// returns: total, available +func ParseMemFree(out string) (int64, int64, error) { // total used free shared buff/cache available //Mem: 1987 706 194 1 1086 1173 //Swap: 0 0 0 @@ -74,18 +75,23 @@ func ParseMemFree(out string) (int64, error) { parsedLine := strings.Fields(line) t, err := strconv.ParseInt(parsedLine[1], 10, 64) if err != nil { - return 0, err + return 0, 0, err + } + a, err := strconv.ParseInt(parsedLine[6], 10, 64) + if err != nil { + return 0, 0, err } m := strings.Trim(parsedLine[0], ":") if m == "Mem" { - return t, nil + return t, a, nil } } - return 0, nil + return 0, 0, nil } // ParseDiskFree parses the output of the `df -m` command -func ParseDiskFree(out string) (int64, error) { +// returns: total, available +func ParseDiskFree(out string) (int64, int64, error) { // Filesystem 1M-blocks Used Available Use% Mounted on // /dev/sda1 39643 3705 35922 10% / outlines := strings.Split(out, "\n") @@ -94,14 +100,18 @@ func ParseDiskFree(out string) (int64, error) { parsedLine := strings.Fields(line) t, err := strconv.ParseInt(parsedLine[1], 10, 64) if err != nil { - return 0, err + return 0, 0, err + } + a, err := strconv.ParseInt(parsedLine[3], 10, 64) + if err != nil { + return 0, 0, err } m := parsedLine[5] if m == "/" { - return t, nil + return t, a, nil } } - return 0, nil + return 0, 0, nil } // GetBinaryDownloadURL returns a suitable URL for the platform From e1effd31ab6318f2d9a6ed6afb5e4a93c79fce66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Fri, 30 Oct 2020 12:13:15 +0100 Subject: [PATCH 14/23] Add some error checking on the parsed data fields --- pkg/util/utils.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 642bd1cb38e2..b0d1632ee3ae 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -73,6 +73,9 @@ func ParseMemFree(out string) (int64, int64, error) { l := len(outlines) for _, line := range outlines[1 : l-1] { parsedLine := strings.Fields(line) + if len(parsedLine) < 7 { + continue + } t, err := strconv.ParseInt(parsedLine[1], 10, 64) if err != nil { return 0, 0, err @@ -86,7 +89,7 @@ func ParseMemFree(out string) (int64, int64, error) { return t, a, nil } } - return 0, 0, nil + return 0, 0, errors.New("No matching data found") } // ParseDiskFree parses the output of the `df -m` command @@ -98,6 +101,9 @@ func ParseDiskFree(out string) (int64, int64, error) { l := len(outlines) for _, line := range outlines[1 : l-1] { parsedLine := strings.Fields(line) + if len(parsedLine) < 6 { + continue + } t, err := strconv.ParseInt(parsedLine[1], 10, 64) if err != nil { return 0, 0, err @@ -111,7 +117,7 @@ func ParseDiskFree(out string) (int64, int64, error) { return t, a, nil } } - return 0, 0, nil + return 0, 0, errors.New("No matching data found") } // GetBinaryDownloadURL returns a suitable URL for the platform From b17ecbd3de03e0698ed97cf3a2f5ab2fb44fd7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Fri, 30 Oct 2020 14:54:56 +0100 Subject: [PATCH 15/23] Convert the return values to use uint64 instead --- pkg/minikube/machine/info.go | 4 ++-- pkg/util/utils.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/minikube/machine/info.go b/pkg/minikube/machine/info.go index 3d18b74341e0..0bf6048439d0 100644 --- a/pkg/minikube/machine/info.go +++ b/pkg/minikube/machine/info.go @@ -97,8 +97,8 @@ func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) { var info HostInfo info.CPUs = ncpus - info.Memory = memory - info.DiskSize = disksize + info.Memory = int64(memory) + info.DiskSize = int64(disksize) return &info, cpuErr, memErr, diskErr } diff --git a/pkg/util/utils.go b/pkg/util/utils.go index b0d1632ee3ae..f6189473fb67 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -65,7 +65,7 @@ func ConvertUnsignedBytesToMB(byteSize uint64) int64 { // ParseMemFree parses the output of the `free -m` command // returns: total, available -func ParseMemFree(out string) (int64, int64, error) { +func ParseMemFree(out string) (uint64, uint64, error) { // total used free shared buff/cache available //Mem: 1987 706 194 1 1086 1173 //Swap: 0 0 0 @@ -76,11 +76,11 @@ func ParseMemFree(out string) (int64, int64, error) { if len(parsedLine) < 7 { continue } - t, err := strconv.ParseInt(parsedLine[1], 10, 64) + t, err := strconv.ParseUint(parsedLine[1], 10, 64) if err != nil { return 0, 0, err } - a, err := strconv.ParseInt(parsedLine[6], 10, 64) + a, err := strconv.ParseUint(parsedLine[6], 10, 64) if err != nil { return 0, 0, err } @@ -94,7 +94,7 @@ func ParseMemFree(out string) (int64, int64, error) { // ParseDiskFree parses the output of the `df -m` command // returns: total, available -func ParseDiskFree(out string) (int64, int64, error) { +func ParseDiskFree(out string) (uint64, uint64, error) { // Filesystem 1M-blocks Used Available Use% Mounted on // /dev/sda1 39643 3705 35922 10% / outlines := strings.Split(out, "\n") @@ -104,11 +104,11 @@ func ParseDiskFree(out string) (int64, int64, error) { if len(parsedLine) < 6 { continue } - t, err := strconv.ParseInt(parsedLine[1], 10, 64) + t, err := strconv.ParseUint(parsedLine[1], 10, 64) if err != nil { return 0, 0, err } - a, err := strconv.ParseInt(parsedLine[3], 10, 64) + a, err := strconv.ParseUint(parsedLine[3], 10, 64) if err != nil { return 0, 0, err } From 88df53440fea62eb5137f83e8ed3d0157d3e38e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Fri, 30 Oct 2020 14:55:40 +0100 Subject: [PATCH 16/23] Supply the disk mountpoint as a parameter instead --- pkg/minikube/machine/info.go | 2 +- pkg/util/utils.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/minikube/machine/info.go b/pkg/minikube/machine/info.go index 0bf6048439d0..89d0e9f0814e 100644 --- a/pkg/minikube/machine/info.go +++ b/pkg/minikube/machine/info.go @@ -90,7 +90,7 @@ func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) { klog.Warningf("Unable to get disk info: %v", diskErr) } df := rr.Stdout.String() - disksize, _, err := util.ParseDiskFree(df) + disksize, _, err := util.ParseDiskFree(df, "/") if err != nil { klog.Warningf("Unable to parse disk info: %v", err) } diff --git a/pkg/util/utils.go b/pkg/util/utils.go index f6189473fb67..87f5533b347d 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -94,7 +94,7 @@ func ParseMemFree(out string) (uint64, uint64, error) { // ParseDiskFree parses the output of the `df -m` command // returns: total, available -func ParseDiskFree(out string) (uint64, uint64, error) { +func ParseDiskFree(out string, mountpoint string) (uint64, uint64, error) { // Filesystem 1M-blocks Used Available Use% Mounted on // /dev/sda1 39643 3705 35922 10% / outlines := strings.Split(out, "\n") @@ -113,7 +113,7 @@ func ParseDiskFree(out string) (uint64, uint64, error) { return 0, 0, err } m := parsedLine[5] - if m == "/" { + if m == mountpoint { return t, a, nil } } From 6104fb9160f53122a8470936a17c98d91f5f8736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 14 Nov 2020 09:13:16 +0100 Subject: [PATCH 17/23] fixup: out.T was renamed to out.Step --- pkg/minikube/machine/fix.go | 2 +- pkg/minikube/machine/start.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/minikube/machine/fix.go b/pkg/minikube/machine/fix.go index de6c2014dbc2..c4f986a12184 100644 --- a/pkg/minikube/machine/fix.go +++ b/pkg/minikube/machine/fix.go @@ -131,7 +131,7 @@ func recreateIfNeeded(api libmachine.API, cc *config.ClusterConfig, n *config.No if h.Driver.DriverName() == driver.Generic { if s == state.Running { - out.T(style.Running, `Using the {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType}) + out.Step(style.Running, `Using the {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType}) } else { return h, errors.Errorf("not running") } diff --git a/pkg/minikube/machine/start.go b/pkg/minikube/machine/start.go index aa1c516fc359..1ee50b7ad261 100644 --- a/pkg/minikube/machine/start.go +++ b/pkg/minikube/machine/start.go @@ -351,7 +351,7 @@ func showHostInfo(h *host.Host, cfg config.ClusterConfig) { info, cpuErr, memErr, DiskErr := RemoteHostInfo(r) if cpuErr == nil && memErr == nil && DiskErr == nil { register.Reg.SetStep(register.RunningRemotely) - out.T(style.StartingGeneric, "Running remotely (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize}) + out.Step(style.StartingGeneric, "Running remotely (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize}) } return } From 3bb75da6a2d8903e1555644a9a4f9d12c20f9d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 14 Nov 2020 09:14:32 +0100 Subject: [PATCH 18/23] Revert "Supply the disk mountpoint as a parameter instead" This reverts commit 88df53440fea62eb5137f83e8ed3d0157d3e38e6. --- pkg/minikube/machine/info.go | 2 +- pkg/util/utils.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/minikube/machine/info.go b/pkg/minikube/machine/info.go index 03c9fe637c6b..4ea320975343 100644 --- a/pkg/minikube/machine/info.go +++ b/pkg/minikube/machine/info.go @@ -90,7 +90,7 @@ func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) { klog.Warningf("Unable to get disk info: %v", diskErr) } df := rr.Stdout.String() - disksize, _, err := util.ParseDiskFree(df, "/") + disksize, _, err := util.ParseDiskFree(df) if err != nil { klog.Warningf("Unable to parse disk info: %v", err) } diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 87f5533b347d..f6189473fb67 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -94,7 +94,7 @@ func ParseMemFree(out string) (uint64, uint64, error) { // ParseDiskFree parses the output of the `df -m` command // returns: total, available -func ParseDiskFree(out string, mountpoint string) (uint64, uint64, error) { +func ParseDiskFree(out string) (uint64, uint64, error) { // Filesystem 1M-blocks Used Available Use% Mounted on // /dev/sda1 39643 3705 35922 10% / outlines := strings.Split(out, "\n") @@ -113,7 +113,7 @@ func ParseDiskFree(out string, mountpoint string) (uint64, uint64, error) { return 0, 0, err } m := parsedLine[5] - if m == mountpoint { + if m == "/" { return t, a, nil } } From bb5386432866d330b26e9e462b8aad1f9ffe0501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 14 Nov 2020 09:14:39 +0100 Subject: [PATCH 19/23] Revert "Convert the return values to use uint64 instead" This reverts commit b17ecbd3de03e0698ed97cf3a2f5ab2fb44fd7ee. --- pkg/minikube/machine/info.go | 4 ++-- pkg/util/utils.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/minikube/machine/info.go b/pkg/minikube/machine/info.go index 4ea320975343..278cfaa9f759 100644 --- a/pkg/minikube/machine/info.go +++ b/pkg/minikube/machine/info.go @@ -97,8 +97,8 @@ func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) { var info HostInfo info.CPUs = ncpus - info.Memory = int64(memory) - info.DiskSize = int64(disksize) + info.Memory = memory + info.DiskSize = disksize return &info, cpuErr, memErr, diskErr } diff --git a/pkg/util/utils.go b/pkg/util/utils.go index f6189473fb67..b0d1632ee3ae 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -65,7 +65,7 @@ func ConvertUnsignedBytesToMB(byteSize uint64) int64 { // ParseMemFree parses the output of the `free -m` command // returns: total, available -func ParseMemFree(out string) (uint64, uint64, error) { +func ParseMemFree(out string) (int64, int64, error) { // total used free shared buff/cache available //Mem: 1987 706 194 1 1086 1173 //Swap: 0 0 0 @@ -76,11 +76,11 @@ func ParseMemFree(out string) (uint64, uint64, error) { if len(parsedLine) < 7 { continue } - t, err := strconv.ParseUint(parsedLine[1], 10, 64) + t, err := strconv.ParseInt(parsedLine[1], 10, 64) if err != nil { return 0, 0, err } - a, err := strconv.ParseUint(parsedLine[6], 10, 64) + a, err := strconv.ParseInt(parsedLine[6], 10, 64) if err != nil { return 0, 0, err } @@ -94,7 +94,7 @@ func ParseMemFree(out string) (uint64, uint64, error) { // ParseDiskFree parses the output of the `df -m` command // returns: total, available -func ParseDiskFree(out string) (uint64, uint64, error) { +func ParseDiskFree(out string) (int64, int64, error) { // Filesystem 1M-blocks Used Available Use% Mounted on // /dev/sda1 39643 3705 35922 10% / outlines := strings.Split(out, "\n") @@ -104,11 +104,11 @@ func ParseDiskFree(out string) (uint64, uint64, error) { if len(parsedLine) < 6 { continue } - t, err := strconv.ParseUint(parsedLine[1], 10, 64) + t, err := strconv.ParseInt(parsedLine[1], 10, 64) if err != nil { return 0, 0, err } - a, err := strconv.ParseUint(parsedLine[3], 10, 64) + a, err := strconv.ParseInt(parsedLine[3], 10, 64) if err != nil { return 0, 0, err } From 612606c265eed15aea4e9d4805078812a37211a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 14 Nov 2020 09:14:47 +0100 Subject: [PATCH 20/23] Revert "Add some error checking on the parsed data fields" This reverts commit e1effd31ab6318f2d9a6ed6afb5e4a93c79fce66. --- pkg/util/utils.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pkg/util/utils.go b/pkg/util/utils.go index b0d1632ee3ae..642bd1cb38e2 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -73,9 +73,6 @@ func ParseMemFree(out string) (int64, int64, error) { l := len(outlines) for _, line := range outlines[1 : l-1] { parsedLine := strings.Fields(line) - if len(parsedLine) < 7 { - continue - } t, err := strconv.ParseInt(parsedLine[1], 10, 64) if err != nil { return 0, 0, err @@ -89,7 +86,7 @@ func ParseMemFree(out string) (int64, int64, error) { return t, a, nil } } - return 0, 0, errors.New("No matching data found") + return 0, 0, nil } // ParseDiskFree parses the output of the `df -m` command @@ -101,9 +98,6 @@ func ParseDiskFree(out string) (int64, int64, error) { l := len(outlines) for _, line := range outlines[1 : l-1] { parsedLine := strings.Fields(line) - if len(parsedLine) < 6 { - continue - } t, err := strconv.ParseInt(parsedLine[1], 10, 64) if err != nil { return 0, 0, err @@ -117,7 +111,7 @@ func ParseDiskFree(out string) (int64, int64, error) { return t, a, nil } } - return 0, 0, errors.New("No matching data found") + return 0, 0, nil } // GetBinaryDownloadURL returns a suitable URL for the platform From 08e1a659c98d1f59395c5b93b7dcee55a69f7c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 14 Nov 2020 09:15:01 +0100 Subject: [PATCH 21/23] Revert "Also parse the available, in addition to the total" This reverts commit be770af47860abbdad1519908192593df17bf84c. --- pkg/minikube/machine/info.go | 4 ++-- pkg/util/utils.go | 26 ++++++++------------------ 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/pkg/minikube/machine/info.go b/pkg/minikube/machine/info.go index 278cfaa9f759..424c880b829f 100644 --- a/pkg/minikube/machine/info.go +++ b/pkg/minikube/machine/info.go @@ -81,7 +81,7 @@ func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) { klog.Warningf("Unable to get mem info: %v", memErr) } free := rr.Stdout.String() - memory, _, err := util.ParseMemFree(free) + memory, err := util.ParseMemFree(free) if err != nil { klog.Warningf("Unable to parse mem info: %v", err) } @@ -90,7 +90,7 @@ func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) { klog.Warningf("Unable to get disk info: %v", diskErr) } df := rr.Stdout.String() - disksize, _, err := util.ParseDiskFree(df) + disksize, err := util.ParseDiskFree(df) if err != nil { klog.Warningf("Unable to parse disk info: %v", err) } diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 642bd1cb38e2..e68d3b93daeb 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -64,8 +64,7 @@ func ConvertUnsignedBytesToMB(byteSize uint64) int64 { } // ParseMemFree parses the output of the `free -m` command -// returns: total, available -func ParseMemFree(out string) (int64, int64, error) { +func ParseMemFree(out string) (int64, error) { // total used free shared buff/cache available //Mem: 1987 706 194 1 1086 1173 //Swap: 0 0 0 @@ -75,23 +74,18 @@ func ParseMemFree(out string) (int64, int64, error) { parsedLine := strings.Fields(line) t, err := strconv.ParseInt(parsedLine[1], 10, 64) if err != nil { - return 0, 0, err - } - a, err := strconv.ParseInt(parsedLine[6], 10, 64) - if err != nil { - return 0, 0, err + return 0, err } m := strings.Trim(parsedLine[0], ":") if m == "Mem" { - return t, a, nil + return t, nil } } - return 0, 0, nil + return 0, nil } // ParseDiskFree parses the output of the `df -m` command -// returns: total, available -func ParseDiskFree(out string) (int64, int64, error) { +func ParseDiskFree(out string) (int64, error) { // Filesystem 1M-blocks Used Available Use% Mounted on // /dev/sda1 39643 3705 35922 10% / outlines := strings.Split(out, "\n") @@ -100,18 +94,14 @@ func ParseDiskFree(out string) (int64, int64, error) { parsedLine := strings.Fields(line) t, err := strconv.ParseInt(parsedLine[1], 10, 64) if err != nil { - return 0, 0, err - } - a, err := strconv.ParseInt(parsedLine[3], 10, 64) - if err != nil { - return 0, 0, err + return 0, err } m := parsedLine[5] if m == "/" { - return t, a, nil + return t, nil } } - return 0, 0, nil + return 0, nil } // GetBinaryDownloadURL returns a suitable URL for the platform From 4428b3b2466d5d0b592e8a4a6cbcd690da8ffbde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 14 Nov 2020 09:16:44 +0100 Subject: [PATCH 22/23] Revert "Show remote host info and proper progress" This reverts commit 41979352b927b85e12574cb3bbbf4917ef1a06a0. --- cmd/minikube/cmd/start.go | 2 +- pkg/minikube/machine/info.go | 43 ++------------------------- pkg/minikube/machine/start.go | 24 ++------------- pkg/minikube/out/register/register.go | 2 -- pkg/minikube/style/style.go | 1 - pkg/minikube/style/style_enum.go | 1 - pkg/util/utils.go | 42 -------------------------- 7 files changed, 6 insertions(+), 109 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 0623b1c8a76e..9ceddfb8174d 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -812,7 +812,7 @@ func validateUser(drvName string) { // memoryLimits returns the amount of memory allocated to the system and hypervisor, the return value is in MiB func memoryLimits(drvName string) (int, int, error) { - info, cpuErr, memErr, diskErr := machine.LocalHostInfo() + info, cpuErr, memErr, diskErr := machine.CachedHostInfo() if cpuErr != nil { klog.Warningf("could not get system cpu info while verifying memory limits, which might be okay: %v", cpuErr) } diff --git a/pkg/minikube/machine/info.go b/pkg/minikube/machine/info.go index 424c880b829f..d2f3066a7ed7 100644 --- a/pkg/minikube/machine/info.go +++ b/pkg/minikube/machine/info.go @@ -19,8 +19,6 @@ package machine import ( "io/ioutil" "os/exec" - "strconv" - "strings" "github.com/docker/machine/libmachine/provision" "github.com/shirou/gopsutil/cpu" @@ -41,8 +39,8 @@ type HostInfo struct { DiskSize int64 } -// LocalHostInfo returns system information such as memory,CPU, DiskSize -func LocalHostInfo() (*HostInfo, error, error, error) { +// CachedHostInfo returns system information such as memory,CPU, DiskSize +func CachedHostInfo() (*HostInfo, error, error, error) { var cpuErr, memErr, diskErr error i, cpuErr := cachedCPUInfo() if cpuErr != nil { @@ -65,43 +63,6 @@ func LocalHostInfo() (*HostInfo, error, error, error) { return &info, cpuErr, memErr, diskErr } -// RemoteHostInfo returns system information such as memory,CPU, DiskSize -func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) { - rr, cpuErr := r.RunCmd(exec.Command("nproc")) - if cpuErr != nil { - klog.Warningf("Unable to get CPU info: %v", cpuErr) - } - nproc := rr.Stdout.String() - ncpus, err := strconv.Atoi(strings.TrimSpace(nproc)) - if err != nil { - klog.Warningf("Failed to parse CPU info: %v", err) - } - rr, memErr := r.RunCmd(exec.Command("free", "-m")) - if memErr != nil { - klog.Warningf("Unable to get mem info: %v", memErr) - } - free := rr.Stdout.String() - memory, err := util.ParseMemFree(free) - if err != nil { - klog.Warningf("Unable to parse mem info: %v", err) - } - rr, diskErr := r.RunCmd(exec.Command("df", "-m")) - if diskErr != nil { - klog.Warningf("Unable to get disk info: %v", diskErr) - } - df := rr.Stdout.String() - disksize, err := util.ParseDiskFree(df) - if err != nil { - klog.Warningf("Unable to parse disk info: %v", err) - } - - var info HostInfo - info.CPUs = ncpus - info.Memory = memory - info.DiskSize = disksize - return &info, cpuErr, memErr, diskErr -} - // showLocalOsRelease shows systemd information about the current linux distribution, on the local host func showLocalOsRelease() { osReleaseOut, err := ioutil.ReadFile("/etc/os-release") diff --git a/pkg/minikube/machine/start.go b/pkg/minikube/machine/start.go index 1ee50b7ad261..2e87e5e379d6 100644 --- a/pkg/minikube/machine/start.go +++ b/pkg/minikube/machine/start.go @@ -136,9 +136,7 @@ func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) ( See https://minikube.sigs.k8s.io/docs/reference/drivers/vmware/ for more information. To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`) } - if cfg.Driver != driver.Generic { - showHostInfo(nil, *cfg) - } + showHostInfo(*cfg) def := registry.Driver(cfg.Driver) if def.Empty() { return nil, fmt.Errorf("unsupported/missing driver: %s", cfg.Driver) @@ -172,9 +170,6 @@ func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) ( return nil, errors.Wrap(err, "creating host") } klog.Infof("duration metric: libmachine.API.Create for %q took %s", cfg.Name, time.Since(cstart)) - if cfg.Driver == driver.Generic { - showHostInfo(h, *cfg) - } if err := postStartSetup(h, *cfg); err != nil { return h, errors.Wrap(err, "post-start") @@ -332,29 +327,16 @@ func acquireMachinesLock(name string, drv string) (mutex.Releaser, error) { } // showHostInfo shows host information -func showHostInfo(h *host.Host, cfg config.ClusterConfig) { +func showHostInfo(cfg config.ClusterConfig) { machineType := driver.MachineType(cfg.Driver) if driver.BareMetal(cfg.Driver) { - info, cpuErr, memErr, DiskErr := LocalHostInfo() + info, cpuErr, memErr, DiskErr := CachedHostInfo() if cpuErr == nil && memErr == nil && DiskErr == nil { register.Reg.SetStep(register.RunningLocalhost) out.Step(style.StartingNone, "Running on localhost (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize}) } return } - if cfg.Driver == driver.Generic { - r, err := CommandRunner(h) - if err != nil { - klog.Warningf("error getting command runner: %v", err) - return - } - info, cpuErr, memErr, DiskErr := RemoteHostInfo(r) - if cpuErr == nil && memErr == nil && DiskErr == nil { - register.Reg.SetStep(register.RunningRemotely) - out.Step(style.StartingGeneric, "Running remotely (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize}) - } - return - } if driver.IsKIC(cfg.Driver) { // TODO:medyagh add free disk space on docker machine register.Reg.SetStep(register.CreatingContainer) out.Step(style.StartingVM, "Creating {{.driver_name}} {{.machine_type}} (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB) ...", out.V{"driver_name": cfg.Driver, "number_of_cpus": cfg.CPUs, "memory_size": cfg.Memory, "machine_type": machineType}) diff --git a/pkg/minikube/out/register/register.go b/pkg/minikube/out/register/register.go index a538a159f222..b442eebad9c9 100644 --- a/pkg/minikube/out/register/register.go +++ b/pkg/minikube/out/register/register.go @@ -30,7 +30,6 @@ const ( StartingNode RegStep = "Starting Node" PullingBaseImage RegStep = "Pulling Base Image" RunningLocalhost RegStep = "Running on Localhost" - RunningRemotely RegStep = "Running Remotely" LocalOSRelease RegStep = "Local OS Release" CreatingContainer RegStep = "Creating Container" CreatingVM RegStep = "Creating VM" @@ -74,7 +73,6 @@ func init() { LocalOSRelease, CreatingContainer, CreatingVM, - RunningRemotely, PreparingKubernetes, ConfiguringLHEnv, VerifyingKubernetes, diff --git a/pkg/minikube/style/style.go b/pkg/minikube/style/style.go index 3bcfee946588..cc722796b056 100644 --- a/pkg/minikube/style/style.go +++ b/pkg/minikube/style/style.go @@ -122,7 +122,6 @@ var Config = map[Enum]Options{ Resetting: {Prefix: "๐Ÿ”„ "}, Shutdown: {Prefix: "๐Ÿ›‘ "}, StartingNone: {Prefix: "๐Ÿคน "}, - StartingGeneric: {Prefix: "๐Ÿ”— "}, StartingVM: {Prefix: "๐Ÿ”ฅ "}, Tip: {Prefix: "๐Ÿ’ก "}, Unmount: {Prefix: "๐Ÿ”ฅ "}, diff --git a/pkg/minikube/style/style_enum.go b/pkg/minikube/style/style_enum.go index 9f2636910ac8..6489e1ab3b09 100644 --- a/pkg/minikube/style/style_enum.go +++ b/pkg/minikube/style/style_enum.go @@ -81,7 +81,6 @@ const ( Shutdown Sparkle StartingNone - StartingGeneric StartingVM Stopped Stopping diff --git a/pkg/util/utils.go b/pkg/util/utils.go index e68d3b93daeb..f5fe5a3b226a 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -22,7 +22,6 @@ import ( "os/user" "path/filepath" "strconv" - "strings" "github.com/blang/semver" units "github.com/docker/go-units" @@ -63,47 +62,6 @@ func ConvertUnsignedBytesToMB(byteSize uint64) int64 { return int64(byteSize / units.MiB) } -// ParseMemFree parses the output of the `free -m` command -func ParseMemFree(out string) (int64, error) { - // total used free shared buff/cache available - //Mem: 1987 706 194 1 1086 1173 - //Swap: 0 0 0 - outlines := strings.Split(out, "\n") - l := len(outlines) - for _, line := range outlines[1 : l-1] { - parsedLine := strings.Fields(line) - t, err := strconv.ParseInt(parsedLine[1], 10, 64) - if err != nil { - return 0, err - } - m := strings.Trim(parsedLine[0], ":") - if m == "Mem" { - return t, nil - } - } - return 0, nil -} - -// ParseDiskFree parses the output of the `df -m` command -func ParseDiskFree(out string) (int64, error) { - // Filesystem 1M-blocks Used Available Use% Mounted on - // /dev/sda1 39643 3705 35922 10% / - outlines := strings.Split(out, "\n") - l := len(outlines) - for _, line := range outlines[1 : l-1] { - parsedLine := strings.Fields(line) - t, err := strconv.ParseInt(parsedLine[1], 10, 64) - if err != nil { - return 0, err - } - m := parsedLine[5] - if m == "/" { - return t, nil - } - } - return 0, nil -} - // GetBinaryDownloadURL returns a suitable URL for the platform func GetBinaryDownloadURL(version, platform string) string { switch platform { From 70d1a314567c1f6321def5cd912ad818d495ce73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 14 Nov 2020 09:36:49 +0100 Subject: [PATCH 23/23] Add helper for checking the generic driver name --- cmd/minikube/cmd/delete.go | 2 +- cmd/minikube/cmd/start.go | 2 +- pkg/minikube/driver/driver.go | 7 ++++++- pkg/minikube/machine/fix.go | 2 +- pkg/minikube/machine/machine.go | 2 +- pkg/minikube/machine/start.go | 4 ++-- pkg/minikube/machine/stop.go | 2 +- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index fdd11f4aaf30..a9fc755f132e 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -309,7 +309,7 @@ func deleteProfile(profile *config.Profile) error { return DeletionError{Err: delErr, Errtype: MissingProfile} } - if err == nil && (driver.BareMetal(cc.Driver) || cc.Driver == driver.Generic) { + if err == nil && (driver.BareMetal(cc.Driver) || driver.IsGeneric(cc.Driver)) { if err := uninstallKubernetes(api, *cc, cc.Nodes[0], viper.GetString(cmdcfg.Bootstrapper)); err != nil { deletionError, ok := err.(DeletionError) if ok { diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 9ceddfb8174d..99434326f5f5 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -299,7 +299,7 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing * os.Exit(0) } - if driver.IsVM(driverName) && driverName != driver.Generic { + if driver.IsVM(driverName) && !driver.IsGeneric(driverName) { url, err := download.ISO(viper.GetStringSlice(isoURL), cmd.Flags().Changed(isoURL)) if err != nil { return node.Starter{}, errors.Wrap(err, "Failed to cache ISO") diff --git a/pkg/minikube/driver/driver.go b/pkg/minikube/driver/driver.go index 1b92d38d1c6e..22ec95b247a3 100644 --- a/pkg/minikube/driver/driver.go +++ b/pkg/minikube/driver/driver.go @@ -96,7 +96,7 @@ func MachineType(name string) string { return "container" } - if name == Generic { + if IsGeneric(name) { return "bare metal machine" } @@ -147,6 +147,11 @@ func BareMetal(name string) bool { return name == None || name == Mock } +// IsGeneric checks if the driver is generic +func IsGeneric(name string) bool { + return name == Generic +} + // NeedsRoot returns true if driver needs to run with root privileges func NeedsRoot(name string) bool { return name == None diff --git a/pkg/minikube/machine/fix.go b/pkg/minikube/machine/fix.go index c4f986a12184..58e09eb8ee1e 100644 --- a/pkg/minikube/machine/fix.go +++ b/pkg/minikube/machine/fix.go @@ -129,7 +129,7 @@ func recreateIfNeeded(api libmachine.API, cc *config.ClusterConfig, n *config.No } } - if h.Driver.DriverName() == driver.Generic { + if driver.IsGeneric(h.Driver.DriverName()) { if s == state.Running { out.Step(style.Running, `Using the {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType}) } else { diff --git a/pkg/minikube/machine/machine.go b/pkg/minikube/machine/machine.go index cf27e81655d6..2fdf60ba693a 100644 --- a/pkg/minikube/machine/machine.go +++ b/pkg/minikube/machine/machine.go @@ -104,7 +104,7 @@ func fastDetectProvisioner(h *host.Host) (libprovision.Provisioner, error) { switch { case driver.IsKIC(d): return provision.NewUbuntuProvisioner(h.Driver), nil - case driver.BareMetal(d), d == driver.Generic: + case driver.BareMetal(d), driver.IsGeneric(d): return libprovision.DetectProvisioner(h.Driver) default: return provision.NewBuildrootProvisioner(h.Driver), nil diff --git a/pkg/minikube/machine/start.go b/pkg/minikube/machine/start.go index 2e87e5e379d6..9079162089a2 100644 --- a/pkg/minikube/machine/start.go +++ b/pkg/minikube/machine/start.go @@ -175,7 +175,7 @@ func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) ( return h, errors.Wrap(err, "post-start") } - if h.Driver.DriverName() == driver.Generic { + if driver.IsGeneric(h.Driver.DriverName()) { if _, err := h.RunSSHCommand(fmt.Sprintf("sudo usermod -aG docker %s", h.Driver.GetSSHUsername())); err != nil { return h, errors.Wrap(err, "usermod") } @@ -296,7 +296,7 @@ func postStartSetup(h *host.Host, mc config.ClusterConfig) error { if driver.BareMetal(mc.Driver) { showLocalOsRelease() } - if driver.IsVM(mc.Driver) || driver.IsKIC(mc.Driver) || mc.Driver == driver.Generic { + if driver.IsVM(mc.Driver) || driver.IsKIC(mc.Driver) || driver.IsGeneric(mc.Driver) { logRemoteOsRelease(r) } return syncLocalAssets(r) diff --git a/pkg/minikube/machine/stop.go b/pkg/minikube/machine/stop.go index 0526b08f7cb6..56623d353526 100644 --- a/pkg/minikube/machine/stop.go +++ b/pkg/minikube/machine/stop.go @@ -55,7 +55,7 @@ func stop(h *host.Host) error { } } - if h.DriverName == driver.Generic { + if driver.IsGeneric(h.DriverName) { return nil }