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 {