Skip to content

Commit 05ee40f

Browse files
committed
Minikube start respects MINIKUBE_ prefixed env now
1 parent bcf3597 commit 05ee40f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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
@@ -210,6 +215,18 @@ var startCmd = &cobra.Command{
210215
// runStart handles the executes the flow of "minikube start"
211216
func runStart(cmd *cobra.Command, args []string) {
212217
out.T(out.Happy, "minikube {{.version}} on {{.os}} ({{.arch}})", out.V{"version": version.GetVersion(), "os": runtime.GOOS, "arch": runtime.GOARCH})
218+
219+
// if --registry-mirror specified when run minikube start,
220+
// take arg precedence over MINIKUBE_REGISTRY_MIRROR
221+
// actually this is a hack, because viper 1.0.0 can assign env to variable if StringSliceVar
222+
// and i can't update it to 1.4.0, it affects too much code
223+
// other types (like String, Bool) of flag works, so imageRepository, imageMirrorCountry
224+
// can be configured as MINIKUBE_IMAGE_REPOSITORY and IMAGE_MIRROR_COUNTRY
225+
// this should be updated to documentation
226+
if len(registryMirror) == 0 {
227+
registryMirror = viper.GetStringSlice("registry_mirror")
228+
}
229+
213230
validateConfig()
214231
validateUser()
215232

0 commit comments

Comments
 (0)