From 5ec324e2d270fdaa3c39634ad0797590bfd69566 Mon Sep 17 00:00:00 2001 From: Max K Date: Wed, 14 Aug 2019 17:46:34 -0700 Subject: [PATCH 1/4] Added check to exit app and show error message if number of cpus is less than the minimum required. --- cmd/minikube/cmd/start.go | 5 +++++ pkg/minikube/constants/constants.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 4f5d6f882859..d8bedcddbf9e 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -574,6 +574,11 @@ func validateConfig() { out.V{"memory": memorySizeMB, "default_memorysize": pkgutil.CalculateSizeInMB(constants.DefaultMemorySize)}) } + cpuCount = viper.GetInt(cpus) + if cpuCount < constants.MinimumCPUS { + exit.UsageT("Requested cpu count {{.requested_cpus}} is less than the minimum allowed of {{.minimum_cpus}}", out.V{"requested_cpus": cpuCount, "minimum_cpus": constants.MinimumCPUS}) + } + // check that kubeadm extra args contain only whitelisted parameters for param := range extraOptions.AsMap().Get(kubeadm.Kubeadm) { if !cfg.ContainsParam(kubeadm.KubeadmExtraArgsWhitelist[kubeadm.KubeadmCmdParam], param) && diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index ca3a47d8a856..90cd2fb86ced 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -141,6 +141,8 @@ const ( MinimumMemorySize = "1024mb" // DefaultCPUS is the default number of cpus of a host DefaultCPUS = 2 + // MinimumCPUS is the minimum number of cpus of a host + MinimumCPUS = 2 // DefaultDiskSize is the default disk image size, in megabytes DefaultDiskSize = "20000mb" // MinimumDiskSize is the minimum disk image size, in megabytes From ac49c96c9ba652339ad1d009624afc310dcce538 Mon Sep 17 00:00:00 2001 From: Max K Date: Tue, 20 Aug 2019 18:23:27 -0700 Subject: [PATCH 2/4] Updated cpu check to handle none driver cpu check --- cmd/minikube/cmd/start.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index d8bedcddbf9e..d0f658470a8f 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -60,6 +60,7 @@ import ( "k8s.io/minikube/pkg/util/lock" "k8s.io/minikube/pkg/util/retry" "k8s.io/minikube/pkg/version" + "github.com/shirou/gopsutil/cpu" ) const ( @@ -574,7 +575,16 @@ func validateConfig() { out.V{"memory": memorySizeMB, "default_memorysize": pkgutil.CalculateSizeInMB(constants.DefaultMemorySize)}) } - cpuCount = viper.GetInt(cpus) + if viper.GetString(vmDriver) == constants.DriverNone { + ci, err := cpu.Info() + if err != nil { + glog.Warningf("Unable to get CPU info: $v", err) + } else { + cpuCount = ci.Cores + } + } else { + cpuCount = viper.GetInt(cpus) + } if cpuCount < constants.MinimumCPUS { exit.UsageT("Requested cpu count {{.requested_cpus}} is less than the minimum allowed of {{.minimum_cpus}}", out.V{"requested_cpus": cpuCount, "minimum_cpus": constants.MinimumCPUS}) } From 68f8dca51a0229c921873a0e35808dbf952879c9 Mon Sep 17 00:00:00 2001 From: Max K Date: Thu, 22 Aug 2019 11:51:19 -0700 Subject: [PATCH 3/4] Fixed counting of physical CPU cores Gopsutil packae doesn't automatically return a count of CPU cores, have to use the Counts function. --- cmd/minikube/cmd/start.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index d0f658470a8f..4c08995f4aa8 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -575,12 +575,14 @@ func validateConfig() { out.V{"memory": memorySizeMB, "default_memorysize": pkgutil.CalculateSizeInMB(constants.DefaultMemorySize)}) } + var cpuCount int if viper.GetString(vmDriver) == constants.DriverNone { - ci, err := cpu.Info() + // Uses the gopsutil cpu package to count the number of physical cpu cores + ci, err := cpu.Counts(false) if err != nil { - glog.Warningf("Unable to get CPU info: $v", err) + glog.Warningf("Unable to get CPU info: %v", err) } else { - cpuCount = ci.Cores + cpuCount = ci } } else { cpuCount = viper.GetInt(cpus) From 4831b48b8fe9ebbc8ed9a0eed1fd7ca2ea1aeda4 Mon Sep 17 00:00:00 2001 From: Max K Date: Mon, 2 Sep 2019 13:17:59 -0700 Subject: [PATCH 4/4] Fixed formatting issue --- 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 4c08995f4aa8..6dd404293b8b 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -37,6 +37,7 @@ import ( "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/remote" + "github.com/shirou/gopsutil/cpu" gopshost "github.com/shirou/gopsutil/host" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -60,7 +61,6 @@ import ( "k8s.io/minikube/pkg/util/lock" "k8s.io/minikube/pkg/util/retry" "k8s.io/minikube/pkg/version" - "github.com/shirou/gopsutil/cpu" ) const (