Merge pull request #12375 from medyagh/fix_go_auto

Fix go bump automation to adopt Kubernetes new kube-cross image name
pull/12379/head
Medya Ghazizadeh 2021-08-30 16:48:39 -07:00 committed by GitHub
commit 0f7be4fa51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View File

@ -34,6 +34,8 @@ RPM_REVISION ?= 0
# used by hack/jenkins/release_build_and_upload.sh and KVM_BUILD_IMAGE, see also BUILD_IMAGE below
# update this only by running `make update-golang-version`
GO_VERSION ?= 1.16.7
# update this only by running `make update-golang-version`
GO_K8S_VERSION_PREFIX ?= v1.23.0
# replace "x.y.0" => "x.y". kube-cross and golang.org/dl use different formats for x.y.0 go versions
KVM_GO_VERSION ?= $(GO_VERSION:.0=)
@ -52,7 +54,8 @@ HYPERKIT_BUILD_IMAGE ?= neilotoole/xcgo:go1.15
# NOTE: "latest" as of 2021-02-06. kube-cross images aren't updated as often as Kubernetes
# https://github.com/kubernetes/kubernetes/blob/master/build/build-image/cross/VERSION
#
BUILD_IMAGE ?= us.gcr.io/k8s-artifacts-prod/build-image/kube-cross:v$(GO_VERSION)-1
BUILD_IMAGE ?= us.gcr.io/k8s-artifacts-prod/build-image/kube-cross:$(GO_K8S_VERSION_PREFIX)-go$(GO_VERSION)-buster.0
ISO_BUILD_IMAGE ?= $(REGISTRY)/buildroot-image

View File

@ -120,6 +120,7 @@ var (
Replace: map[string]string{
// searching for 1.* so it does NOT match "KVM_GO_VERSION ?= $(GO_VERSION:.0=)" in the Makefile
`GO_VERSION \?= 1.*`: `GO_VERSION ?= {{.StableVersion}}`,
`GO_K8S_VERSION_PREFIX \?= v1.*`: `GO_K8S_VERSION_PREFIX ?= {{.K8SVersion}}`,
},
},
}
@ -134,6 +135,8 @@ var (
type Data struct {
StableVersion string `json:"stableVersion"`
StableVersionMM string `json:"stableVersionMM"` // go.mod wants go version in <major>.<minor> format
K8SVersion string `json:"k8sVersion"` // as of v1.23.0 Kubernetes uses k8s version in golang image name because: https://github.com/kubernetes/kubernetes/pull/103692#issuecomment-908659826
}
func main() {
@ -142,30 +145,33 @@ func main() {
defer cancel()
// get Golang stable version
stable, stableMM, err := goVersions()
stable, stableMM, k8sVersion, err := goVersions()
if err != nil || stable == "" || stableMM == "" {
klog.Fatalf("Unable to get Golang stable version: %v", err)
}
data := Data{StableVersion: stable, StableVersionMM: stableMM}
data := Data{StableVersion: stable, StableVersionMM: stableMM, K8SVersion: k8sVersion}
klog.Infof("Golang stable version: %s", data.StableVersion)
update.Apply(ctx, schema, data, prBranchPrefix, prTitle, prIssue)
}
// goVersion returns Golang stable version.
func goVersions() (stable, stableMM string, err error) {
func goVersions() (stable, stableMM, k8sVersion string, err error) {
// will update to the same image that kubernetes project uses
resp, err := http.Get("https://raw.githubusercontent.com/kubernetes/kubernetes/master/build/build-image/cross/VERSION")
if err != nil {
return "", "", err
return "", "", "", err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", "", err
return "", "", "", err
}
stable = strings.TrimPrefix(string(body), "v")
stable = strings.Split(stable, "-")[0]
// example response: v1.23.0-go1.17-buster.0
stable = string(body)
k8sVersion = strings.Split(stable, "-")[0]
stable = strings.Split(stable, "-")[1]
stable = strings.Replace(stable, "go", "", 1)
mmp := strings.SplitN(stable, ".", 3)
stableMM = strings.Join(mmp[0:2], ".") // <major>.<minor> version
return stable, stableMM, nil
return stable, stableMM, k8sVersion, nil
}