Skip to content

Commit ce1cc8d

Browse files
authored
Merge pull request #7054 from afbjorklund/image-mirror-version-parse
Strip the version prefix before calling semver
2 parents 361d082 + dc6b9ba commit ce1cc8d

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

cmd/minikube/cmd/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string)
835835
repository := viper.GetString(imageRepository)
836836
mirrorCountry := strings.ToLower(viper.GetString(imageMirrorCountry))
837837
if strings.ToLower(repository) == "auto" || mirrorCountry != "" {
838-
found, autoSelectedRepository, err := selectImageRepository(mirrorCountry, semver.MustParse(k8sVersion))
838+
found, autoSelectedRepository, err := selectImageRepository(mirrorCountry, semver.MustParse(strings.TrimPrefix(k8sVersion, version.VersionPrefix)))
839839
if err != nil {
840840
exit.WithError("Failed to check main repository and mirrors for images for images", err)
841841
}

cmd/minikube/cmd/start_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,50 @@ func TestGetKuberneterVersion(t *testing.T) {
7070
}
7171
}
7272

73+
func TestMirrorCountry(t *testing.T) {
74+
// Set default disk size value in lieu of flag init
75+
viper.SetDefault(humanReadableDiskSize, defaultDiskSize)
76+
77+
k8sVersion := constants.DefaultKubernetesVersion
78+
var tests = []struct {
79+
description string
80+
k8sVersion string
81+
imageRepository string
82+
mirrorCountry string
83+
cfg *cfg.ClusterConfig
84+
}{
85+
{
86+
description: "image-repository none, image-mirror-country none",
87+
imageRepository: "",
88+
mirrorCountry: "",
89+
},
90+
{
91+
description: "image-repository auto, image-mirror-country none",
92+
imageRepository: "auto",
93+
mirrorCountry: "",
94+
},
95+
{
96+
description: "image-repository auto, image-mirror-country china",
97+
imageRepository: "auto",
98+
mirrorCountry: "cn",
99+
},
100+
}
101+
102+
for _, test := range tests {
103+
t.Run(test.description, func(t *testing.T) {
104+
cmd := &cobra.Command{}
105+
viper.SetDefault(imageRepository, test.imageRepository)
106+
viper.SetDefault(imageMirrorCountry, test.mirrorCountry)
107+
config, _, err := generateCfgFromFlags(cmd, k8sVersion, "none")
108+
if err != nil {
109+
t.Fatalf("Got unexpected error %v during config generation", err)
110+
}
111+
// the result can still be "", but anyway
112+
_ = config.KubernetesConfig.ImageRepository
113+
})
114+
}
115+
}
116+
73117
func TestGenerateCfgFromFlagsHTTPProxyHandling(t *testing.T) {
74118
// Set default disk size value in lieu of flag init
75119
viper.SetDefault(humanReadableDiskSize, defaultDiskSize)

0 commit comments

Comments
 (0)