Skip to content

Commit

Permalink
Add condition to check --cpus count with available cpu count
Browse files Browse the repository at this point in the history
  • Loading branch information
BLasan committed Feb 6, 2021
1 parent bdd1e6d commit 399c23d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
klog.Errorf("Error autoSetOptions : %v", err)
}

validateFlags(cmd, driverName)
validateFlags(cmd, driverName, existing.CPUs)
validateUser(driverName)
if driverName == oci.Docker {
validateDockerStorageDriver(driverName)
Expand Down Expand Up @@ -995,8 +995,8 @@ func validateRequestedMemorySize(req int, drvName string) {
}
}

// validateCPUCount validates the cpu count matches the minimum recommended
func validateCPUCount(drvName string) {
// validateCPUCount validates the cpu count matches the minimum recommended & not exceeding the available cpu count
func validateCPUCount(drvName string, argCPUCount int) {
var cpuCount int
if driver.BareMetal(drvName) {

Expand All @@ -1015,6 +1015,10 @@ func validateCPUCount(drvName string) {
exitIfNotForced(reason.RsrcInsufficientCores, "Requested cpu count {{.requested_cpus}} is less than the minimum allowed of {{.minimum_cpus}}", out.V{"requested_cpus": cpuCount, "minimum_cpus": minimumCPUS})
}

if cpuCount < argCPUCount {
exitIfNotForced(reason.RsrcInsufficientCores, "Requested cpu count {{.requested_cpus}} is less than the available CPU count of {{.avail_cpus}}", out.V{"requested_cpus": argCPUCount, "avail_cpus": cpuCount})
}

if !driver.IsKIC((drvName)) {
return
}
Expand Down Expand Up @@ -1044,7 +1048,7 @@ func validateCPUCount(drvName string) {
}

// validateFlags validates the supplied flags against known bad combinations
func validateFlags(cmd *cobra.Command, drvName string) {
func validateFlags(cmd *cobra.Command, drvName string, cpuCount int) {
if cmd.Flags().Changed(humanReadableDiskSize) {
diskSizeMB, err := util.CalculateSizeInMB(viper.GetString(humanReadableDiskSize))
if err != nil {
Expand All @@ -1062,7 +1066,7 @@ func validateFlags(cmd *cobra.Command, drvName string) {
}
}

validateCPUCount(drvName)
validateCPUCount(drvName, cpuCount)

if cmd.Flags().Changed(memory) {
if !driver.HasResourceLimits(drvName) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func upgradeExistingConfig(cc *config.ClusterConfig) {
// skipping updating existing docker env , docker opt, InsecureRegistry, registryMirror, extra-config, apiserver-ips
func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterConfig) config.ClusterConfig { //nolint to suppress cyclomatic complexity 45 of func `updateExistingConfigFromFlags` is high (> 30)

validateFlags(cmd, existing.Driver)
validateFlags(cmd, existing.Driver, existing.CPUs)

cc := *existing

Expand Down

0 comments on commit 399c23d

Please sign in to comment.