From 98b0258565dc0b4b6755a91b5231f96545f2f1f5 Mon Sep 17 00:00:00 2001 From: SataQiu <1527062125@qq.com> Date: Fri, 22 May 2020 15:11:02 +0800 Subject: [PATCH] honor --image-repository even if --image-mirror-country is set --- cmd/minikube/cmd/start_flags.go | 8 ++------ cmd/minikube/cmd/start_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 6ed72ee0395f..7dd8dff6c2b5 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -211,7 +211,7 @@ func ClusterFlagValue() string { // generateClusterConfig generate a config.ClusterConfig based on flags or existing cluster config func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k8sVersion string, drvName string) (config.ClusterConfig, config.Node, error) { - cc := config.ClusterConfig{} + var cc config.ClusterConfig if existing != nil { // create profile config first time cc = updateExistingConfigFromFlags(cmd, existing) } else { @@ -242,10 +242,6 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k return cc, config.Node{}, errors.Wrap(err, "new runtime manager") } - if cmd.Flags().Changed(imageRepository) { - cc.KubernetesConfig.ImageRepository = viper.GetString(imageRepository) - } - // Pick good default values for --network-plugin and --enable-default-cni based on runtime. selectedEnableDefaultCNI := viper.GetBool(enableDefaultCNI) selectedNetworkPlugin := viper.GetString(networkPlugin) @@ -258,7 +254,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k repository := viper.GetString(imageRepository) mirrorCountry := strings.ToLower(viper.GetString(imageMirrorCountry)) - if strings.ToLower(repository) == "auto" || mirrorCountry != "" { + if strings.ToLower(repository) == "auto" || (mirrorCountry != "" && repository == "") { found, autoSelectedRepository, err := selectImageRepository(mirrorCountry, semver.MustParse(strings.TrimPrefix(k8sVersion, version.VersionPrefix))) if err != nil { exit.WithError("Failed to check main repository and mirrors for images", err) diff --git a/cmd/minikube/cmd/start_test.go b/cmd/minikube/cmd/start_test.go index 3e3e6597021a..4abff4557cfb 100644 --- a/cmd/minikube/cmd/start_test.go +++ b/cmd/minikube/cmd/start_test.go @@ -97,6 +97,11 @@ func TestMirrorCountry(t *testing.T) { imageRepository: "", mirrorCountry: "", }, + { + description: "image-repository none, image-mirror-country china", + imageRepository: "", + mirrorCountry: "cn", + }, { description: "image-repository auto, image-mirror-country none", imageRepository: "auto", @@ -107,6 +112,16 @@ func TestMirrorCountry(t *testing.T) { imageRepository: "auto", mirrorCountry: "cn", }, + { + description: "image-repository registry.test.com, image-mirror-country none", + imageRepository: "registry.test.com", + mirrorCountry: "", + }, + { + description: "image-repository registry.test.com, image-mirror-country china", + imageRepository: "registry.test.com", + mirrorCountry: "cn", + }, } for _, test := range tests {