diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 44e3d3210c1d..8b55075e9f75 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -822,7 +822,7 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) repository := viper.GetString(imageRepository) mirrorCountry := strings.ToLower(viper.GetString(imageMirrorCountry)) if strings.ToLower(repository) == "auto" || mirrorCountry != "" { - found, autoSelectedRepository, err := selectImageRepository(mirrorCountry, semver.MustParse(k8sVersion)) + 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 for images", err) } diff --git a/cmd/minikube/cmd/start_test.go b/cmd/minikube/cmd/start_test.go index 23675528b67c..ef7e4b74033f 100644 --- a/cmd/minikube/cmd/start_test.go +++ b/cmd/minikube/cmd/start_test.go @@ -70,6 +70,50 @@ func TestGetKuberneterVersion(t *testing.T) { } } +func TestMirrorCountry(t *testing.T) { + // Set default disk size value in lieu of flag init + viper.SetDefault(humanReadableDiskSize, defaultDiskSize) + + k8sVersion := constants.DefaultKubernetesVersion + var tests = []struct { + description string + k8sVersion string + imageRepository string + mirrorCountry string + cfg *cfg.ClusterConfig + }{ + { + description: "image-repository none, image-mirror-country none", + imageRepository: "", + mirrorCountry: "", + }, + { + description: "image-repository auto, image-mirror-country none", + imageRepository: "auto", + mirrorCountry: "", + }, + { + description: "image-repository auto, image-mirror-country china", + imageRepository: "auto", + mirrorCountry: "cn", + }, + } + + for _, test := range tests { + t.Run(test.description, func(t *testing.T) { + cmd := &cobra.Command{} + viper.SetDefault(imageRepository, test.imageRepository) + viper.SetDefault(imageMirrorCountry, test.mirrorCountry) + config, _, err := generateCfgFromFlags(cmd, k8sVersion, "none") + if err != nil { + t.Fatalf("Got unexpected error %v during config generation", err) + } + // the result can still be "", but anyway + _ = config.KubernetesConfig.ImageRepository + }) + } +} + func TestGenerateCfgFromFlagsHTTPProxyHandling(t *testing.T) { // Set default disk size value in lieu of flag init viper.SetDefault(humanReadableDiskSize, defaultDiskSize)