Skip to content

Commit

Permalink
Merge pull request #16029 from afbjorklund/kubeadm-registry-flag
Browse files Browse the repository at this point in the history
Always use the new registry.k8s.io repository
  • Loading branch information
medyagh authored Mar 30, 2023
2 parents 5d71a4e + 2010622 commit d6162ec
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 116 deletions.
10 changes: 5 additions & 5 deletions pkg/minikube/bootstrapper/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Pause(v semver.Version, mirror string) string {
imageName := "pause"
pv := imageVersion(v, mirror, imageName, "3.6")

return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror, v), imageName), pv)
return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), imageName), pv)
}

// essentials returns images needed too bootstrap a Kubernetes
Expand All @@ -67,7 +67,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, v), name), v)
return fmt.Sprintf("%s:v%s", path.Join(kubernetesRepo(mirror), name), v)
}

// fixes 13136 by getting the latest image version from the k8s.gcr.io repository instead of hardcoded
Expand Down Expand Up @@ -120,7 +120,7 @@ func coreDNS(v semver.Version, mirror string) string {
imageName = "coredns"
}

return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror, v), imageName), cv)
return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), imageName), cv)
}

// etcd returns the image used for etcd
Expand All @@ -131,15 +131,15 @@ func etcd(v semver.Version, mirror string) string {
imageName := "etcd"
ev := imageVersion(v, mirror, imageName, "3.5.0-0")

return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror, v), imageName), ev)
return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), imageName), ev)
}

func imageVersion(v semver.Version, mirror, imageName, defaultVersion string) string {
versionString := fmt.Sprintf("v%s", v.String())
if ver, ok := constants.KubeadmImages[versionString][imageName]; ok {
return ver
}
return findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror, v), imageName), defaultVersion)
return findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror), imageName), defaultVersion)
}

