From 05ee40fc2829851658c2dd7e552bf2b87519751f Mon Sep 17 00:00:00 2001 From: fang duan Date: Wed, 26 Jun 2019 19:10:33 +0800 Subject: [PATCH 1/2] Minikube start respects MINIKUBE_ prefixed env now --- cmd/minikube/cmd/start.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 847dbc637450..b133fab336e1 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -128,6 +128,12 @@ func init() { // initMinikubeFlags includes commandline flags for minikube. func initMinikubeFlags() { + viper.SetEnvPrefix(constants.MinikubeEnvPrefix) + // Replaces '-' in flags with '_' in env variables + // e.g. iso-url => $ENVPREFIX_ISO_URL + viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) + viper.AutomaticEnv() + startCmd.Flags().Int(cpus, constants.DefaultCPUS, "Number of CPUs allocated to the minikube VM") startCmd.Flags().String(memory, constants.DefaultMemorySize, "Amount of RAM allocated to the minikube VM (format: [], where unit = b, k, m or g)") startCmd.Flags().String(humanReadableDiskSize, constants.DefaultDiskSize, "Disk size allocated to the minikube VM (format: [], where unit = b, k, m or g)") @@ -158,7 +164,6 @@ func initKubernetesFlags() { startCmd.Flags().String(apiServerName, constants.APIServerName, "The apiserver name which is used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") startCmd.Flags().StringArrayVar(&apiServerNames, "apiserver-names", nil, "A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") startCmd.Flags().IPSliceVar(&apiServerIPs, "apiserver-ips", nil, "A set of apiserver IP Addresses which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") - } // initDriverFlags inits the commandline flags for vm drivers @@ -210,6 +215,18 @@ var startCmd = &cobra.Command{ // runStart handles the executes the flow of "minikube start" func runStart(cmd *cobra.Command, args []string) { out.T(out.Happy, "minikube {{.version}} on {{.os}} ({{.arch}})", out.V{"version": version.GetVersion(), "os": runtime.GOOS, "arch": runtime.GOARCH}) + + // if --registry-mirror specified when run minikube start, + // take arg precedence over MINIKUBE_REGISTRY_MIRROR + // actually this is a hack, because viper 1.0.0 can assign env to variable if StringSliceVar + // and i can't update it to 1.4.0, it affects too much code + // other types (like String, Bool) of flag works, so imageRepository, imageMirrorCountry + // can be configured as MINIKUBE_IMAGE_REPOSITORY and IMAGE_MIRROR_COUNTRY + // this should be updated to documentation + if len(registryMirror) == 0 { + registryMirror = viper.GetStringSlice("registry_mirror") + } + validateConfig() validateUser() From a44b3393aaa47d554c523b561aa5a20e99167802 Mon Sep 17 00:00:00 2001 From: fang duan Date: Tue, 30 Jul 2019 08:20:37 +0800 Subject: [PATCH 2/2] FIX --- 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 1452a0e98526..6a2c627287e0 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -235,7 +235,7 @@ func runStart(cmd *cobra.Command, args []string) { out.V{"driver": vmDriver, "os": runtime.GOOS}, ) } - + validateConfig() validateUser() validateDriverVersion(viper.GetString(vmDriver))