From 8f0483461b569171df1961b212e8d3a4d2405038 Mon Sep 17 00:00:00 2001 From: "srikrishnabh93@gmail.com" Date: Sat, 31 Jul 2021 23:20:32 +0530 Subject: [PATCH] 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",