From 6e8f596eacbac11a742f0e6a2cc6b4d0c6dcb29a Mon Sep 17 00:00:00 2001 From: Anshul Sirur Date: Wed, 19 Aug 2020 14:43:13 +0200 Subject: [PATCH] Fix --memory flag parsing in minikube start Due to the way Go handles variable scope, `mem` was being redeclared inside the conditional. Outside, we were stuck with the value provided by `suggestMemoryAllocation`, therefore ignoring the value passed through the `--memory` flag. --- cmd/minikube/cmd/start_flags.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index d3c4f2c1f5cc..d954bf89c934 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -227,14 +227,14 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k mem := suggestMemoryAllocation(sysLimit, containerLimit, viper.GetInt(nodes)) if cmd.Flags().Changed(memory) { - mem, err := pkgutil.CalculateSizeInMB(viper.GetString(memory)) + var err error + mem, err = pkgutil.CalculateSizeInMB(viper.GetString(memory)) if err != nil { exit.WithCodeT(exit.Config, "Generate unable to parse memory '{{.memory}}': {{.error}}", out.V{"memory": viper.GetString(memory), "error": err}) } if driver.IsKIC(drvName) && mem > containerLimit { exit.UsageT("{{.driver_name}} has only {{.container_limit}}MB memory but you specified {{.specified_memory}}MB", out.V{"container_limit": containerLimit, "specified_memory": mem, "driver_name": driver.FullName(drvName)}) } - } else { validateMemorySize(mem, drvName) glog.Infof("Using suggested %dMB memory alloc based on sys=%dMB, container=%dMB", mem, sysLimit, containerLimit)