Merge pull request #7054 from afbjorklund/image-mirror-version-parse
Strip the version prefix before calling semverpull/7089/head
commit
ce1cc8d34c
|
|
@ -835,7 +835,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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue