Repository: kubernetes/minikube
Pull request #14768 (2022-08-09 20:16:16)

The DefaultKubernetesRepo changed for 1.25.0
See: https://github.com/kubernetes/kubernetes/commit/50bea1dad89930ad565526910aadc314b9e9f38b

* https://github.com/kubernetes/kubeadm/issues/2671

Changing the old releases would mean having to redo the old preload as well.

But it could be a good idea to make sure that 1.25.0 comes out the right way...

k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes/minikube/pull/14768#" title="Author self-approved">afbjorklund</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes%2Fminikube).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubernetes/minikube/blob/master/OWNERS)~~ [afbjorklund]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/pkg/minikube/bootstrapper/images/images.go b/pkg/minikube/bootstrapper/images/images.go
index 81f621006..eb37ad053 100644
--- a/pkg/minikube/bootstrapper/images/images.go
+++ b/pkg/minikube/bootstrapper/images/images.go
@@ -51,10 +51,10 @@ func Pause(v semver.Version, mirror string) string {
 	if pVersion, ok := constants.KubeadmImages[majorMinorVersion][imageName]; ok {
 		pv = pVersion
 	} else {
-		pv = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror), imageName), pv)
+		pv = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror, v), imageName), pv)
 	}
 
-	return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), imageName), pv)
+	return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror, v), imageName), pv)
 }
 
 // essentials returns images needed too bootstrap a Kubernetes
@@ -74,7 +74,7 @@ func essentials(mirror string, v semver.Version) []string {
 
 // componentImage returns a Kubernetes component image to pull
 func componentImage(name string, v semver.Version, mirror string) string {
-	return fmt.Sprintf("%s:v%s", path.Join(kubernetesRepo(mirror), name), v)
+	return fmt.Sprintf("%s:v%s", path.Join(kubernetesRepo(mirror, v), name), v)
 }
 
 // fixes 13136 by getting the latest image version from the k8s.gcr.io repository instead of hardcoded
@@ -127,14 +127,14 @@ func coreDNS(v semver.Version, mirror string) string {
 	if cVersion, ok := constants.KubeadmImages[majorMinorVersion][imageName]; ok {
 		cv = cVersion
 	} else {
-		cv = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror), imageName), cv)
+		cv = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror, v), imageName), cv)
 	}
 
 	if mirror == constants.AliyunMirror {
 		imageName = "coredns"
 	}
 
-	return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), imageName), cv)
+	return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror, v), imageName), cv)
 }
 
 // etcd returns the image used for etcd
@@ -148,10 +148,10 @@ func etcd(v semver.Version, mirror string) string {
 	if eVersion, ok := constants.KubeadmImages[majorMinorVersion][imageName]; ok {
 		ev = eVersion
 	} else {
-		ev = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror), imageName), ev)
+		ev = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror, v), imageName), ev)
 	}
 
-	return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), imageName), ev)
+	return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror, v), imageName), ev)
 }
 
 // auxiliary returns images that are helpful for running minikube
diff --git a/pkg/minikube/bootstrapper/images/repo.go b/pkg/minikube/bootstrapper/images/repo.go
index dbd25d454..956d9d13f 100644
--- a/pkg/minikube/bootstrapper/images/repo.go
+++ b/pkg/minikube/bootstrapper/images/repo.go
@@ -16,13 +16,28 @@ limitations under the License.
 
 package images
 
-// DefaultKubernetesRepo is the default Kubernetes repository
-const DefaultKubernetesRepo = "k8s.gcr.io"
+import (
+	"github.com/blang/semver/v4"
+)
+
+// OldDefaultKubernetesRepo is the old default Kubernetes repository
+const OldDefaultKubernetesRepo = "k8s.gcr.io"
+
+// NewDefaultKubernetesRepo is the new default Kubernetes repository
+const NewDefaultKubernetesRepo = "registry.k8s.io"
 
 // kubernetesRepo returns the official Kubernetes repository, or an alternate
-func kubernetesRepo(mirror string) string {
+func kubernetesRepo(mirror string, v semver.Version) string {
 	if mirror != "" {
 		return mirror
 	}
-	return DefaultKubernetesRepo
+	return DefaultKubernetesRepo(v)
+}
+
+func DefaultKubernetesRepo(kv semver.Version) string {
+	// these (-1.24) should probably be moved too
+	if kv.LT(semver.MustParse("1.25.0-alpha.1")) {
+		return OldDefaultKubernetesRepo
+	}
+	return NewDefaultKubernetesRepo
 }
diff --git a/pkg/minikube/node/start.go b/pkg/minikube/node/start.go
index 076405202..2217f52f2 100644
--- a/pkg/minikube/node/start.go
+++ b/pkg/minikube/node/start.go
@@ -556,7 +556,7 @@ func startMachine(cfg *config.ClusterConfig, node *config.Node, delOnFail bool)
 		return runner, preExists, m, host, errors.Wrap(err, "Failed to get command runner")
 	}
 
-	ip, err := validateNetwork(host, runner, cfg.KubernetesConfig.ImageRepository)
+	ip, err := validateNetwork(host, runner, cfg.KubernetesConfig.ImageRepository, cfg.KubernetesConfig.KubernetesVersion)
 	if err != nil {
 		return runner, preExists, m, host, errors.Wrap(err, "Failed to validate network")
 	}
