add automation for k8s version

pull/12375/head
Medya Gh 2021-08-30 14:53:28 -07:00
parent d092445716
commit 50e14f30c3
2 changed files with 11 additions and 9 deletions

View File

@ -34,9 +34,7 @@ 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
# Kubernetes uses k8s version in golang image version because:
# https://github.com/kubernetes/kubernetes/pull/103692#issuecomment-908659826
# TODO: make automation update this #12374
# 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

View File

@ -119,7 +119,8 @@ var (
"Makefile": {
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_VERSION \?= 1.*`: `GO_VERSION ?= {{.StableVersion}}`,
`GO_K8S_VERSION \?= 1.*`: `GO_K8S_VERSION ?= {{.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:"k8sVersionMM"` // 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,18 +145,18 @@ 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 {
@ -164,10 +167,11 @@ func goVersions() (stable, stableMM string, err error) {
return "", "", err
}
// example response: v1.23.0-go1.17-buster.0
stable = strings.TrimPrefix(string(body), "v")
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
}