Skip to content

Commit ba2f931

Browse files
Merge pull request #5086 from MaxKam/checkCPUCount
Minimum CPUs check
2 parents 3457782 + 4831b48 commit ba2f931

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

cmd/minikube/cmd/start.go

+17
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/google/go-containerregistry/pkg/authn"
4040
"github.com/google/go-containerregistry/pkg/name"
4141
"github.com/google/go-containerregistry/pkg/v1/remote"
42+
"github.com/shirou/gopsutil/cpu"
4243
gopshost "github.com/shirou/gopsutil/host"
4344
"github.com/spf13/cobra"
4445
"github.com/spf13/viper"
@@ -582,6 +583,22 @@ func validateConfig() {
582583
out.V{"memory": memorySizeMB, "default_memorysize": pkgutil.CalculateSizeInMB(constants.DefaultMemorySize)})
583584
}
584585

586+
var cpuCount int
587+
if viper.GetString(vmDriver) == constants.DriverNone {
588+
// Uses the gopsutil cpu package to count the number of physical cpu cores
589+
ci, err := cpu.Counts(false)
590+
if err != nil {
591+
glog.Warningf("Unable to get CPU info: %v", err)
592+
} else {
593+
cpuCount = ci
594+
}
595+
} else {
596+
cpuCount = viper.GetInt(cpus)
597+
}
598+
if cpuCount < constants.MinimumCPUS {
599+
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})
600+
}
601+
585602
// check that kubeadm extra args contain only whitelisted parameters
586603
for param := range extraOptions.AsMap().Get(kubeadm.Kubeadm) {
587604
if !cfg.ContainsParam(kubeadm.KubeadmExtraArgsWhitelist[kubeadm.KubeadmCmdParam], param) &&

pkg/minikube/constants/constants.go

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ const (
141141
MinimumMemorySize = "1024mb"
142142
// DefaultCPUS is the default number of cpus of a host
143143
DefaultCPUS = 2
144+
// MinimumCPUS is the minimum number of cpus of a host
145+
MinimumCPUS = 2
144146
// DefaultDiskSize is the default disk image size, in megabytes
145147
DefaultDiskSize = "20000mb"
146148
// MinimumDiskSize is the minimum disk image size, in megabytes

0 commit comments

Comments
 (0)