// auxiliary returns images that are helpful for running minikube
Expand Down
72 changes: 36 additions & 36 deletions pkg/minikube/bootstrapper/images/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,49 @@ func TestEssentials(t *testing.T) {
images []string
}{
{"v1.18.0", strings.Split(strings.Trim(`
k8s.gcr.io/kube-apiserver:v1.18.0
k8s.gcr.io/kube-controller-manager:v1.18.0
k8s.gcr.io/kube-scheduler:v1.18.0
k8s.gcr.io/kube-proxy:v1.18.0
k8s.gcr.io/pause:3.2
k8s.gcr.io/etcd:3.4.3-0
k8s.gcr.io/coredns:1.6.7
registry.k8s.io/kube-apiserver:v1.18.0
registry.k8s.io/kube-controller-manager:v1.18.0
registry.k8s.io/kube-scheduler:v1.18.0
registry.k8s.io/kube-proxy:v1.18.0
registry.k8s.io/pause:3.2
registry.k8s.io/etcd:3.4.3-0
registry.k8s.io/coredns:1.6.7
`, "\n"), "\n")},
{"v1.19.0", strings.Split(strings.Trim(`
k8s.gcr.io/kube-apiserver:v1.19.0
k8s.gcr.io/kube-controller-manager:v1.19.0
k8s.gcr.io/kube-scheduler:v1.19.0
k8s.gcr.io/kube-proxy:v1.19.0
k8s.gcr.io/pause:3.2
k8s.gcr.io/etcd:3.4.9-1
k8s.gcr.io/coredns:1.7.0
registry.k8s.io/kube-apiserver:v1.19.0
registry.k8s.io/kube-controller-manager:v1.19.0
registry.k8s.io/kube-scheduler:v1.19.0
registry.k8s.io/kube-proxy:v1.19.0
registry.k8s.io/pause:3.2
registry.k8s.io/etcd:3.4.9-1
registry.k8s.io/coredns:1.7.0
`, "\n"), "\n")},
{"v1.20.0", strings.Split(strings.Trim(`
k8s.gcr.io/kube-apiserver:v1.20.0
k8s.gcr.io/kube-controller-manager:v1.20.0
k8s.gcr.io/kube-scheduler:v1.20.0
k8s.gcr.io/kube-proxy:v1.20.0
k8s.gcr.io/pause:3.2
k8s.gcr.io/etcd:3.4.13-0
k8s.gcr.io/coredns:1.7.0
registry.k8s.io/kube-apiserver:v1.20.0
registry.k8s.io/kube-controller-manager:v1.20.0
registry.k8s.io/kube-scheduler:v1.20.0
registry.k8s.io/kube-proxy:v1.20.0
registry.k8s.io/pause:3.2
registry.k8s.io/etcd:3.4.13-0
registry.k8s.io/coredns:1.7.0
`, "\n"), "\n")},
{"v1.21.0", strings.Split(strings.Trim(`
k8s.gcr.io/kube-apiserver:v1.21.0
k8s.gcr.io/kube-controller-manager:v1.21.0
k8s.gcr.io/kube-scheduler:v1.21.0
k8s.gcr.io/kube-proxy:v1.21.0
k8s.gcr.io/pause:3.4.1
k8s.gcr.io/etcd:3.4.13-0
k8s.gcr.io/coredns/coredns:v1.8.0
registry.k8s.io/kube-apiserver:v1.21.0
registry.k8s.io/kube-controller-manager:v1.21.0
registry.k8s.io/kube-scheduler:v1.21.0
registry.k8s.io/kube-proxy:v1.21.0
registry.k8s.io/pause:3.4.1
registry.k8s.io/etcd:3.4.13-0
registry.k8s.io/coredns/coredns:v1.8.0
`, "\n"), "\n")},
{"v1.22.0", strings.Split(strings.Trim(`
k8s.gcr.io/kube-apiserver:v1.22.0
k8s.gcr.io/kube-controller-manager:v1.22.0
k8s.gcr.io/kube-scheduler:v1.22.0
k8s.gcr.io/kube-proxy:v1.22.0
k8s.gcr.io/pause:3.5
k8s.gcr.io/etcd:3.5.0-0
k8s.gcr.io/coredns/coredns:v1.8.4
registry.k8s.io/kube-apiserver:v1.22.0
registry.k8s.io/kube-controller-manager:v1.22.0
registry.k8s.io/kube-scheduler:v1.22.0
registry.k8s.io/kube-proxy:v1.22.0
registry.k8s.io/pause:3.5
registry.k8s.io/etcd:3.5.0-0
registry.k8s.io/coredns/coredns:v1.8.4
`, "\n"), "\n")},
}
for _, tc := range testCases {
Expand All @@ -85,7 +85,7 @@ k8s.gcr.io/coredns/coredns:v1.8.4
t.Fatal(err)
}
want := tc.images
got := essentials("k8s.gcr.io", v)
got := essentials("registry.k8s.io", v)
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("images mismatch (-want +got):\n%s", diff)
}
Expand Down
56 changes: 28 additions & 28 deletions pkg/minikube/bootstrapper/images/kubeadm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,43 +75,43 @@ func TestKubeadmImages(t *testing.T) {
"mirror.k8s.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(),
}},
{"v1.24.0", "", false, []string{
"k8s.gcr.io/kube-proxy:v1.24.0",
"k8s.gcr.io/kube-scheduler:v1.24.0",
"k8s.gcr.io/kube-controller-manager:v1.24.0",
"k8s.gcr.io/kube-apiserver: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",
"registry.k8s.io/kube-proxy:v1.24.0",
"registry.k8s.io/kube-scheduler:v1.24.0",
"registry.k8s.io/kube-controller-manager:v1.24.0",
"registry.k8s.io/kube-apiserver:v1.24.0",
"registry.k8s.io/coredns/coredns:v1.8.6",
"registry.k8s.io/etcd:3.5.3-0",
"registry.k8s.io/pause:3.7",
"gcr.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(),
}},
{"v1.23.0", "", false, []string{
"k8s.gcr.io/kube-proxy:v1.23.0",
"k8s.gcr.io/kube-scheduler:v1.23.0",
"k8s.gcr.io/kube-controller-manager:v1.23.0",
"k8s.gcr.io/kube-apiserver:v1.23.0",
"k8s.gcr.io/coredns/coredns:v1.8.6",
"k8s.gcr.io/etcd:3.5.1-0",
"k8s.gcr.io/pause:3.6",
"registry.k8s.io/kube-proxy:v1.23.0",
"registry.k8s.io/kube-scheduler:v1.23.0",
"registry.k8s.io/kube-controller-manager:v1.23.0",
"registry.k8s.io/kube-apiserver:v1.23.0",
"registry.k8s.io/coredns/coredns:v1.8.6",
"registry.k8s.io/etcd:3.5.1-0",
"registry.k8s.io/pause:3.6",
"gcr.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(),
}},
{"v1.22.0", "", false, []string{
"k8s.gcr.io/kube-proxy:v1.22.0",
"k8s.gcr.io/kube-scheduler:v1.22.0",
"k8s.gcr.io/kube-controller-manager:v1.22.0",
"k8s.gcr.io/kube-apiserver:v1.22.0",
"k8s.gcr.io/coredns/coredns:v1.8.4",
"k8s.gcr.io/etcd:3.5.0-0",
"k8s.gcr.io/pause:3.5",
"registry.k8s.io/kube-proxy:v1.22.0",
"registry.k8s.io/kube-scheduler:v1.22.0",
"registry.k8s.io/kube-controller-manager:v1.22.0",
"registry.k8s.io/kube-apiserver:v1.22.0",
"registry.k8s.io/coredns/coredns:v1.8.4",
"registry.k8s.io/etcd:3.5.0-0",
"registry.k8s.io/pause:3.5",
"gcr.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(),
}},
{"v1.16.0", "", false, []string{
"k8s.gcr.io/kube-proxy:v1.16.0",
"k8s.gcr.io/kube-scheduler:v1.16.0",
"k8s.gcr.io/kube-controller-manager:v1.16.0",
"k8s.gcr.io/kube-apiserver:v1.16.0",
"k8s.gcr.io/coredns:1.6.2",
"k8s.gcr.io/etcd:3.3.15-0",
"k8s.gcr.io/pause:3.1",
"registry.k8s.io/kube-proxy:v1.16.0",
"registry.k8s.io/kube-scheduler:v1.16.0",
"registry.k8s.io/kube-controller-manager:v1.16.0",
"registry.k8s.io/kube-apiserver:v1.16.0",
"registry.k8s.io/coredns:1.6.2",
"registry.k8s.io/etcd:3.3.15-0",
"registry.k8s.io/pause:3.1",
"gcr.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(),
}},
{"v1.11.0", "", true, nil},
Expand Down
23 changes: 4 additions & 19 deletions pkg/minikube/bootstrapper/images/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,13 @@ limitations under the License.

