ci: update all with go (#21213)

* add update all go script

* add update all make target

* add update all make target

* standardize the component name for look up

* standardize amd amd component name

* rename all hack update go code to match component name to standardize

* delete extra folder

* update makefile with new standard filenames

* update component name amd

* fix amd gpu name

* skip amd for now till broken

* fix cilium helm update

* standard name for cloud spanner emulator

* standard crio name

* set max to 100

* delete old folder

* skip docsy for update all

* return error if fail to apply

* docsy versoin

* update files with go-github

* update file names

* move all make targets to same location

* standard name for golang comp

* skip istio addon

* skip kicbase version since it is not related

* skip kubeadm constant too

* skip kubernetes version too

* run components that dont support before/after

* update kubeadm constant

* skip kubeadm constant on non linux

* add kubernetes_versions_list to not support before/after

* list preload version as one of the internal jobs

* list preload version as one of the internal jobs

* simpllify the code

* use log for printing

* add boiler plates

* add gh workflow
pull/21244/head
Medya Ghazizadeh 2025-08-04 18:15:23 -07:00 committed by GitHub
parent 7ce514291e
commit c0e46ff8cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
56 changed files with 304 additions and 90 deletions

42
.github/workflows/update-all.yml vendored Normal file
View File

@ -0,0 +1,42 @@
name: "update-all"
on:
workflow_dispatch:
env:
GOPROXY: https://proxy.golang.org
GO_VERSION: '1.24.0'
permissions:
contents: read
jobs:
update-all:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5
with:
go-version: ${{env.GO_VERSION}}
- name: Bump versions
id: bumpVersions
run: |
MAKEALL_OUTPUT=$(make _update-all)
echo "changes<<EOF" >> "$GITHUB_OUTPUT"
echo "$MAKEALL_OUTPUT" >> "$GITHUB_OUTPUT"
echo "$(git status --porcelain)" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Create PR
id: createPR
if: ${{ steps.bumpVersions.outputs.changes != '' }}
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e
with:
token: ${{ secrets.MINIKUBE_BOT_PAT }}
commit-message: 'Kicbase/ISO: Update dependency versions'
committer: minikube-bot <minikube-bot@google.com>
author: minikube-bot <minikube-bot@google.com>
branch: bump_iso_image_versions
branch-suffix: short-commit-hash
push-to-fork: minikube-bot/minikube
base: master
delete-branch: true
title: 'deubg pr: update all dependencies'
body: |
Changelog:
${{ steps.bumpVersions.outputs.changelog }}

View File

@ -21,9 +21,9 @@ jobs:
- name: Bump amd-gpu-device-plugin version
id: bumpAmdDevicePlugin
run: |
echo "OLD_VERSION=$(DEP=amd-gpu-device-plugin make get-dependency-version)" >> "$GITHUB_OUTPUT"
make update-amd-gpu-device-plugin-version
echo "NEW_VERSION=$(DEP=amd-gpu-device-plugin make get-dependency-version)" >> "$GITHUB_OUTPUT"
echo "OLD_VERSION=$(DEP=amd-device-gpu-plugin make get-dependency-version)" >> "$GITHUB_OUTPUT"
make update-amd-device-plugin-version
echo "NEW_VERSION=$(DEP=amd-device-gpu-plugin make get-dependency-version)" >> "$GITHUB_OUTPUT"
# The following is to support multiline with GITHUB_OUTPUT, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
echo "changes<<EOF" >> "$GITHUB_OUTPUT"
echo "$(git status --porcelain)" >> "$GITHUB_OUTPUT"
@ -45,4 +45,4 @@ jobs:
body: |
The [k8s-device-plugin](https://github.com/ROCm/k8s-device-plugin) project released a new k8s-device-plugin image
This PR was auto-generated by `make update-amd-gpu-device-plugin-version` using [update-amd-gpu-device-plugin-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-amd-gpu-device-plugin-version.yml) CI Workflow.
This PR was auto-generated by `make update-amd-device-plugin-version` using [update-amd-gpu-device-plugin-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-amd-gpu-device-plugin-version.yml) CI Workflow.

View File

@ -21,9 +21,9 @@ jobs:
- name: Bump cloud-spanner-emulator version
id: bumpCloudSpannerEmulator
run: |
echo "OLD_VERSION=$(DEP=cloud-spanner make get-dependency-version)" >> "$GITHUB_OUTPUT"
echo "OLD_VERSION=$(DEP=cloud-spanner-emulator make get-dependency-version)" >> "$GITHUB_OUTPUT"
make update-cloud-spanner-emulator-version
echo "NEW_VERSION=$(DEP=cloud-spanner make get-dependency-version)" >> "$GITHUB_OUTPUT"
echo "NEW_VERSION=$(DEP=cloud-spanner-emulator make get-dependency-version)" >> "$GITHUB_OUTPUT"
# The following is to support multiline with GITHUB_OUTPUT, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
echo "changes<<EOF" >> "$GITHUB_OUTPUT"
echo "$(git status --porcelain)" >> "$GITHUB_OUTPUT"

View File

@ -21,9 +21,9 @@ jobs:
- name: Bump Golang Versions
id: bumpGolang
run: |
echo "OLD_VERSION=$(DEP=go make get-dependency-version)" >> "$GITHUB_OUTPUT"
echo "OLD_VERSION=$(DEP=golang make get-dependency-version)" >> "$GITHUB_OUTPUT"
make update-golang-version
echo "NEW_VERSION=$(DEP=go make get-dependency-version)" >> "$GITHUB_OUTPUT"
echo "NEW_VERSION=$(DEP=golang make get-dependency-version)" >> "$GITHUB_OUTPUT"
# The following is to support multiline with GITHUB_OUTPUT, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
echo "changes<<EOF" >> "$GITHUB_OUTPUT"
echo "$(git status --porcelain)" >> "$GITHUB_OUTPUT"

140
Makefile
View File

@ -35,12 +35,12 @@ 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.24.0
GO_VERSION ?= 1.24.5
# set GOTOOLCHAIN to GO_VERSION to override any toolchain version specified in
# go.mod (ref: https://go.dev/doc/toolchain#GOTOOLCHAIN)
export GOTOOLCHAIN := go$(GO_VERSION)
# update this only by running `make update-golang-version`
GO_K8S_VERSION_PREFIX ?= v1.33.0
GO_K8S_VERSION_PREFIX ?= v1.34.0
# replace "x.y.0" => "x.y". kube-cross and go.dev/dl use different formats for x.y.0 go versions
KVM_GO_VERSION ?= $(GO_VERSION:.0=)
@ -1033,28 +1033,6 @@ help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: update-golang-version
update-golang-version:
cd hack && go run update/golang_version/update_golang_version.go
.PHONY: update-kubernetes-version
update-kubernetes-version:
cd hack && go run update/kubernetes_version/update_kubernetes_version.go
.PHONY: update-golint-version
update-golint-version:
cd hack && go run update/golint_version/update_golint_version.go
.PHONY: update-preload-version
update-preload-version:
cd hack && go run update/preload_version/update_preload_version.go
.PHONY: update-kubeadm-constants
update-kubeadm-constants:
cd hack && go run update/kubeadm_constants/update_kubeadm_constants.go
gofmt -w pkg/minikube/constants/constants_kubeadm_images.go
.PHONY: stress
stress: ## run the stress tests
go test -test.v -test.timeout=2h ./test/stress -loops=10 | tee "./out/testout_$(COMMIT_SHORT).txt"
@ -1071,176 +1049,202 @@ cpu-benchmark-autopause: ## run the cpu usage auto-pause benchmark
time-to-k8s-benchmark:
./hack/benchmark/time-to-k8s/time-to-k8s.sh
.PHONY: update-golang-version
update-golang-version:
cd hack && go run update/golang_version/golang_version.go
.PHONY: update-kubernetes-version
update-kubernetes-version:
cd hack && go run update/kubernetes_version/kubernetes_version.go
.PHONY: update-golint-version
update-golint-version:
cd hack && go run update/golint_version/golint_version.go
.PHONY: update-preload-version
update-preload-version:
cd hack && go run update/preload_version/preload_version.go
.PHONY: update-kubeadm-constants
update-kubeadm-constants:
cd hack && go run update/kubeadm_constants/kubeadm_constants.go
gofmt -w pkg/minikube/constants/constants_kubeadm_images.go
.PHONY: update-gopogh-version
update-gopogh-version: ## update gopogh version
cd hack && go run update/gopogh_version/update_gopogh_version.go
cd hack && go run update/gopogh_version/gopogh_version.go
.PHONY: update-gotestsum-version
update-gotestsum-version:
cd hack && go run update/gotestsum_version/update_gotestsum_version.go
cd hack && go run update/gotestsum_version/gotestsum_version.go
.PHONY: update-gh-version
update-gh-version:
cd hack && go run update/gh_version/update_gh_version.go
cd hack && go run update/gh_version/gh_version.go
.PHONY: update-docsy-version
update-docsy-version:
cd hack && go run update/docsy_version/update_docsy_version.go
cd hack && go run update/docsy_version/docsy_version.go
.PHONY: update-hugo-version
update-hugo-version:
cd hack && go run update/hugo_version/update_hugo_version.go
cd hack && go run update/hugo_version/hugo_version.go
.PHONY: update-cloud-spanner-emulator-version
update-cloud-spanner-emulator-version:
cd hack && go run update/cloud_spanner_emulator_version/update_cloud_spanner_emulator_version.go
cd hack && go run update/cloud_spanner_emulator_version/cloud_spanner_emulator_version.go
.PHONY: update-containerd-version
update-containerd-version:
cd hack && go run update/containerd_version/update_containerd_version.go
cd hack && go run update/containerd_version/containerd_version.go
.PHONY: update-buildkit-version
update-buildkit-version:
cd hack && go run update/buildkit_version/update_buildkit_version.go
cd hack && go run update/buildkit_version/buildkit_version.go
.PHONY: update-cri-o-version
update-cri-o-version:
cd hack && go run update/cri-o_version/update_cri-o_version.go
cd hack && go run update/cri_o_version/cri_o_version.go
.PHONY: update-crun-version
update-crun-version:
cd hack && go run update/crun_version/update_crun_version.go
cd hack && go run update/crun_version/crun_version.go
.PHONY: update-metrics-server-version
update-metrics-server-version:
cd hack && go run update/metrics_server_version/update_metrics_server_version.go
cd hack && go run update/metrics_server_version/metrics_server_version.go
.PHONY: update-runc-version
update-runc-version:
cd hack && go run update/runc_version/update_runc_version.go
cd hack && go run update/runc_version/runc_version.go
.PHONY: update-docker-version
update-docker-version:
cd hack && go run update/docker_version/update_docker_version.go
cd hack && go run update/docker_version/docker_version.go
.PHONY: update-ubuntu-version
update-ubuntu-version:
cd hack && go run update/ubuntu_version/update_ubuntu_version.go
cd hack && go run update/ubuntu_version/ubuntu_version.go
.PHONY: update-cni-plugins-version
update-cni-plugins-version:
cd hack && go run update/cni_plugins_version/update_cni_plugins_version.go
cd hack && go run update/cni_plugins_version/cni_plugins_version.go
.PHONY: update-gcp-auth-version
update-gcp-auth-version:
cd hack && go run update/gcp_auth_version/update_gcp_auth_version.go
cd hack && go run update/gcp_auth_version/gcp_auth_version.go
.PHONY: update-kubernetes-versions-list
update-kubernetes-versions-list:
cd hack && go run update/kubernetes_versions_list/update_kubernetes_versions_list.go
cd hack && go run update/kubernetes_versions_list/kubernetes_versions_list.go
.PHONY: update-ingress-version
update-ingress-version:
cd hack && go run update/ingress_version/update_ingress_version.go
cd hack && go run update/ingress_version/ingress_version.go
.PHONY: update-flannel-version
update-flannel-version:
cd hack && go run update/flannel_version/update_flannel_version.go
cd hack && go run update/flannel_version/flannel_version.go
.PHONY: update-inspektor-gadget-version
update-inspektor-gadget-version:
cd hack && go run update/inspektor_gadget_version/update_inspektor_gadget_version.go
cd hack && go run update/inspektor_gadget_version/inspektor_gadget_version.go
.PHONY: update-calico-version
update-calico-version:
cd hack && go run update/calico_version/update_calico_version.go
cd hack && go run update/calico_version/calico_version.go
.PHONY: update-cri-dockerd-version
update-cri-dockerd-version:
cd hack && go run update/cri_dockerd_version/update_cri_dockerd_version.go
cd hack && go run update/cri_dockerd_version/cri_dockerd_version.go
.PHONY: update-go-github-version
update-go-github-version:
cd hack && go run update/go_github_version/update_go_github_version.go
cd hack && go run update/go_github_version/go_github_version.go
.PHONY: update-docker-buildx-version
update-docker-buildx-version:
cd hack && go run update/docker_buildx_version/update_docker_buildx_version.go
cd hack && go run update/docker_buildx_version/docker_buildx_version.go
.PHONY: update-nerdctl-version
update-nerdctl-version:
cd hack && go run update/nerdctl_version/update_nerdctl_version.go
cd hack && go run update/nerdctl_version/nerdctl_version.go
.PHONY: update-crictl-version
update-crictl-version:
cd hack && go run update/crictl_version/update_crictl_version.go
cd hack && go run update/crictl_version/crictl_version.go
.PHONY: update-kindnetd-version
update-kindnetd-version:
cd hack && go run update/kindnetd_version/update_kindnetd_version.go
cd hack && go run update/kindnetd_version/kindnetd_version.go
.PHONY: update-istio-operator-version
update-istio-operator-version:
cd hack && go run update/istio_operator_version/update_istio_operator_version.go
cd hack && go run update/istio_operator_version/istio_operator_version.go
.PHONY: update-registry-version
update-registry-version:
cd hack && go run update/registry_version/update_registry_version.go
cd hack && go run update/registry_version/registry_version.go
.PHONY: update-volcano-version
update-volcano-version:
cd hack && go run update/volcano_version/update_volcano_version.go
cd hack && go run update/volcano_version/volcano_version.go
.PHONY: update-kong-version
update-kong-version:
cd hack && go run update/kong_version/update_kong_version.go
cd hack && go run update/kong_version/kong_version.go
.PHONY: update-kong-ingress-controller-version
update-kong-ingress-controller-version:
cd hack && go run update/kong_ingress_controller_version/update_kong_ingress_controller_version.go
cd hack && go run update/kong_ingress_controller_version/kong_ingress_controller_version.go
.PHONY: update-nvidia-device-plugin-version
update-nvidia-device-plugin-version:
cd hack && go run update/nvidia_device_plugin_version/update_nvidia_device_plugin_version.go
cd hack && go run update/nvidia_device_plugin_version/nvidia_device_plugin_version.go
.PHONY: update-amd-gpu-device-plugin-version
update-amd-gpu-device-plugin-version:
cd hack && go run update/amd_device_plugin_version/update_amd_device_plugin_version.go
# for amd gpu
.PHONY: update-amd-device-plugin-version
update-amd-device-plugin-version:
cd hack && go run update/amd_device_gpu_plugin_version/amd_device_gpu_plugin_version.go
.PHONY: update-nerdctld-version
update-nerdctld-version:
cd hack && go run update/nerdctld_version/update_nerdctld_version.go
cd hack && go run update/nerdctld_version/nerdctld_version.go
.PHONY: update-kubectl-version
update-kubectl-version:
cd hack && go run update/kubectl_version/update_kubectl_version.go
cd hack && go run update/kubectl_version/kubectl_version.go
.PHONY: update-site-node-version
update-site-node-version:
cd hack && go run update/site_node_version/update_site_node_version.go
cd hack && go run update/site_node_version/site_node_version.go
.PHONY: update-cilium-version
update-cilium-version:
cd hack && go run update/cilium_version/update_cilium_version.go
cd hack && go run update/cilium_version/cilium_version.go
.PHONY: update-yakd-version
update-yakd-version:
cd hack && go run update/yakd_version/update_yakd_version.go
cd hack && go run update/yakd_version/yakd_version.go
.PHONY: update-kube-registry-proxy-version
update-kube-registry-proxy-version:
cd hack && go run update/kube_registry_proxy_version/update_kube_registry_proxy_version.go
cd hack && go run update/kube_registry_proxy_version/kube_registry_proxy_version.go
.PHONY: update-headlamp-version
update-headlamp-version:
cd hack && go run update/headlamp_version/update_headlamp_version.go
cd hack && go run update/headlamp_version/headlamp_version.go
.PHONY: update-kube-vip-version
update-kube-vip-version:
cd hack && go run update/kube_vip_version/update_kube_vip_version.go
cd hack && go run update/kube_vip_version/kube_vip_version.go
# used by update- Targets to get before/after versions of tools it updates
# example usage echo "OLD_VERSION=$(DEP=node make get-dependency-version)" >> "$GITHUB_OUTPUT"
.PHONY: get-dependency-verison
get-dependency-version:
@(cd hack && go run update/get_version/get_version.go)
# runs update on all hack/update/components only used for debugging purposes, not meant to be used regularly
.PHONY: _update-all
_update-all:
@(cd hack && go run update/update_all/update_all.go)

View File

@ -45,14 +45,20 @@ func main() {
version := strings.TrimPrefix(stable.Tag, "v")
// Add the cilium repo to helm
if err := exec.Command("helm", "repo", "add", "cilium", "https://helm.cilium.io/").Run(); err != nil {
klog.Fatal(err)
addRepoCmd := exec.Command("helm", "repo", "add", "cilium", "https://helm.cilium.io/")
if err := addRepoCmd.Run(); err != nil {
klog.Fatalf("failed to run command %v: %v", addRepoCmd.Args, err)
}
if err := exec.Command("helm", "repo", "update").Run(); err != nil {
klog.Fatalf("failed to update help repo %v", err)
}
// Generate the cilium YAML
yamlBytes, err := exec.Command("helm", "template", "cilium", "cilium/cilium", "--version", version, "--namespace", "kube-system").Output()
templateCmd := exec.Command("helm", "template", "cilium", "cilium/cilium", "--version", version, "--namespace", "kube-system")
yamlBytes, err := templateCmd.Output()
if err != nil {
klog.Fatal(err)
klog.Fatalf("failed to run command %v: %v", templateCmd.Args, err)
}
yaml := string(yamlBytes)

View File

@ -20,6 +20,7 @@ import (
"log"
"os"
"regexp"
"strings"
)
const (
@ -33,11 +34,11 @@ type dependency struct {
}
var dependencies = map[string]dependency{
"amd-gpu-device-plugin": {addonsFile, `rocm/k8s-device-plugin:(.*)@`},
"amd-device-gpu-plugin": {addonsFile, `rocm/k8s-device-plugin:(.*)@`},
"buildkit": {"deploy/iso/minikube-iso/arch/x86_64/package/buildkit-bin/buildkit-bin.mk", `BUILDKIT_BIN_VERSION = (.*)`},
"calico": {"pkg/minikube/bootstrapper/images/images.go", `calicoVersion = "(.*)"`},
"cilium": {"pkg/minikube/cni/cilium.yaml", `quay.io/cilium/cilium:(.*)@`},
"cloud-spanner": {addonsFile, `cloud-spanner-emulator/emulator:(.*)@`},
"cloud-spanner-emulator": {addonsFile, `cloud-spanner-emulator/emulator:(.*)@`},
"cni-plugins": {"deploy/iso/minikube-iso/arch/x86_64/package/cni-plugins-latest/cni-plugins-latest.mk", `CNI_PLUGINS_LATEST_VERSION = (.*)`},
"containerd": {"deploy/iso/minikube-iso/arch/x86_64/package/containerd-bin/containerd-bin.mk", `CONTAINERD_BIN_VERSION = (.*)`},
"cri-dockerd": {dockerfile, `CRI_DOCKERD_VERSION="(.*)"`},
@ -49,7 +50,7 @@ var dependencies = map[string]dependency{
"flannel": {"pkg/minikube/cni/flannel.yaml", `flannel:(.*)`},
"gcp-auth": {addonsFile, `k8s-minikube/gcp-auth-webhook:(.*)@`},
"gh": {"hack/jenkins/installers/check_install_gh.sh", `GH_VERSION="(.*)"`},
"go": {"Makefile", `\nGO_VERSION \?= (.*)`},
"golang": {"Makefile", `\nGO_VERSION \?= (.*)`},
"go-github": {"go.mod", `github\.com\/google\/go-github\/.* (.*)`},
"golint": {"Makefile", `GOLINT_VERSION \?= (.*)`},
"gopogh": {"hack/jenkins/installers/check_install_gopogh.sh", `github.com/medyagh/gopogh/cmd/gopogh@(.*)`},
@ -82,6 +83,7 @@ func main() {
if depName == "" {
log.Fatalf("the environment variable 'DEP' needs to be set")
}
depName = standrizeComponentName(depName)
dep, ok := dependencies[depName]
if !ok {
log.Fatalf("%s is not a valid dependency", depName)
@ -101,3 +103,12 @@ func main() {
}
os.Stdout.Write(submatches[1])
}
// some components have _ or - in their names vs their make folders, standarizing for automation such as as update-all
func standrizeComponentName(name string) string {
// Convert the component name to lowercase and replace underscores with hyphens
name = strings.ToLower(name)
name = strings.ReplaceAll(name, "_", "-")
name = strings.ReplaceAll(name, "-version", "")
return name
}

View File

@ -70,13 +70,14 @@ func main() {
func generateSchema() map[string]update.Item {
files := []string{
"cmd/minikube/cmd/config/kubernetes_version.go",
"hack/preload-images/kubernetes.go",
"hack/update/github.go",
"hack/update/ingress_version/update_ingress_version.go",
"hack/update/kubeadm_constants/update_kubeadm_constants.go",
"hack/update/kubernetes_versions_list/update_kubernetes_versions_list.go",
"hack/update/site_node_version/update_site_node_version.go",
"pkg/perf/monitor/github.go",
"hack/preload-images/kubernetes.go",
"hack/update/kubeadm_constants/kubeadm_constants.go",
"hack/update/ingress_version/ingress_version.go",
"hack/update/site_node_version/site_node_version.go",
"hack/update/go_github_version/go_github_version.go",
"hack/update/kubernetes_versions_list/kubernetes_versions_list.go",
"hack/update/github.go",
}
schema := make(map[string]update.Item)

View File

@ -83,7 +83,7 @@ func (i *Item) apply(data interface{}) error {
}
// Apply applies concrete update plan (schema + data) to local filesystem repo
func Apply(schema map[string]Item, data interface{}) {
func Apply(schema map[string]Item, data interface{}) error {
schema, pretty, err := GetPlan(schema, data)
if err != nil {
klog.Fatalf("Unable to parse schema: %v\n%s", err, pretty)
@ -93,11 +93,13 @@ func Apply(schema map[string]Item, data interface{}) {
changed, err := fsUpdate(FSRoot, schema, data)
if err != nil {
klog.Errorf("Unable to update local repo: %v", err)
return err
} else if !changed {
klog.Infof("Local repo update skipped: nothing changed")
} else {
klog.Infof("Local repo successfully updated")
}
return nil
}
// GetPlan returns concrete plan replacing placeholders in schema with actual data values, returns JSON-formatted representation of the plan and any error occurred.

View File

@ -0,0 +1,148 @@
/*
Copyright 2025 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"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)
var (
// These components do not support before/after version comparison
noVersionCheck = map[string]bool{
"docsy_version": true,
"kubeadm_constants": true,
"kubernetes_version": true,
"kubernetes_versions_list": true,
}
// Skip these components from auto-updating
skipList = map[string]bool{
"get_version": true, // self (internal)
"update_all": true, // self
"k8s-lib": true, // not needed anymore (TODO: remove in future)
"amd_device_gpu_plugin_version": true, // sem vers issue https://github.com/ROCm/k8s-device-plugin/issues/144eadm_auto_build
"istio_operator_version": true, // till this is fixed https://github.com/istio/istio/issues/57185
"kicbase_version": true, // This one is not related to auto updating, this is a tool used by kicbae_auto_build
"preload_version": true, // This is an internal tool to bump the preload version, not a component update
}
)
func shouldSkip(component string) bool {
if runtime.GOOS != "linux" && component == "kubeadm_constants" { // kubeadm constants update job only works on linux
log.Printf("Skipping %s on non-linux OS: %s", component, runtime.GOOS)
return true
}
return skipList[component]
}
func getVersion(component string) (string, error) {
cmd := exec.Command("go", "run", "update/get_version/get_version.go")
cmd.Env = append(os.Environ(), fmt.Sprintf("DEP=%s", component))
var out bytes.Buffer
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
log.Printf("failed to get version for %s: %v", component, err)
log.Printf("command output: %s", out.String())
return "", err
}
return strings.TrimSpace(out.String()), nil
}
func main() {
const updateDir = "update"
const maxUpdates = 100
cwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
log.Println("Starting update process in:", cwd)
entries, err := os.ReadDir(updateDir)
if err != nil {
log.Fatalf("Failed to read directory %s: %v", updateDir, err)
}
var changes []string
updatesRun := 0
for _, entry := range entries {
if !entry.IsDir() || updatesRun >= maxUpdates {
continue
}
component := entry.Name()
if shouldSkip(component) {
continue
}
log.Printf("Processing %s...\n", component)
var oldVersion string
if !noVersionCheck[component] {
oldVersion, err = getVersion(component)
if err != nil {
log.Fatalf("Could not get old version for %s: %v", component, err)
}
}
script := filepath.Join(updateDir, component, fmt.Sprintf("%s.go", component))
cmd := exec.Command("go", "run", script)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Fatalf("Failed to update %s: %v", component, err)
}
if !noVersionCheck[component] {
newVersion, err := getVersion(component)
if err != nil {
log.Printf("Could not get new version for %s: %v", component, err)
continue
}
if oldVersion != newVersion {
change := fmt.Sprintf("- **%s:** `%s` -> `%s`", component, oldVersion, newVersion)
changes = append(changes, change)
fmt.Println(change)
} else {
fmt.Printf("No change for %s.\n", component)
}
fmt.Println()
}
updatesRun++
}
fmt.Println("---")
fmt.Println("Updated components summary:")
fmt.Println(strings.Join(changes, "\n"))
// Output machine-readable summary for GitHub Actions
fmt.Printf("updates<<EOF\n%s\nEOF\n", strings.Join(changes, "\n"))
}