From 5f46b98eaea35de9d2e73688f70a6f6ab65fa2bb Mon Sep 17 00:00:00 2001 From: "srikrishnabh93@gmail.com" Date: Tue, 27 Jul 2021 23:41:17 +0530 Subject: [PATCH 1/9] initial fix on update kubeadm images automatically --- .../update_kubeadm_image_versions.go | 197 ++++++++++++++++++ hack/update/update.go | 3 + pkg/minikube/bootstrapper/images/images.go | 99 ++++++--- .../bootstrapper/images/kubeadm_test.go | 24 ++- pkg/minikube/bootstrapper/images/repo.go | 5 +- pkg/minikube/bootstrapper/images/repo_test.go | 70 +++++++ .../constants/constants_kubeadm_images.go | 148 +++++++++++++ 7 files changed, 501 insertions(+), 45 deletions(-) create mode 100644 hack/update/kubeadm_image_version/update_kubeadm_image_versions.go create mode 100644 pkg/minikube/bootstrapper/images/repo_test.go create mode 100644 pkg/minikube/constants/constants_kubeadm_images.go diff --git a/hack/update/kubeadm_image_version/update_kubeadm_image_versions.go b/hack/update/kubeadm_image_version/update_kubeadm_image_versions.go new file mode 100644 index 000000000000..8b59265b96a8 --- /dev/null +++ b/hack/update/kubeadm_image_version/update_kubeadm_image_versions.go @@ -0,0 +1,197 @@ +/* +Copyright 2021 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "bytes" + "context" + "errors" + "flag" + "fmt" + "io" + "net/http" + "os" + "os/exec" + "strings" + "text/template" + "time" + + "golang.org/x/mod/semver" + "k8s.io/klog/v2" + "k8s.io/minikube/hack/update" + "k8s.io/minikube/pkg/minikube/constants" +) + +const ( + // default context timeout + cxTimeout = 300 * time.Second + kubeadmReleaseURL = "https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/amd64/kubeadm" + kubeadmBinaryName = "kubeadm-linux-amd64-%s" + minikubeConstantsFilePath = "pkg/minikube/constants/constants_kubeadm_images.go" + kubeadmImagesTemplate = ` + {{- range $version, $element := .}} + "{{$version}}": { + {{- range $image, $tag := $element}} + "{{$image}}": "{{$tag}}", + {{- end}} + },{{- end}}` +) + +// Data contains kubeadm Images map +type Data struct { + ImageMap string `json:"ImageMap"` +} + +func main() { + + inputVersion := flag.Lookup("kubernetes-version").Value.String() + + imageVersions := make([]string, 0) + + // set a context with defined timeout + ctx, cancel := context.WithTimeout(context.Background(), cxTimeout) + defer cancel() + + if inputVersion == "latest" { + stableImageVersion, latestImageVersion, _, _, err := getK8sVersions(ctx, "kubernetes", "kubernetes") + if err != nil { + klog.Fatal(err) + } + imageVersions = append(imageVersions, stableImageVersion, latestImageVersion) + } else if semver.IsValid(inputVersion) { + imageVersions = append(imageVersions, inputVersion) + } else { + klog.Fatal(errors.New("invalid version")) + } + + for _, imageVersion := range imageVersions { + imageMapString, err := getKubeadmImagesMapString(imageVersion) + if err != nil { + klog.Fatalln(err) + } + + data := Data{ImageMap: imageMapString} + schema := map[string]update.Item{ + minikubeConstantsFilePath: { + Replace: map[string]string{}, + }, + } + + if _, ok := constants.KubeadmImages[imageVersion]; !ok { + schema[minikubeConstantsFilePath].Replace[`KubeadmImages = .*`] = + `KubeadmImages = map[string]map[string]string{ {{.ImageMap}}` + } else { + versionIdentifier := fmt.Sprintf(`"%s": {[^}]+},`, imageVersion) + schema[minikubeConstantsFilePath].Replace[versionIdentifier] = "{{.ImageMap}}" + } + + update.Apply(ctx, schema, data, "", "", -1) + } +} + +func getKubeadmImagesMapString(version string) (string, error) { + url := fmt.Sprintf(kubeadmReleaseURL, version) + fileName := fmt.Sprintf(kubeadmBinaryName, version) + if err := downloadFile(url, fileName); err != nil { + return "", err + } + + kubeadmCommand := fmt.Sprintf("./%s", fileName) + args := []string{"config", "images", "list"} + imageListString, err := executeCommand(kubeadmCommand, args...) + if err != nil { + return "", err + } + + if err := os.Remove(fileName); err != nil { + klog.Errorf("failed to remove binary %s", fileName) + } + + return formatKubeadmImageList(version, imageListString) +} + +func formatKubeadmImageList(version, data string) (string, error) { + templateData := make(map[string]map[string]string) + templateData[version] = make(map[string]string) + lines := strings.Split(data, "\n") + for _, line := range lines { + imageTag := strings.Split(line, ":") + if len(imageTag) == 2 { + templateData[version][imageTag[0]] = imageTag[1] + } + } + + imageTemplate := template.New("kubeadmImage") + t, err := imageTemplate.Parse(kubeadmImagesTemplate) + if err != nil { + return "", err + } + + var bytesBuffer bytes.Buffer + if err := t.Execute(&bytesBuffer, &templateData); err != nil { + return "", err + } + + return bytesBuffer.String(), nil +} + +func downloadFile(url, fileName string) error { + file, err := os.Create(fileName) + if err != nil { + return err + } + defer file.Close() + + response, err := http.Get(url) + if err != nil { + return err + } + defer response.Body.Close() + + if response.StatusCode != http.StatusOK { + return fmt.Errorf("non success status code, while downloading file: %s from: %s", fileName, url) + } + + if _, err := io.Copy(file, response.Body); err != nil { + return err + } + + return os.Chmod(fileName, os.ModePerm) +} + +func executeCommand(command string, args ...string) (string, error) { + output, err := exec.Command(command, args...).Output() + if err != nil { + return "", err + } + return string(output), nil +} + +// getK8sVersion returns Kubernetes versions. +func getK8sVersions(ctx context.Context, owner, repo string) (stable, latest, latestMM, latestP0 string, err error) { + // get Kubernetes versions from GitHub Releases + stable, latest, err = update.GHReleases(ctx, owner, repo) + if err != nil || !semver.IsValid(stable) || !semver.IsValid(latest) { + return "", "", "", "", err + } + latestMM = semver.MajorMinor(latest) + latestP0 = latestMM + ".0" + if semver.Compare(stable, latestP0) == -1 { + latestP0 = latest + } + return stable, latest, latestMM, latestP0, nil +} diff --git a/hack/update/update.go b/hack/update/update.go index dbf70619995b..f7732f7bfa37 100644 --- a/hack/update/update.go +++ b/hack/update/update.go @@ -62,6 +62,9 @@ func init() { if err := flag.Set("alsologtostderr", "true"); err != nil { klog.Warningf("Unable to set flag value for alsologtostderr: %v", err) } + + // used in update_kubeadm_image_versions.go + flag.String("kubernetes-version", "", "kubernetes-version") flag.Parse() defer klog.Flush() diff --git a/pkg/minikube/bootstrapper/images/images.go b/pkg/minikube/bootstrapper/images/images.go index a3de6b1414f9..362702407c2d 100644 --- a/pkg/minikube/bootstrapper/images/images.go +++ b/pkg/minikube/bootstrapper/images/images.go @@ -21,6 +21,8 @@ import ( "fmt" "path" + "k8s.io/minikube/pkg/minikube/constants" + "github.com/blang/semver" "k8s.io/minikube/pkg/version" @@ -31,10 +33,18 @@ func Pause(v semver.Version, mirror string) string { // Should match `PauseVersion` in: // https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/constants/constants_unix.go pv := "3.2" + k8sVersion := fmt.Sprintf("v1.%d.0", v.Minor) + imageName := path.Join(kubernetesRepo(mirror), "pause") + + if _, ok := constants.KubeadmImages[k8sVersion]; ok { + pv = constants.KubeadmImages[k8sVersion][imageName] + } + if semver.MustParseRange("<1.18.0-alpha.0")(v) { pv = "3.1" } - return path.Join(kubernetesRepo(mirror), "pause:"+pv) + + return fmt.Sprintf("%s:%s", imageName, pv) } // essentials returns images needed too bootstrap a Kubernetes @@ -60,28 +70,44 @@ func componentImage(name string, v semver.Version, mirror string) string { func coreDNS(v semver.Version, mirror string) string { // Should match `CoreDNSVersion` in // https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/constants/constants.go + /*cv := "1.7.0" + + //switch v.Minor { + //case 22: + // cv = "1.8.0" + //case 10, 20, 21: + // cv = "1.7.0" + //case 18: + // cv = "1.6.7" + //case 17: + // cv = "1.6.5" + //case 16: + // cv = "1.6.2" + //case 15, 14: + // cv = "1.3.1" + //case 13: + // cv = "1.2.6" + //case 12: + // cv = "1.2.2" + //case 11: + // cv = "1.1.3" + //} + */ + cv := "1.7.0" - switch v.Minor { - case 22: - cv = "1.8.0" - case 10, 20, 21: - cv = "1.7.0" - case 18: - cv = "1.6.7" - case 17: - cv = "1.6.5" - case 16: - cv = "1.6.2" - case 15, 14: - cv = "1.3.1" - case 13: - cv = "1.2.6" - case 12: - cv = "1.2.2" - case 11: - cv = "1.1.3" + k8sVersion := fmt.Sprintf("v1.%d.0", v.Minor) + imageName := path.Join(kubernetesRepo(mirror), "coredns") + + if v.Minor >= 21 { + imageName = path.Join(imageName, "coredns") } - return path.Join(kubernetesRepo(mirror), "coredns:"+cv) + + if _, ok := constants.KubeadmImages[k8sVersion]; ok { + cv = constants.KubeadmImages[k8sVersion][imageName] + } + + // return path.Join(kubernetesRepo(mirror), "coredns:"+cv) + return fmt.Sprintf("%s:%s", imageName, cv) } // etcd returns the image used for etcd @@ -90,17 +116,24 @@ func etcd(v semver.Version, mirror string) string { // https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/constants/constants.go ev := "3.4.13-0" - switch v.Minor { - case 17, 18: - ev = "3.4.3-0" - case 16: - ev = "3.3.15-0" - case 14, 15: - ev = "3.3.10" - case 12, 13: - ev = "3.2.24" - case 11: - ev = "3.2.18" + /*switch v.Minor { + //case 17, 18: + // ev = "3.4.3-0" + //case 16: + // ev = "3.3.15-0" + //case 14, 15: + // ev = "3.3.10" + //case 12, 13: + // ev = "3.2.24" + //case 11: + // ev = "3.2.18" + //} + */ + k8sVersion := fmt.Sprintf("v1.%d.0", v.Minor) + imageName := path.Join(kubernetesRepo(mirror), "etcd") + + if _, ok := constants.KubeadmImages[k8sVersion]; ok { + ev = constants.KubeadmImages[k8sVersion][imageName] } // An awkward special case for v1.19.0 - do not imitate unless necessary @@ -108,7 +141,7 @@ func etcd(v semver.Version, mirror string) string { ev = "3.4.9-1" } - return path.Join(kubernetesRepo(mirror), "etcd:"+ev) + return fmt.Sprintf("%s:%s", imageName, ev) } // auxiliary returns images that are helpful for running minikube diff --git a/pkg/minikube/bootstrapper/images/kubeadm_test.go b/pkg/minikube/bootstrapper/images/kubeadm_test.go index 238c068d38a4..66f1d95ed056 100644 --- a/pkg/minikube/bootstrapper/images/kubeadm_test.go +++ b/pkg/minikube/bootstrapper/images/kubeadm_test.go @@ -17,6 +17,7 @@ limitations under the License. package images import ( + "fmt" "sort" "testing" @@ -42,17 +43,17 @@ func TestKubeadmImages(t *testing.T) { "docker.io/kubernetesui/dashboard:v2.1.0", "docker.io/kubernetesui/metrics-scraper:v1.0.4", }}, - {"v1.16.1", "mirror.k8s.io", []string{ - "mirror.k8s.io/kube-proxy:v1.16.1", - "mirror.k8s.io/kube-scheduler:v1.16.1", - "mirror.k8s.io/kube-controller-manager:v1.16.1", - "mirror.k8s.io/kube-apiserver:v1.16.1", - "mirror.k8s.io/coredns:1.6.2", - "mirror.k8s.io/etcd:3.3.15-0", - "mirror.k8s.io/pause:3.1", - "mirror.k8s.io/storage-provisioner:" + version.GetStorageProvisionerVersion(), - "mirror.k8s.io/dashboard:v2.1.0", - "mirror.k8s.io/metrics-scraper:v1.0.4", + {"v1.16.0", "k8s.gcr.io", []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", + "k8s.gcr.io/storage-provisioner:" + version.GetStorageProvisionerVersion(), + "k8s.gcr.io/dashboard:v2.1.0", + "k8s.gcr.io/metrics-scraper:v1.0.4", }}, {"v1.15.0", "", []string{ "k8s.gcr.io/kube-proxy:v1.15.0", @@ -111,6 +112,7 @@ func TestKubeadmImages(t *testing.T) { sort.Strings(got) sort.Strings(tc.want) if diff := cmp.Diff(tc.want, got); diff != "" { + fmt.Println(diff) t.Errorf("%s images mismatch (-want +got):\n%s", tc.version, diff) } } diff --git a/pkg/minikube/bootstrapper/images/repo.go b/pkg/minikube/bootstrapper/images/repo.go index ca9e3c366a86..437f520f113f 100644 --- a/pkg/minikube/bootstrapper/images/repo.go +++ b/pkg/minikube/bootstrapper/images/repo.go @@ -19,6 +19,9 @@ package images // DefaultKubernetesRepo is the default Kubernetes repository const DefaultKubernetesRepo = "k8s.gcr.io" +// DefaultMinikubeRepo is the default Minikube repository +const DefaultMinikubeRepo = "gcr.io/k8s-minikube" + // kubernetesRepo returns the official Kubernetes repository, or an alternate func kubernetesRepo(mirror string) string { if mirror != "" { @@ -32,5 +35,5 @@ func minikubeRepo(mirror string) string { if mirror != "" { return mirror } - return "gcr.io/k8s-minikube" + return DefaultMinikubeRepo } diff --git a/pkg/minikube/bootstrapper/images/repo_test.go b/pkg/minikube/bootstrapper/images/repo_test.go new file mode 100644 index 000000000000..dc0bcf485013 --- /dev/null +++ b/pkg/minikube/bootstrapper/images/repo_test.go @@ -0,0 +1,70 @@ +/* +Copyright 2021 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package images + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func Test_kubernetesRepo(t *testing.T) { + tests := []struct { + mirror string + want string + }{ + { + "", + DefaultKubernetesRepo, + }, + { + "mirror.k8s.io", + "mirror.k8s.io", + }, + } + for _, tc := range tests { + got := kubernetesRepo(tc.mirror) + if !cmp.Equal(got, tc.want) { + t.Errorf("mirror miss match, want: %s, got: %s", tc.want, got) + } + } + +} + +func Test_minikubeRepo(t *testing.T) { + tests := []struct { + mirror string + want string + }{ + { + "", + DefaultMinikubeRepo, + }, + { + "mirror.k8s.io", + "mirror.k8s.io", + }, + } + + for _, tc := range tests { + got := minikubeRepo(tc.mirror) + if !cmp.Equal(got, tc.want) { + t.Errorf("mirror miss match, want: %s, got: %s", tc.want, got) + } + } + +} diff --git a/pkg/minikube/constants/constants_kubeadm_images.go b/pkg/minikube/constants/constants_kubeadm_images.go new file mode 100644 index 000000000000..04843cd57b68 --- /dev/null +++ b/pkg/minikube/constants/constants_kubeadm_images.go @@ -0,0 +1,148 @@ +/* +Copyright 2021 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package constants + +var ( + KubeadmImages = map[string]map[string]string{ + "v1.22.0-rc.0": { + "k8s.gcr.io/coredns/coredns": "v1.8.4", + "k8s.gcr.io/etcd": "3.4.13-0", + "k8s.gcr.io/kube-apiserver": "v1.21.3", + "k8s.gcr.io/kube-controller-manager": "v1.21.3", + "k8s.gcr.io/kube-proxy": "v1.21.3", + "k8s.gcr.io/kube-scheduler": "v1.21.3", + "k8s.gcr.io/pause": "3.5", + }, + "v1.21.3": { + "k8s.gcr.io/coredns/coredns": "v1.8.0", + "k8s.gcr.io/etcd": "3.4.13-0", + "k8s.gcr.io/kube-apiserver": "v1.21.3", + "k8s.gcr.io/kube-controller-manager": "v1.21.3", + "k8s.gcr.io/kube-proxy": "v1.21.3", + "k8s.gcr.io/kube-scheduler": "v1.21.3", + "k8s.gcr.io/pause": "3.4.1", + }, + "v1.21.0": { + "k8s.gcr.io/coredns/coredns": "v1.8.0", + "k8s.gcr.io/etcd": "3.4.13-0", + "k8s.gcr.io/kube-apiserver": "v1.21.3", + "k8s.gcr.io/kube-controller-manager": "v1.21.3", + "k8s.gcr.io/kube-proxy": "v1.21.3", + "k8s.gcr.io/kube-scheduler": "v1.21.3", + "k8s.gcr.io/pause": "3.4.1", + }, + "v1.20.0": { + "k8s.gcr.io/coredns": "1.7.0", + "k8s.gcr.io/etcd": "3.4.13-0", + "k8s.gcr.io/kube-apiserver": "v1.20.9", + "k8s.gcr.io/kube-controller-manager": "v1.20.9", + "k8s.gcr.io/kube-proxy": "v1.20.9", + "k8s.gcr.io/kube-scheduler": "v1.20.9", + "k8s.gcr.io/pause": "3.2", + }, + "v1.19.0": { + "k8s.gcr.io/coredns": "1.7.0", + "k8s.gcr.io/etcd": "3.4.9-1", + "k8s.gcr.io/kube-apiserver": "v1.19.13", + "k8s.gcr.io/kube-controller-manager": "v1.19.13", + "k8s.gcr.io/kube-proxy": "v1.19.13", + "k8s.gcr.io/kube-scheduler": "v1.19.13", + "k8s.gcr.io/pause": "3.2", + }, + "v1.18.0": { + "k8s.gcr.io/coredns": "1.6.7", + "k8s.gcr.io/etcd": "3.4.3-0", + "k8s.gcr.io/kube-apiserver": "v1.18.20", + "k8s.gcr.io/kube-controller-manager": "v1.18.20", + "k8s.gcr.io/kube-proxy": "v1.18.20", + "k8s.gcr.io/kube-scheduler": "v1.18.20", + "k8s.gcr.io/pause": "3.2", + }, + "v1.17.0": { + "k8s.gcr.io/coredns": "1.6.5", + "k8s.gcr.io/etcd": "3.4.3-0", + "k8s.gcr.io/kube-apiserver": "v1.17.17", + "k8s.gcr.io/kube-controller-manager": "v1.17.17", + "k8s.gcr.io/kube-proxy": "v1.17.17", + "k8s.gcr.io/kube-scheduler": "v1.17.17", + "k8s.gcr.io/pause": "3.1", + }, + "v1.16.1": { + "mirror.k8s.io/kube-proxy": "v1.16.1", + "mirror.k8s.io/kube-scheduler": "v1.16.1", + "mirror.k8s.io/kube-controller-manager": "v1.16.1", + "mirror.k8s.io/kube-apiserver": "v1.16.1", + "mirror.k8s.io/coredns": "1.6.2", + "mirror.k8s.io/etcd": "3.3.15-0", + "mirror.k8s.io/pause": "3.1", + }, + "v1.16.0": { + "k8s.gcr.io/coredns": "1.6.2", + "k8s.gcr.io/etcd": "3.3.15-0", + "k8s.gcr.io/kube-apiserver": "v1.16.15", + "k8s.gcr.io/kube-controller-manager": "v1.16.15", + "k8s.gcr.io/kube-proxy": "v1.16.15", + "k8s.gcr.io/kube-scheduler": "v1.16.15", + "k8s.gcr.io/pause": "3.1", + }, + "v1.15.0": { + "k8s.gcr.io/coredns": "1.3.1", + "k8s.gcr.io/etcd": "3.3.10", + "k8s.gcr.io/kube-apiserver": "v1.15.12", + "k8s.gcr.io/kube-controller-manager": "v1.15.12", + "k8s.gcr.io/kube-proxy": "v1.15.12", + "k8s.gcr.io/kube-scheduler": "v1.15.12", + "k8s.gcr.io/pause": "3.1", + }, + "v1.14.0": { + "k8s.gcr.io/coredns": "1.3.1", + "k8s.gcr.io/etcd": "3.3.10", + "k8s.gcr.io/kube-apiserver": "v1.14.10", + "k8s.gcr.io/kube-controller-manager": "v1.14.10", + "k8s.gcr.io/kube-proxy": "v1.14.10", + "k8s.gcr.io/kube-scheduler": "v1.14.10", + "k8s.gcr.io/pause": "3.1", + }, + "v1.13.0": { + "k8s.gcr.io/coredns": "1.2.6", + "k8s.gcr.io/etcd": "3.2.24", + "k8s.gcr.io/kube-apiserver": "v1.13.12", + "k8s.gcr.io/kube-controller-manager": "v1.13.12", + "k8s.gcr.io/kube-proxy": "v1.13.12", + "k8s.gcr.io/kube-scheduler": "v1.13.12", + "k8s.gcr.io/pause": "3.1", + }, + "v1.12.0": { + "k8s.gcr.io/coredns": "1.2.2", + "k8s.gcr.io/etcd": "3.2.24", + "k8s.gcr.io/kube-apiserver": "v1.21.3", + "k8s.gcr.io/kube-controller-manager": "v1.21.3", + "k8s.gcr.io/kube-proxy": "v1.21.3", + "k8s.gcr.io/kube-scheduler": "v1.21.3", + "k8s.gcr.io/pause": "3.1", + }, + "v1.11.0": { + "k8s.gcr.io/coredns": "1.1.3", + "k8s.gcr.io/etcd-amd64": "3.2.18", + "k8s.gcr.io/kube-apiserver-amd64": "v1.11.10", + "k8s.gcr.io/kube-controller-manager-amd64": "v1.11.10", + "k8s.gcr.io/kube-proxy-amd64": "v1.11.10", + "k8s.gcr.io/kube-scheduler-amd64": "v1.11.10", + "k8s.gcr.io/pause-amd64": "3.1", + }, + } +) From 8f0483461b569171df1961b212e8d3a4d2405038 Mon Sep 17 00:00:00 2001 From: "srikrishnabh93@gmail.com" Date: Sat, 31 Jul 2021 23:20:32 +0530 Subject: [PATCH 2/9] added makefile target --- Makefile | 5 +++ .../update_kubeadm_constants.go} | 14 ++++-- hack/update/update.go | 2 +- pkg/minikube/bootstrapper/images/images.go | 19 ++++---- .../constants/constants_kubeadm_images.go | 44 ++++++------------- 5 files changed, 40 insertions(+), 44 deletions(-) rename hack/update/{kubeadm_image_version/update_kubeadm_image_versions.go => kubeadm_constants/update_kubeadm_constants.go} (89%) diff --git a/Makefile b/Makefile index c4bfe0497b4c..674b637c7ce0 100644 --- a/Makefile +++ b/Makefile @@ -932,6 +932,11 @@ else go run update_kubernetes_version.go) endif +.PHONY: update-kubeadm-constants +update-kubeadm-constants: + (cd hack/update/kubeadm_constants && \ + go run update_kubeadm_constants.go -kubernetes-version=latest) + .PHONY: stress stress: ## run the stress tests go test -test.v -test.timeout=2h ./test/stress -loops=10 | tee "./out/testout_$(COMMIT_SHORT).txt" diff --git a/hack/update/kubeadm_image_version/update_kubeadm_image_versions.go b/hack/update/kubeadm_constants/update_kubeadm_constants.go similarity index 89% rename from hack/update/kubeadm_image_version/update_kubeadm_image_versions.go rename to hack/update/kubeadm_constants/update_kubeadm_constants.go index 8b59265b96a8..647b2d2b844d 100644 --- a/hack/update/kubeadm_image_version/update_kubeadm_image_versions.go +++ b/hack/update/kubeadm_constants/update_kubeadm_constants.go @@ -91,11 +91,13 @@ func main() { }, } - if _, ok := constants.KubeadmImages[imageVersion]; !ok { + majorMinorVersion := semver.MajorMinor(imageVersion) + + if _, ok := constants.KubeadmImages[majorMinorVersion]; !ok { schema[minikubeConstantsFilePath].Replace[`KubeadmImages = .*`] = `KubeadmImages = map[string]map[string]string{ {{.ImageMap}}` } else { - versionIdentifier := fmt.Sprintf(`"%s": {[^}]+},`, imageVersion) + versionIdentifier := fmt.Sprintf(`"%s": {[^}]+},`, majorMinorVersion) schema[minikubeConstantsFilePath].Replace[versionIdentifier] = "{{.ImageMap}}" } @@ -107,6 +109,7 @@ func getKubeadmImagesMapString(version string) (string, error) { url := fmt.Sprintf(kubeadmReleaseURL, version) fileName := fmt.Sprintf(kubeadmBinaryName, version) if err := downloadFile(url, fileName); err != nil { + klog.Errorf("failed to download kubeadm binary %s", err.Error()) return "", err } @@ -114,6 +117,7 @@ func getKubeadmImagesMapString(version string) (string, error) { args := []string{"config", "images", "list"} imageListString, err := executeCommand(kubeadmCommand, args...) if err != nil { + klog.Errorf("failed to execute kubeadm command %s", kubeadmCommand) return "", err } @@ -126,18 +130,20 @@ func getKubeadmImagesMapString(version string) (string, error) { func formatKubeadmImageList(version, data string) (string, error) { templateData := make(map[string]map[string]string) - templateData[version] = make(map[string]string) + majorMinorVersion := semver.MajorMinor(version) + templateData[majorMinorVersion] = make(map[string]string) lines := strings.Split(data, "\n") for _, line := range lines { imageTag := strings.Split(line, ":") if len(imageTag) == 2 { - templateData[version][imageTag[0]] = imageTag[1] + templateData[majorMinorVersion][imageTag[0]] = imageTag[1] } } imageTemplate := template.New("kubeadmImage") t, err := imageTemplate.Parse(kubeadmImagesTemplate) if err != nil { + klog.Errorf("failed to create kubeadm image map template %s", err.Error()) return "", err } diff --git a/hack/update/update.go b/hack/update/update.go index f7732f7bfa37..2fec384cae6f 100644 --- a/hack/update/update.go +++ b/hack/update/update.go @@ -63,7 +63,7 @@ func init() { klog.Warningf("Unable to set flag value for alsologtostderr: %v", err) } - // used in update_kubeadm_image_versions.go + // used in update_kubeadm_constants.go flag.String("kubernetes-version", "", "kubernetes-version") flag.Parse() defer klog.Flush() diff --git a/pkg/minikube/bootstrapper/images/images.go b/pkg/minikube/bootstrapper/images/images.go index 362702407c2d..cefbe5ea1243 100644 --- a/pkg/minikube/bootstrapper/images/images.go +++ b/pkg/minikube/bootstrapper/images/images.go @@ -33,11 +33,11 @@ func Pause(v semver.Version, mirror string) string { // Should match `PauseVersion` in: // https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/constants/constants_unix.go pv := "3.2" - k8sVersion := fmt.Sprintf("v1.%d.0", v.Minor) + majorMinorVersion := fmt.Sprintf("v%d.%d", v.Major, v.Minor) imageName := path.Join(kubernetesRepo(mirror), "pause") - if _, ok := constants.KubeadmImages[k8sVersion]; ok { - pv = constants.KubeadmImages[k8sVersion][imageName] + if _, ok := constants.KubeadmImages[majorMinorVersion]; ok { + pv = constants.KubeadmImages[majorMinorVersion][imageName] } if semver.MustParseRange("<1.18.0-alpha.0")(v) { @@ -95,15 +95,16 @@ func coreDNS(v semver.Version, mirror string) string { */ cv := "1.7.0" - k8sVersion := fmt.Sprintf("v1.%d.0", v.Minor) + + majorMinorVersion := fmt.Sprintf("v%d.%d", v.Major, v.Minor) imageName := path.Join(kubernetesRepo(mirror), "coredns") if v.Minor >= 21 { imageName = path.Join(imageName, "coredns") } - if _, ok := constants.KubeadmImages[k8sVersion]; ok { - cv = constants.KubeadmImages[k8sVersion][imageName] + if _, ok := constants.KubeadmImages[majorMinorVersion]; ok { + cv = constants.KubeadmImages[majorMinorVersion][imageName] } // return path.Join(kubernetesRepo(mirror), "coredns:"+cv) @@ -129,11 +130,11 @@ func etcd(v semver.Version, mirror string) string { // ev = "3.2.18" //} */ - k8sVersion := fmt.Sprintf("v1.%d.0", v.Minor) + majorMinorVersion := fmt.Sprintf("v%d.%d", v.Major, v.Minor) imageName := path.Join(kubernetesRepo(mirror), "etcd") - if _, ok := constants.KubeadmImages[k8sVersion]; ok { - ev = constants.KubeadmImages[k8sVersion][imageName] + if _, ok := constants.KubeadmImages[majorMinorVersion]; ok { + ev = constants.KubeadmImages[majorMinorVersion][imageName] } // An awkward special case for v1.19.0 - do not imitate unless necessary diff --git a/pkg/minikube/constants/constants_kubeadm_images.go b/pkg/minikube/constants/constants_kubeadm_images.go index 04843cd57b68..37106dbb08ac 100644 --- a/pkg/minikube/constants/constants_kubeadm_images.go +++ b/pkg/minikube/constants/constants_kubeadm_images.go @@ -18,7 +18,7 @@ package constants var ( KubeadmImages = map[string]map[string]string{ - "v1.22.0-rc.0": { + "v1.22": { "k8s.gcr.io/coredns/coredns": "v1.8.4", "k8s.gcr.io/etcd": "3.4.13-0", "k8s.gcr.io/kube-apiserver": "v1.21.3", @@ -27,16 +27,8 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.21.3", "k8s.gcr.io/pause": "3.5", }, - "v1.21.3": { - "k8s.gcr.io/coredns/coredns": "v1.8.0", - "k8s.gcr.io/etcd": "3.4.13-0", - "k8s.gcr.io/kube-apiserver": "v1.21.3", - "k8s.gcr.io/kube-controller-manager": "v1.21.3", - "k8s.gcr.io/kube-proxy": "v1.21.3", - "k8s.gcr.io/kube-scheduler": "v1.21.3", - "k8s.gcr.io/pause": "3.4.1", - }, - "v1.21.0": { + + "v1.21": { "k8s.gcr.io/coredns/coredns": "v1.8.0", "k8s.gcr.io/etcd": "3.4.13-0", "k8s.gcr.io/kube-apiserver": "v1.21.3", @@ -45,7 +37,7 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.21.3", "k8s.gcr.io/pause": "3.4.1", }, - "v1.20.0": { + "v1.20": { "k8s.gcr.io/coredns": "1.7.0", "k8s.gcr.io/etcd": "3.4.13-0", "k8s.gcr.io/kube-apiserver": "v1.20.9", @@ -54,7 +46,7 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.20.9", "k8s.gcr.io/pause": "3.2", }, - "v1.19.0": { + "v1.19": { "k8s.gcr.io/coredns": "1.7.0", "k8s.gcr.io/etcd": "3.4.9-1", "k8s.gcr.io/kube-apiserver": "v1.19.13", @@ -63,7 +55,7 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.19.13", "k8s.gcr.io/pause": "3.2", }, - "v1.18.0": { + "v1.18": { "k8s.gcr.io/coredns": "1.6.7", "k8s.gcr.io/etcd": "3.4.3-0", "k8s.gcr.io/kube-apiserver": "v1.18.20", @@ -72,7 +64,7 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.18.20", "k8s.gcr.io/pause": "3.2", }, - "v1.17.0": { + "v1.17": { "k8s.gcr.io/coredns": "1.6.5", "k8s.gcr.io/etcd": "3.4.3-0", "k8s.gcr.io/kube-apiserver": "v1.17.17", @@ -81,16 +73,7 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.17.17", "k8s.gcr.io/pause": "3.1", }, - "v1.16.1": { - "mirror.k8s.io/kube-proxy": "v1.16.1", - "mirror.k8s.io/kube-scheduler": "v1.16.1", - "mirror.k8s.io/kube-controller-manager": "v1.16.1", - "mirror.k8s.io/kube-apiserver": "v1.16.1", - "mirror.k8s.io/coredns": "1.6.2", - "mirror.k8s.io/etcd": "3.3.15-0", - "mirror.k8s.io/pause": "3.1", - }, - "v1.16.0": { + "v1.16": { "k8s.gcr.io/coredns": "1.6.2", "k8s.gcr.io/etcd": "3.3.15-0", "k8s.gcr.io/kube-apiserver": "v1.16.15", @@ -99,7 +82,7 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.16.15", "k8s.gcr.io/pause": "3.1", }, - "v1.15.0": { + "v1.15": { "k8s.gcr.io/coredns": "1.3.1", "k8s.gcr.io/etcd": "3.3.10", "k8s.gcr.io/kube-apiserver": "v1.15.12", @@ -108,7 +91,8 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.15.12", "k8s.gcr.io/pause": "3.1", }, - "v1.14.0": { + + "v1.14": { "k8s.gcr.io/coredns": "1.3.1", "k8s.gcr.io/etcd": "3.3.10", "k8s.gcr.io/kube-apiserver": "v1.14.10", @@ -117,7 +101,7 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.14.10", "k8s.gcr.io/pause": "3.1", }, - "v1.13.0": { + "v1.13": { "k8s.gcr.io/coredns": "1.2.6", "k8s.gcr.io/etcd": "3.2.24", "k8s.gcr.io/kube-apiserver": "v1.13.12", @@ -126,7 +110,7 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.13.12", "k8s.gcr.io/pause": "3.1", }, - "v1.12.0": { + "v1.12": { "k8s.gcr.io/coredns": "1.2.2", "k8s.gcr.io/etcd": "3.2.24", "k8s.gcr.io/kube-apiserver": "v1.21.3", @@ -135,7 +119,7 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.21.3", "k8s.gcr.io/pause": "3.1", }, - "v1.11.0": { + "v1.11": { "k8s.gcr.io/coredns": "1.1.3", "k8s.gcr.io/etcd-amd64": "3.2.18", "k8s.gcr.io/kube-apiserver-amd64": "v1.11.10", From 837c73d964e9a1abbad27032086321727c38aece Mon Sep 17 00:00:00 2001 From: "srikrishnabh93@gmail.com" Date: Sun, 1 Aug 2021 13:42:42 +0530 Subject: [PATCH 3/9] added gofmt for constants_kubeadm_images --- Makefile | 3 ++- hack/update/kubeadm_constants/update_kubeadm_constants.go | 2 +- hack/update/update.go | 2 +- pkg/minikube/bootstrapper/images/images.go | 2 +- pkg/minikube/bootstrapper/images/repo_test.go | 4 ++-- pkg/minikube/constants/constants_kubeadm_images.go | 1 - 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 68b6c397023f..50950a8ccc46 100644 --- a/Makefile +++ b/Makefile @@ -983,7 +983,8 @@ endif .PHONY: update-kubeadm-constants update-kubeadm-constants: (cd hack/update/kubeadm_constants && \ - go run update_kubeadm_constants.go -kubernetes-version=latest) + go run update_kubeadm_constants.go) + gofmt -w pkg/minikube/constants/constants_kubeadm_images.go .PHONY: stress stress: ## run the stress tests diff --git a/hack/update/kubeadm_constants/update_kubeadm_constants.go b/hack/update/kubeadm_constants/update_kubeadm_constants.go index 647b2d2b844d..740a5c301e96 100644 --- a/hack/update/kubeadm_constants/update_kubeadm_constants.go +++ b/hack/update/kubeadm_constants/update_kubeadm_constants.go @@ -152,7 +152,7 @@ func formatKubeadmImageList(version, data string) (string, error) { return "", err } - return bytesBuffer.String(), nil + return strings.TrimLeft(bytesBuffer.String(), "\n"), nil } func downloadFile(url, fileName string) error { diff --git a/hack/update/update.go b/hack/update/update.go index 2fec384cae6f..36c64be5f732 100644 --- a/hack/update/update.go +++ b/hack/update/update.go @@ -64,7 +64,7 @@ func init() { } // used in update_kubeadm_constants.go - flag.String("kubernetes-version", "", "kubernetes-version") + flag.String("kubernetes-version", "latest", "kubernetes-version") flag.Parse() defer klog.Flush() diff --git a/pkg/minikube/bootstrapper/images/images.go b/pkg/minikube/bootstrapper/images/images.go index f2b92b4153f4..fba23098b490 100644 --- a/pkg/minikube/bootstrapper/images/images.go +++ b/pkg/minikube/bootstrapper/images/images.go @@ -23,7 +23,7 @@ import ( "k8s.io/minikube/pkg/minikube/constants" - "github.com/blang/semver" + "github.com/blang/semver/v4" "k8s.io/minikube/pkg/version" ) diff --git a/pkg/minikube/bootstrapper/images/repo_test.go b/pkg/minikube/bootstrapper/images/repo_test.go index dc0bcf485013..e4e2b11aa8ef 100644 --- a/pkg/minikube/bootstrapper/images/repo_test.go +++ b/pkg/minikube/bootstrapper/images/repo_test.go @@ -52,11 +52,11 @@ func Test_minikubeRepo(t *testing.T) { }{ { "", - DefaultMinikubeRepo, + "gcr.io/k8s-minikube", }, { "mirror.k8s.io", - "mirror.k8s.io", + "mirror.k8s.io/k8s-minikube", }, } diff --git a/pkg/minikube/constants/constants_kubeadm_images.go b/pkg/minikube/constants/constants_kubeadm_images.go index 37106dbb08ac..4b0c002065af 100644 --- a/pkg/minikube/constants/constants_kubeadm_images.go +++ b/pkg/minikube/constants/constants_kubeadm_images.go @@ -27,7 +27,6 @@ var ( "k8s.gcr.io/kube-scheduler": "v1.21.3", "k8s.gcr.io/pause": "3.5", }, - "v1.21": { "k8s.gcr.io/coredns/coredns": "v1.8.0", "k8s.gcr.io/etcd": "3.4.13-0", From ddfcf464dcf3c55761572c1d14d100e1d5e3c614 Mon Sep 17 00:00:00 2001 From: "srikrishnabh93@gmail.com" Date: Mon, 2 Aug 2021 23:02:01 +0530 Subject: [PATCH 4/9] fixed formatting --- hack/update/kubeadm_constants/update_kubeadm_constants.go | 6 ++++-- pkg/minikube/bootstrapper/images/kubeadm_test.go | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hack/update/kubeadm_constants/update_kubeadm_constants.go b/hack/update/kubeadm_constants/update_kubeadm_constants.go index 740a5c301e96..706a212b20dc 100644 --- a/hack/update/kubeadm_constants/update_kubeadm_constants.go +++ b/hack/update/kubeadm_constants/update_kubeadm_constants.go @@ -84,7 +84,7 @@ func main() { klog.Fatalln(err) } - data := Data{ImageMap: imageMapString} + var data Data schema := map[string]update.Item{ minikubeConstantsFilePath: { Replace: map[string]string{}, @@ -94,9 +94,11 @@ func main() { majorMinorVersion := semver.MajorMinor(imageVersion) if _, ok := constants.KubeadmImages[majorMinorVersion]; !ok { + data = Data{ImageMap: imageMapString} schema[minikubeConstantsFilePath].Replace[`KubeadmImages = .*`] = `KubeadmImages = map[string]map[string]string{ {{.ImageMap}}` } else { + data = Data{ImageMap: strings.TrimLeft(imageMapString, "\n")} versionIdentifier := fmt.Sprintf(`"%s": {[^}]+},`, majorMinorVersion) schema[minikubeConstantsFilePath].Replace[versionIdentifier] = "{{.ImageMap}}" } @@ -152,7 +154,7 @@ func formatKubeadmImageList(version, data string) (string, error) { return "", err } - return strings.TrimLeft(bytesBuffer.String(), "\n"), nil + return bytesBuffer.String(), nil } func downloadFile(url, fileName string) error { diff --git a/pkg/minikube/bootstrapper/images/kubeadm_test.go b/pkg/minikube/bootstrapper/images/kubeadm_test.go index 4a71d8096424..28123215d548 100644 --- a/pkg/minikube/bootstrapper/images/kubeadm_test.go +++ b/pkg/minikube/bootstrapper/images/kubeadm_test.go @@ -17,7 +17,6 @@ limitations under the License. package images import ( - "fmt" "sort" "testing" @@ -121,7 +120,6 @@ func TestKubeadmImages(t *testing.T) { sort.Strings(got) sort.Strings(tc.want) if diff := cmp.Diff(tc.want, got); diff != "" { - fmt.Println(diff) t.Errorf("%s images mismatch (-want +got):\n%s", tc.version, diff) } } From e744f3e3cc17c4d4a44ee3f3067f0c9688eb0aea Mon Sep 17 00:00:00 2001 From: "srikrishnabh93@gmail.com" Date: Thu, 26 Aug 2021 19:20:38 +0530 Subject: [PATCH 5/9] fixed kubeadm image version for 22 --- .../constants/constants_kubeadm_images.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/minikube/constants/constants_kubeadm_images.go b/pkg/minikube/constants/constants_kubeadm_images.go index 4b0c002065af..0da133805c19 100644 --- a/pkg/minikube/constants/constants_kubeadm_images.go +++ b/pkg/minikube/constants/constants_kubeadm_images.go @@ -20,11 +20,11 @@ var ( KubeadmImages = map[string]map[string]string{ "v1.22": { "k8s.gcr.io/coredns/coredns": "v1.8.4", - "k8s.gcr.io/etcd": "3.4.13-0", - "k8s.gcr.io/kube-apiserver": "v1.21.3", - "k8s.gcr.io/kube-controller-manager": "v1.21.3", - "k8s.gcr.io/kube-proxy": "v1.21.3", - "k8s.gcr.io/kube-scheduler": "v1.21.3", + "k8s.gcr.io/etcd": "3.5.0-0", + "k8s.gcr.io/kube-apiserver": "v1.22.1", + "k8s.gcr.io/kube-controller-manager": "v1.22.1", + "k8s.gcr.io/kube-proxy": "v1.22.1", + "k8s.gcr.io/kube-scheduler": "v1.22.1", "k8s.gcr.io/pause": "3.5", }, "v1.21": { @@ -112,10 +112,10 @@ var ( "v1.12": { "k8s.gcr.io/coredns": "1.2.2", "k8s.gcr.io/etcd": "3.2.24", - "k8s.gcr.io/kube-apiserver": "v1.21.3", - "k8s.gcr.io/kube-controller-manager": "v1.21.3", - "k8s.gcr.io/kube-proxy": "v1.21.3", - "k8s.gcr.io/kube-scheduler": "v1.21.3", + "k8s.gcr.io/kube-apiserver": "v1.22.1", + "k8s.gcr.io/kube-controller-manager": "v1.22.1", + "k8s.gcr.io/kube-proxy": "v1.22.1", + "k8s.gcr.io/kube-scheduler": "v1.22.1", "k8s.gcr.io/pause": "3.1", }, "v1.11": { From 7e7a97e69d70f7db2f44331ad3b4f50f02b459e1 Mon Sep 17 00:00:00 2001 From: "srikrishnabh93@gmail.com" Date: Wed, 29 Sep 2021 20:51:03 +0530 Subject: [PATCH 6/9] updated the test data kubeadm_test.go --- .../bootstrapper/images/kubeadm_test.go | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/minikube/bootstrapper/images/kubeadm_test.go b/pkg/minikube/bootstrapper/images/kubeadm_test.go index 56ddda36daa5..92b072bc6928 100644 --- a/pkg/minikube/bootstrapper/images/kubeadm_test.go +++ b/pkg/minikube/bootstrapper/images/kubeadm_test.go @@ -46,17 +46,17 @@ func TestKubeadmImages(t *testing.T) { "docker.io/kubernetesui/dashboard:v2.3.1", "docker.io/kubernetesui/metrics-scraper:v1.0.7", }}, - {"v1.16.1", "mirror.k8s.io", false, []string{ - "mirror.k8s.io/kube-proxy:v1.16.1", - "mirror.k8s.io/kube-scheduler:v1.16.1", - "mirror.k8s.io/kube-controller-manager:v1.16.1", - "mirror.k8s.io/kube-apiserver:v1.16.1", - "mirror.k8s.io/coredns:1.6.2", - "mirror.k8s.io/etcd:3.3.15-0", - "mirror.k8s.io/pause:3.1", - "mirror.k8s.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(), - "mirror.k8s.io/kubernetesui/dashboard:v2.3.1", - "mirror.k8s.io/kubernetesui/metrics-scraper:v1.0.7", + {"v1.16.1", "k8s.gcr.io", false, []string{ + "k8s.gcr.io/kube-proxy:v1.16.1", + "k8s.gcr.io/kube-scheduler:v1.16.1", + "k8s.gcr.io/kube-controller-manager:v1.16.1", + "k8s.gcr.io/kube-apiserver:v1.16.1", + "k8s.gcr.io/coredns:1.6.2", + "k8s.gcr.io/etcd:3.3.15-0", + "k8s.gcr.io/pause:3.1", + "k8s.gcr.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(), + "k8s.gcr.io/kubernetesui/dashboard:v2.3.1", + "k8s.gcr.io/kubernetesui/metrics-scraper:v1.0.7", }}, {"v1.15.0", "", false, []string{ "k8s.gcr.io/kube-proxy:v1.15.0", From 991d9d47ce3cfb81a0b31823d0fae954fb69a3a9 Mon Sep 17 00:00:00 2001 From: "srikrishnabh93@gmail.com" Date: Thu, 21 Oct 2021 22:51:46 +0530 Subject: [PATCH 7/9] removed vars latestP0 latestMM from update kubeadm consts --- .../update_kubeadm_constants.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hack/update/kubeadm_constants/update_kubeadm_constants.go b/hack/update/kubeadm_constants/update_kubeadm_constants.go index 706a212b20dc..8d126a28ac16 100644 --- a/hack/update/kubeadm_constants/update_kubeadm_constants.go +++ b/hack/update/kubeadm_constants/update_kubeadm_constants.go @@ -67,7 +67,7 @@ func main() { defer cancel() if inputVersion == "latest" { - stableImageVersion, latestImageVersion, _, _, err := getK8sVersions(ctx, "kubernetes", "kubernetes") + stableImageVersion, latestImageVersion, err := getK8sVersions(ctx, "kubernetes", "kubernetes") if err != nil { klog.Fatal(err) } @@ -190,16 +190,16 @@ func executeCommand(command string, args ...string) (string, error) { } // getK8sVersion returns Kubernetes versions. -func getK8sVersions(ctx context.Context, owner, repo string) (stable, latest, latestMM, latestP0 string, err error) { +func getK8sVersions(ctx context.Context, owner, repo string) (stable, latest string, err error) { // get Kubernetes versions from GitHub Releases stable, latest, err = update.GHReleases(ctx, owner, repo) - if err != nil || !semver.IsValid(stable) || !semver.IsValid(latest) { - return "", "", "", "", err + if err != nil { + return "", "", err } - latestMM = semver.MajorMinor(latest) - latestP0 = latestMM + ".0" - if semver.Compare(stable, latestP0) == -1 { - latestP0 = latest + + if !semver.IsValid(stable) || !semver.IsValid(latest) { + return "", "", fmt.Errorf("invalid release obtained stable : %s, latest : %s", stable, latest) } - return stable, latest, latestMM, latestP0, nil + + return stable, latest, nil } From d0928b19131d78737cf7732e32d72b69e990a56c Mon Sep 17 00:00:00 2001 From: "srikrishnabh93@gmail.com" Date: Thu, 21 Oct 2021 23:01:32 +0530 Subject: [PATCH 8/9] updated kubeadm-constants image version --- pkg/minikube/constants/constants_kubeadm_images.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/minikube/constants/constants_kubeadm_images.go b/pkg/minikube/constants/constants_kubeadm_images.go index 0da133805c19..325dfae9fa32 100644 --- a/pkg/minikube/constants/constants_kubeadm_images.go +++ b/pkg/minikube/constants/constants_kubeadm_images.go @@ -21,10 +21,10 @@ var ( "v1.22": { "k8s.gcr.io/coredns/coredns": "v1.8.4", "k8s.gcr.io/etcd": "3.5.0-0", - "k8s.gcr.io/kube-apiserver": "v1.22.1", - "k8s.gcr.io/kube-controller-manager": "v1.22.1", - "k8s.gcr.io/kube-proxy": "v1.22.1", - "k8s.gcr.io/kube-scheduler": "v1.22.1", + "k8s.gcr.io/kube-apiserver": "v1.22.2", + "k8s.gcr.io/kube-controller-manager": "v1.22.2", + "k8s.gcr.io/kube-proxy": "v1.22.2", + "k8s.gcr.io/kube-scheduler": "v1.22.2", "k8s.gcr.io/pause": "3.5", }, "v1.21": { From 7dd0eb0c94fac9dc4f4ad7f53c0f75d8092ed10d Mon Sep 17 00:00:00 2001 From: "srikrishnabh93@gmail.com" Date: Sun, 7 Nov 2021 00:25:33 +0530 Subject: [PATCH 9/9] fixed review comments --- .../update_kubeadm_constants.go | 3 + pkg/minikube/bootstrapper/images/images.go | 16 +- .../bootstrapper/images/kubeadm_test.go | 22 +-- .../constants/constants_kubeadm_images.go | 169 +++++++++--------- 4 files changed, 104 insertions(+), 106 deletions(-) diff --git a/hack/update/kubeadm_constants/update_kubeadm_constants.go b/hack/update/kubeadm_constants/update_kubeadm_constants.go index 8d126a28ac16..7399904d1991 100644 --- a/hack/update/kubeadm_constants/update_kubeadm_constants.go +++ b/hack/update/kubeadm_constants/update_kubeadm_constants.go @@ -138,6 +138,9 @@ func formatKubeadmImageList(version, data string) (string, error) { for _, line := range lines { imageTag := strings.Split(line, ":") if len(imageTag) == 2 { + // removing the repo from image name + imageName := strings.Split(imageTag[0], "/") + imageTag[0] = strings.Join(imageName[1:], "/") templateData[majorMinorVersion][imageTag[0]] = imageTag[1] } } diff --git a/pkg/minikube/bootstrapper/images/images.go b/pkg/minikube/bootstrapper/images/images.go index b9ae8535a847..50dedec0c54c 100644 --- a/pkg/minikube/bootstrapper/images/images.go +++ b/pkg/minikube/bootstrapper/images/images.go @@ -35,15 +35,13 @@ func Pause(v semver.Version, mirror string) string { // https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/constants/constants.go // https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/constants/constants_unix.go pv := "3.6" - majorMinorVersion := fmt.Sprintf("v%d.%d", v.Major, v.Minor) - imageName := path.Join(kubernetesRepo(mirror), "pause") - + imageName := "pause" if pVersion, ok := constants.KubeadmImages[majorMinorVersion][imageName]; ok { pv = pVersion } - return fmt.Sprintf("%s:%s", imageName, pv) + return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), imageName), pv) } // essentials returns images needed too bootstrap a Kubernetes @@ -79,12 +77,11 @@ func coreDNS(v semver.Version, mirror string) string { } majorMinorVersion := fmt.Sprintf("v%d.%d", v.Major, v.Minor) - imageName := path.Join(kubernetesRepo(mirror), in) - if cVersion, ok := constants.KubeadmImages[majorMinorVersion][imageName]; ok { + if cVersion, ok := constants.KubeadmImages[majorMinorVersion][in]; ok { cv = cVersion } - return fmt.Sprintf("%s:%s", imageName, cv) + return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), in), cv) } // etcd returns the image used for etcd @@ -94,13 +91,12 @@ func etcd(v semver.Version, mirror string) string { // https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/constants/constants.go ev := "3.5.0-0" majorMinorVersion := fmt.Sprintf("v%d.%d", v.Major, v.Minor) - imageName := path.Join(kubernetesRepo(mirror), "etcd") - + imageName := "etcd" if eVersion, ok := constants.KubeadmImages[majorMinorVersion][imageName]; ok { ev = eVersion } - return fmt.Sprintf("%s:%s", imageName, ev) + return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), imageName), ev) } // auxiliary returns images that are helpful for running minikube diff --git a/pkg/minikube/bootstrapper/images/kubeadm_test.go b/pkg/minikube/bootstrapper/images/kubeadm_test.go index 92b072bc6928..56ddda36daa5 100644 --- a/pkg/minikube/bootstrapper/images/kubeadm_test.go +++ b/pkg/minikube/bootstrapper/images/kubeadm_test.go @@ -46,17 +46,17 @@ func TestKubeadmImages(t *testing.T) { "docker.io/kubernetesui/dashboard:v2.3.1", "docker.io/kubernetesui/metrics-scraper:v1.0.7", }}, - {"v1.16.1", "k8s.gcr.io", false, []string{ - "k8s.gcr.io/kube-proxy:v1.16.1", - "k8s.gcr.io/kube-scheduler:v1.16.1", - "k8s.gcr.io/kube-controller-manager:v1.16.1", - "k8s.gcr.io/kube-apiserver:v1.16.1", - "k8s.gcr.io/coredns:1.6.2", - "k8s.gcr.io/etcd:3.3.15-0", - "k8s.gcr.io/pause:3.1", - "k8s.gcr.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(), - "k8s.gcr.io/kubernetesui/dashboard:v2.3.1", - "k8s.gcr.io/kubernetesui/metrics-scraper:v1.0.7", + {"v1.16.1", "mirror.k8s.io", false, []string{ + "mirror.k8s.io/kube-proxy:v1.16.1", + "mirror.k8s.io/kube-scheduler:v1.16.1", + "mirror.k8s.io/kube-controller-manager:v1.16.1", + "mirror.k8s.io/kube-apiserver:v1.16.1", + "mirror.k8s.io/coredns:1.6.2", + "mirror.k8s.io/etcd:3.3.15-0", + "mirror.k8s.io/pause:3.1", + "mirror.k8s.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(), + "mirror.k8s.io/kubernetesui/dashboard:v2.3.1", + "mirror.k8s.io/kubernetesui/metrics-scraper:v1.0.7", }}, {"v1.15.0", "", false, []string{ "k8s.gcr.io/kube-proxy:v1.15.0", diff --git a/pkg/minikube/constants/constants_kubeadm_images.go b/pkg/minikube/constants/constants_kubeadm_images.go index 325dfae9fa32..ceabf19bad17 100644 --- a/pkg/minikube/constants/constants_kubeadm_images.go +++ b/pkg/minikube/constants/constants_kubeadm_images.go @@ -19,113 +19,112 @@ package constants var ( KubeadmImages = map[string]map[string]string{ "v1.22": { - "k8s.gcr.io/coredns/coredns": "v1.8.4", - "k8s.gcr.io/etcd": "3.5.0-0", - "k8s.gcr.io/kube-apiserver": "v1.22.2", - "k8s.gcr.io/kube-controller-manager": "v1.22.2", - "k8s.gcr.io/kube-proxy": "v1.22.2", - "k8s.gcr.io/kube-scheduler": "v1.22.2", - "k8s.gcr.io/pause": "3.5", + "coredns/coredns": "v1.8.4", + "etcd": "3.5.0-0", + "kube-apiserver": "v1.22.3", + "kube-controller-manager": "v1.22.3", + "kube-proxy": "v1.22.3", + "kube-scheduler": "v1.22.3", + "pause": "3.5", }, "v1.21": { - "k8s.gcr.io/coredns/coredns": "v1.8.0", - "k8s.gcr.io/etcd": "3.4.13-0", - "k8s.gcr.io/kube-apiserver": "v1.21.3", - "k8s.gcr.io/kube-controller-manager": "v1.21.3", - "k8s.gcr.io/kube-proxy": "v1.21.3", - "k8s.gcr.io/kube-scheduler": "v1.21.3", - "k8s.gcr.io/pause": "3.4.1", + "coredns/coredns": "v1.8.0", + "etcd": "3.4.13-0", + "kube-apiserver": "v1.21.6", + "kube-controller-manager": "v1.21.6", + "kube-proxy": "v1.21.6", + "kube-scheduler": "v1.21.6", + "pause": "3.4.1", }, "v1.20": { - "k8s.gcr.io/coredns": "1.7.0", - "k8s.gcr.io/etcd": "3.4.13-0", - "k8s.gcr.io/kube-apiserver": "v1.20.9", - "k8s.gcr.io/kube-controller-manager": "v1.20.9", - "k8s.gcr.io/kube-proxy": "v1.20.9", - "k8s.gcr.io/kube-scheduler": "v1.20.9", - "k8s.gcr.io/pause": "3.2", + "coredns": "1.7.0", + "etcd": "3.4.13-0", + "kube-apiserver": "v1.20.12", + "kube-controller-manager": "v1.20.12", + "kube-proxy": "v1.20.12", + "kube-scheduler": "v1.20.12", + "pause": "3.2", }, "v1.19": { - "k8s.gcr.io/coredns": "1.7.0", - "k8s.gcr.io/etcd": "3.4.9-1", - "k8s.gcr.io/kube-apiserver": "v1.19.13", - "k8s.gcr.io/kube-controller-manager": "v1.19.13", - "k8s.gcr.io/kube-proxy": "v1.19.13", - "k8s.gcr.io/kube-scheduler": "v1.19.13", - "k8s.gcr.io/pause": "3.2", + "coredns": "1.7.0", + "etcd": "3.4.9-1", + "kube-apiserver": "v1.19.16", + "kube-controller-manager": "v1.19.16", + "kube-proxy": "v1.19.16", + "kube-scheduler": "v1.19.16", + "pause": "3.2", }, "v1.18": { - "k8s.gcr.io/coredns": "1.6.7", - "k8s.gcr.io/etcd": "3.4.3-0", - "k8s.gcr.io/kube-apiserver": "v1.18.20", - "k8s.gcr.io/kube-controller-manager": "v1.18.20", - "k8s.gcr.io/kube-proxy": "v1.18.20", - "k8s.gcr.io/kube-scheduler": "v1.18.20", - "k8s.gcr.io/pause": "3.2", + "coredns": "1.6.7", + "etcd": "3.4.3-0", + "kube-apiserver": "v1.18.20", + "kube-controller-manager": "v1.18.20", + "kube-proxy": "v1.18.20", + "kube-scheduler": "v1.18.20", + "pause": "3.2", }, "v1.17": { - "k8s.gcr.io/coredns": "1.6.5", - "k8s.gcr.io/etcd": "3.4.3-0", - "k8s.gcr.io/kube-apiserver": "v1.17.17", - "k8s.gcr.io/kube-controller-manager": "v1.17.17", - "k8s.gcr.io/kube-proxy": "v1.17.17", - "k8s.gcr.io/kube-scheduler": "v1.17.17", - "k8s.gcr.io/pause": "3.1", + "coredns": "1.6.5", + "etcd": "3.4.3-0", + "kube-apiserver": "v1.17.17", + "kube-controller-manager": "v1.17.17", + "kube-proxy": "v1.17.17", + "kube-scheduler": "v1.17.17", + "pause": "3.1", }, "v1.16": { - "k8s.gcr.io/coredns": "1.6.2", - "k8s.gcr.io/etcd": "3.3.15-0", - "k8s.gcr.io/kube-apiserver": "v1.16.15", - "k8s.gcr.io/kube-controller-manager": "v1.16.15", - "k8s.gcr.io/kube-proxy": "v1.16.15", - "k8s.gcr.io/kube-scheduler": "v1.16.15", - "k8s.gcr.io/pause": "3.1", + "coredns": "1.6.2", + "etcd": "3.3.15-0", + "kube-apiserver": "v1.16.15", + "kube-controller-manager": "v1.16.15", + "kube-proxy": "v1.16.15", + "kube-scheduler": "v1.16.15", + "pause": "3.1", }, "v1.15": { - "k8s.gcr.io/coredns": "1.3.1", - "k8s.gcr.io/etcd": "3.3.10", - "k8s.gcr.io/kube-apiserver": "v1.15.12", - "k8s.gcr.io/kube-controller-manager": "v1.15.12", - "k8s.gcr.io/kube-proxy": "v1.15.12", - "k8s.gcr.io/kube-scheduler": "v1.15.12", - "k8s.gcr.io/pause": "3.1", + "coredns": "1.3.1", + "etcd": "3.3.10", + "kube-apiserver": "v1.15.12", + "kube-controller-manager": "v1.15.12", + "kube-proxy": "v1.15.12", + "kube-scheduler": "v1.15.12", + "pause": "3.1", }, - "v1.14": { - "k8s.gcr.io/coredns": "1.3.1", - "k8s.gcr.io/etcd": "3.3.10", - "k8s.gcr.io/kube-apiserver": "v1.14.10", - "k8s.gcr.io/kube-controller-manager": "v1.14.10", - "k8s.gcr.io/kube-proxy": "v1.14.10", - "k8s.gcr.io/kube-scheduler": "v1.14.10", - "k8s.gcr.io/pause": "3.1", + "coredns": "1.3.1", + "etcd": "3.3.10", + "kube-apiserver": "v1.14.10", + "kube-controller-manager": "v1.14.10", + "kube-proxy": "v1.14.10", + "kube-scheduler": "v1.14.10", + "pause": "3.1", }, "v1.13": { - "k8s.gcr.io/coredns": "1.2.6", - "k8s.gcr.io/etcd": "3.2.24", - "k8s.gcr.io/kube-apiserver": "v1.13.12", - "k8s.gcr.io/kube-controller-manager": "v1.13.12", - "k8s.gcr.io/kube-proxy": "v1.13.12", - "k8s.gcr.io/kube-scheduler": "v1.13.12", - "k8s.gcr.io/pause": "3.1", + "coredns": "1.2.6", + "etcd": "3.2.24", + "kube-apiserver": "v1.13.12", + "kube-controller-manager": "v1.13.12", + "kube-proxy": "v1.13.12", + "kube-scheduler": "v1.13.12", + "pause": "3.1", }, "v1.12": { - "k8s.gcr.io/coredns": "1.2.2", - "k8s.gcr.io/etcd": "3.2.24", - "k8s.gcr.io/kube-apiserver": "v1.22.1", - "k8s.gcr.io/kube-controller-manager": "v1.22.1", - "k8s.gcr.io/kube-proxy": "v1.22.1", - "k8s.gcr.io/kube-scheduler": "v1.22.1", - "k8s.gcr.io/pause": "3.1", + "coredns": "1.2.2", + "etcd": "3.2.24", + "kube-apiserver": "v1.22.3", + "kube-controller-manager": "v1.22.3", + "kube-proxy": "v1.22.3", + "kube-scheduler": "v1.22.3", + "pause": "3.1", }, "v1.11": { - "k8s.gcr.io/coredns": "1.1.3", - "k8s.gcr.io/etcd-amd64": "3.2.18", - "k8s.gcr.io/kube-apiserver-amd64": "v1.11.10", - "k8s.gcr.io/kube-controller-manager-amd64": "v1.11.10", - "k8s.gcr.io/kube-proxy-amd64": "v1.11.10", - "k8s.gcr.io/kube-scheduler-amd64": "v1.11.10", - "k8s.gcr.io/pause-amd64": "3.1", + "coredns": "1.1.3", + "etcd-amd64": "3.2.18", + "kube-apiserver-amd64": "v1.11.10", + "kube-controller-manager-amd64": "v1.11.10", + "kube-proxy-amd64": "v1.11.10", + "kube-scheduler-amd64": "v1.11.10", + "pause-amd64": "3.1", }, } )