package images

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"
// DefaultKubernetesRepo is the default Kubernetes repository
const DefaultKubernetesRepo = "registry.k8s.io"

// kubernetesRepo returns the official Kubernetes repository, or an alternate
func kubernetesRepo(mirror string, v semver.Version) string {
func kubernetesRepo(mirror string) string {
if mirror != "" {
return mirror
}
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
return DefaultKubernetesRepo
}
25 changes: 5 additions & 20 deletions pkg/minikube/bootstrapper/images/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,27 @@ 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
version semver.Version
want string
mirror string
want string
}{
{
"",
kv,
DefaultKubernetesRepo(kv),
DefaultKubernetesRepo,
},
{
"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, tc.version)
got := kubernetesRepo(tc.mirror)
if !cmp.Equal(got, tc.want) {
t.Errorf("mirror miss match, want: %s, got: %s", tc.want, got)
t.Errorf("mirror mismatch, want: %s, got: %s", tc.want, got)
}
}

Expand Down
11 changes: 5 additions & 6 deletions pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,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, cfg.KubernetesConfig.KubernetesVersion)
ip, err := validateNetwork(host, runner, cfg.KubernetesConfig.ImageRepository)
if err != nil {
return runner, preExists, m, host, errors.Wrap(err, "Failed to validate network")
}
Expand Down Expand Up @@ -724,7 +724,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, kubernetesVersion string) (string, error) {
func validateNetwork(h *host.Host, r command.Runner, imageRepository string) (string, error) {
ip, err := h.Driver.GetIP()
if err != nil {
return ip, err
Expand Down Expand Up @@ -756,7 +756,7 @@ func validateNetwork(h *host.Host, r command.Runner, imageRepository string, kub
}

// Non-blocking
go tryRegistry(r, h.Driver.DriverName(), imageRepository, kubernetesVersion, ip)
go tryRegistry(r, h.Driver.DriverName(), imageRepository, ip)
return ip, nil
}

Expand Down Expand Up @@ -812,7 +812,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, kubernetesVersion string, ip string) {
func tryRegistry(r command.Runner, driverName, imageRepository, ip string) {
// 2 second timeout. For best results, call tryRegistry in a non-blocking manner.
opts := []string{"-sS", "-m", "2"}

Expand All @@ -822,8 +822,7 @@ func tryRegistry(r command.Runner, driverName string, imageRepository string, ku
}

if imageRepository == "" {
v, _ := util.ParseKubernetesVersion(kubernetesVersion)
imageRepository = images.DefaultKubernetesRepo(v)
imageRepository = images.DefaultKubernetesRepo
}

opts = append(opts, fmt.Sprintf("https://%s/", imageRepository))
Expand Down
10 changes: 8 additions & 2 deletions test/integration/start_stop_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func testPulledImages(ctx context.Context, t *testing.T, profile, version string

rr, err := Run(t, exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "sudo crictl images -o json"))
if err != nil {
t.Errorf("failed tp get images inside minikube. args %q: %v", rr.Command(), err)
t.Errorf("failed to get images inside minikube. args %q: %v", rr.Command(), err)
}
jv := map[string][]struct {
Tags []string `json:"repoTags"`
Expand All @@ -377,7 +377,13 @@ func testPulledImages(ctx context.Context, t *testing.T, profile, version string
}
}
}
wantRaw, err := images.Kubeadm("", version)

mirror := ""
// Kubernetes versions prior to v1.25 will contain the old registry due to the preload
if v, _ := util.ParseKubernetesVersion(version); v.LT(semver.MustParse("1.25.0-alpha.1")) {
mirror = "k8s.gcr.io"
}
wantRaw, err := images.Kubeadm(mirror, version)
if err != nil {
t.Errorf("failed to get kubeadm images for %s : %v", version, err)
}
Expand Down

0 comments on commit d6162ec

Please sign in to comment.