Skip to content

Commit ae9f406

Browse files
authored
Merge pull request #4607 from dfang/feature/registry_mirror_env
Automatically set flags for MINIKUBE_ prefixed env vars
2 parents de84f83 + a44b339 commit ae9f406

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: cmd/minikube/cmd/start.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ func init() {
128128

129129
// initMinikubeFlags includes commandline flags for minikube.
130130
func initMinikubeFlags() {
131+
viper.SetEnvPrefix(constants.MinikubeEnvPrefix)
132+
// Replaces '-' in flags with '_' in env variables
133+
// e.g. iso-url => $ENVPREFIX_ISO_URL
134+
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
135+
viper.AutomaticEnv()
136+
131137
startCmd.Flags().Int(cpus, constants.DefaultCPUS, "Number of CPUs allocated to the minikube VM")
132138
startCmd.Flags().String(memory, constants.DefaultMemorySize, "Amount of RAM allocated to the minikube VM (format: <number>[<unit>], where unit = b, k, m or g)")
133139
startCmd.Flags().String(humanReadableDiskSize, constants.DefaultDiskSize, "Disk size allocated to the minikube VM (format: <number>[<unit>], where unit = b, k, m or g)")
@@ -158,7 +164,6 @@ func initKubernetesFlags() {
158164
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")
159165
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")
160166
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")
161-
162167
}
163168

164169
// initDriverFlags inits the commandline flags for vm drivers
@@ -243,6 +248,17 @@ func runStart(cmd *cobra.Command, args []string) {
243248
}
244249
out.T(out.Happy, "{{.prefix}}minikube {{.version}} on {{.platform}}", out.V{"prefix": prefix, "version": version.GetVersion(), "platform": platform()})
245250

251+
// if --registry-mirror specified when run minikube start,
252+
// take arg precedence over MINIKUBE_REGISTRY_MIRROR
253+
// actually this is a hack, because viper 1.0.0 can assign env to variable if StringSliceVar
254+
// and i can't update it to 1.4.0, it affects too much code
255+
// other types (like String, Bool) of flag works, so imageRepository, imageMirrorCountry
256+
// can be configured as MINIKUBE_IMAGE_REPOSITORY and IMAGE_MIRROR_COUNTRY
257+
// this should be updated to documentation
258+
if len(registryMirror) == 0 {
259+
registryMirror = viper.GetStringSlice("registry_mirror")
260+
}
261+
246262
vmDriver := viper.GetString(vmDriver)
247263
if err := cmdcfg.IsValidDriver(runtime.GOOS, vmDriver); err != nil {
248264
exit.WithCodeT(
@@ -251,6 +267,7 @@ func runStart(cmd *cobra.Command, args []string) {
251267
out.V{"driver": vmDriver, "os": runtime.GOOS},
252268
)
253269
}
270+
254271
validateConfig()
255272
validateUser()
256273
validateDriverVersion(viper.GetString(vmDriver))

0 commit comments

Comments
 (0)