Skip to content

Commit 4ebec48

Browse files
authored
Prevent Unnecessary Version Bumps in go.mod During Go Version Updates (#20781)
* Prevent Unnecessary Version Bumps in `go.mod` During Go Version Updates This PR addresses issue #20770, where the minikube automation (triggered by make `update-golang-version`) unnecessarily bumped minor or patch versions in `go.mod` when updating the Go version. Following Kubernetes' practice, which avoids such bumps in `go.mod`, this change ensures only the go directive is updated to the stable Go version. **Changes:** - Added `go.mod` to the schema map in `hack/update/golang_version/update_golang_version.go` with a regex (go 1\.\d+\.\d+) to update the go directive to {{.StableVersion}} (e.g., go 1.24.2). - This ensures the automation updates only the go directive without modifying module dependencies, aligning with Kubernetes' `go.mod` behavior. **Impact:** - Running make `update-golang-version` now updates the go directive (e.g., from go 1.22.3 to go 1.24.2) without unintended dependency version bumps. - Tested by setting go 1.22.3 in go.mod, running go mod tidy and make update-golang-version, and verifying only the go directive and toolchain changed. fixes: #20773 * Pin `go.mod` to Major.Minor Go Version (e.g., `1.24.0`) **Description**: Fixes #20773 by updating the automation to pin the `go` directive in `go.mod` to the major.minor Go version (e.g., `1.24.0`) instead of the full version (e.g., `1.24.2`), aligning with Kubernetes’ `go.mod`. This prevents breaking users relying on minikube packages. **Changes**: - Modified `hack/update/golang_version/update_golang_version.go` to compute `MajorMinor` version (e.g., `1.24.0`) from `StableVersion`. - Updated `schema` to set `go.mod`’s `go` directive to `{{.MajorMinor}}`. - Tested by setting `go 1.23.4`, running `make update-golang-version`, and verifying `go 1.24.0` with no dependency bumps. **Closes**: #20773 * Reverted all 66 files to upstream master except update_golang_version.go
1 parent 38a80fe commit 4ebec48

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

hack/update/golang_version/update_golang_version.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ var (
3636
}
3737

3838
schema = map[string]update.Item{
39+
"go.mod": {
40+
Replace: map[string]string{
41+
`go 1\.\d+\.\d+`: `go {{.MajorMinor}}`, // Match and replace only the major.minor Go version
42+
},
43+
},
3944
"Makefile": {
4045
Replace: map[string]string{
4146
// searching for 1.* so it does NOT match "KVM_GO_VERSION ?= $(GO_VERSION:.0=)" in the Makefile
@@ -74,8 +79,8 @@ var (
7479
// Data holds stable Golang version - in full and in <major>.<minor> format
7580
type Data struct {
7681
StableVersion string
82+
MajorMinor string // Major.minor version (e.g., 1.24.0)
7783
K8SVersion string // as of v1.23.0 Kubernetes uses k8s version in golang image name because: https://github.com/kubernetes/kubernetes/pull/103692#issuecomment-908659826
78-
7984
}
8085

8186
func main() {
@@ -91,8 +96,13 @@ func main() {
9196
klog.Warningf("Golang stable version is a release candidate, skipping: %s", stable)
9297
return
9398
}
94-
data := Data{StableVersion: stable, K8SVersion: k8sVersion}
95-
klog.Infof("Golang stable version: %s", data.StableVersion)
99+
// Derive major.minor version (e.g., 1.24.0 from 1.24.2)
100+
majorMinor := stable
101+
if parts := strings.Split(stable, "."); len(parts) >= 3 {
102+
majorMinor = fmt.Sprintf("%s.%s.0", parts[0], parts[1])
103+
}
104+
data := Data{StableVersion: stable, MajorMinor: majorMinor, K8SVersion: k8sVersion}
105+
klog.Infof("Golang stable version: %s, MajorMinor: %s", data.StableVersion, data.MajorMinor)
96106

97107
update.Apply(schema, data)
98108

0 commit comments

Comments
 (0)