@@ -639,7 +639,7 @@ func startHostInternal(api libmachine.API, cc *config.ClusterConfig, n *config.N
 }
 
 // validateNetwork tries to catch network problems as soon as possible
-func validateNetwork(h *host.Host, r command.Runner, imageRepository string) (string, error) {
+func validateNetwork(h *host.Host, r command.Runner, imageRepository string, kubernetesVersion string) (string, error) {
 	ip, err := h.Driver.GetIP()
 	if err != nil {
 		return ip, err
@@ -671,7 +671,7 @@ func validateNetwork(h *host.Host, r command.Runner, imageRepository string) (st
 	}
 
 	// Non-blocking
-	go tryRegistry(r, h.Driver.DriverName(), imageRepository)
+	go tryRegistry(r, h.Driver.DriverName(), imageRepository, kubernetesVersion)
 	return ip, nil
 }
 
@@ -716,7 +716,7 @@ func trySSH(h *host.Host, ip string) error {
 }
 
 // tryRegistry tries to connect to the image repository
-func tryRegistry(r command.Runner, driverName string, imageRepository string) {
+func tryRegistry(r command.Runner, driverName string, imageRepository string, kubernetesVersion string) {
 	// 2 second timeout. For best results, call tryRegistry in a non-blocking manner.
 	opts := []string{"-sS", "-m", "2"}
 
@@ -726,7 +726,8 @@ func tryRegistry(r command.Runner, driverName string, imageRepository string) {
 	}
 
 	if imageRepository == "" {
-		imageRepository = images.DefaultKubernetesRepo
+		v, _ := util.ParseKubernetesVersion(kubernetesVersion)
+		imageRepository = images.DefaultKubernetesRepo(v)
 	}
 
 	opts = append(opts, fmt.Sprintf("https://%s/", imageRepository))


Test patch:
diff --git a/pkg/minikube/bootstrapper/images/kubeadm_test.go b/pkg/minikube/bootstrapper/images/kubeadm_test.go
index 150a3a9bf..eba62f256 100644
--- a/pkg/minikube/bootstrapper/images/kubeadm_test.go
+++ b/pkg/minikube/bootstrapper/images/kubeadm_test.go
@@ -34,6 +34,26 @@ func TestKubeadmImages(t *testing.T) {
 		{"invalid", "", true, nil},
 		{"v0.0.1", "", true, nil}, // too old
 		{"v2.0.0", "", true, nil}, // too new
+		{"v1.25.0", "", false, []string{
+			"registry.k8s.io/kube-apiserver:v1.25.0",
+			"registry.k8s.io/kube-controller-manager:v1.25.0",
+			"registry.k8s.io/kube-scheduler:v1.25.0",
+			"registry.k8s.io/kube-proxy:v1.25.0",
+			"registry.k8s.io/coredns/coredns:v1.9.3",
+			"registry.k8s.io/etcd:3.5.4-0",
+			"registry.k8s.io/pause:3.8",
+			"gcr.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(),
+		}},
+		{"v1.24.0", "", false, []string{
+			"k8s.gcr.io/kube-apiserver:v1.24.0",
+			"k8s.gcr.io/kube-controller-manager:v1.24.0",
+			"k8s.gcr.io/kube-scheduler:v1.24.0",
+			"k8s.gcr.io/kube-proxy:v1.24.0",
+			"k8s.gcr.io/coredns/coredns:v1.8.6",
+			"k8s.gcr.io/etcd:3.5.3-0",
+			"k8s.gcr.io/pause:3.7",
+			"gcr.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(),
+		}},
 		{"v1.17.0", "", false, []string{
 			"k8s.gcr.io/kube-proxy:v1.17.0",
 			"k8s.gcr.io/kube-scheduler:v1.17.0",
diff --git a/pkg/minikube/bootstrapper/images/repo_test.go b/pkg/minikube/bootstrapper/images/repo_test.go
index 5621003dd..9167befd7 100644
--- a/pkg/minikube/bootstrapper/images/repo_test.go
+++ b/pkg/minikube/bootstrapper/images/repo_test.go
@@ -19,25 +19,40 @@ package images
 import (
 	"testing"
 
+	"github.com/blang/semver/v4"
 	"github.com/google/go-cmp/cmp"
 )
 
 func Test_kubernetesRepo(t *testing.T) {
+	kv := semver.MustParse("1.23.0")
 	tests := []struct {
-		mirror string
-		want   string
+		mirror  string
+		version semver.Version
+		want    string
 	}{
 		{
 			"",
-			DefaultKubernetesRepo,
+			kv,
+			DefaultKubernetesRepo(kv),
 		},
 		{
 			"mirror.k8s.io",
+			kv,
 			"mirror.k8s.io",
 		},
+		{
+			"",
+			semver.MustParse("1.24.0"),
+			OldDefaultKubernetesRepo,
+		},
+		{
+			"",
+			semver.MustParse("1.25.0"),
+			NewDefaultKubernetesRepo,
+		},
 	}
 	for _, tc := range tests {
-		got := kubernetesRepo(tc.mirror)
+		got := kubernetesRepo(tc.mirror, tc.version)
 		if !cmp.Equal(got, tc.want) {
 			t.Errorf("mirror miss match, want: %s, got: %s", tc.want, got)
 		}