Skip to content

Commit

Permalink
Merge pull request #5086 from MaxKam/checkCPUCount
Browse files Browse the repository at this point in the history
Minimum CPUs check
  • Loading branch information
sharifelgamal authored Sep 5, 2019
2 parents 3457782 + 4831b48 commit ba2f931
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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"
Expand Down Expand Up @@ -582,6 +583,22 @@ func validateConfig() {
out.V{"memory": memorySizeMB, "default_memorysize": pkgutil.CalculateSizeInMB(constants.DefaultMemorySize)})
}

var cpuCount int
if viper.GetString(vmDriver) == constants.DriverNone {
// 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)
} else {
cpuCount = ci
}
} 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})
}

// 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) &&
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba2f931

Please sign in to comment.