Skip to content

Commit a0b44a5

Browse files
authored
Merge pull request #7285 from twz123/backport-7280-to-release-1.35
[Backport release-1.35] Check Go module versions more thoroughly
2 parents adf86fb + 7f10862 commit a0b44a5

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ require (
272272
gopkg.in/yaml.v2 v2.4.0 // indirect
273273
gopkg.in/yaml.v3 v3.0.1 // indirect
274274
k8s.io/controller-manager v0.35.2 // indirect
275-
k8s.io/cri-client v0.35.1 // indirect
275+
k8s.io/cri-client v0.35.2 // indirect
276276
k8s.io/klog/v2 v2.130.1 // indirect
277277
k8s.io/kms v0.35.2 // indirect
278278
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect

pkg/constant/constant_test.go

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,27 @@ func TestKubernetesModuleVersions(t *testing.T) {
6969
}
7070
},
7171
func(t *testing.T, pkgPath string, module *packages.Module) bool {
72-
modVer := module.Version
72+
expected := "v" + kubernetesVersion
7373
if module.Path != "k8s.io/kubernetes" {
7474
// All modules besides Kubernetes itself use v0 instead of v1.
75-
modVer = strings.Replace(modVer, "v0.", "v1.", 1)
75+
if suffix, found := strings.CutPrefix(expected, "v1."); found {
76+
expected = "v0." + suffix
77+
}
7678
}
7779

78-
return !assert.Equal(t, "v"+kubernetesVersion, modVer,
80+
ok := assert.Equal(t, expected, module.Version,
7981
"Module version for package %s doesn't match: %+#v",
80-
pkgPath, module,
81-
)
82+
pkgPath, module)
83+
if module.Replace == nil {
84+
return ok
85+
}
86+
87+
ok = assert.Nil(t, module.Replace.Replace) && ok
88+
ok = assert.Equal(t, module.Path, module.Replace.Path) && ok
89+
ok = assert.Equal(t, expected, module.Replace.Version,
90+
"Replacing module version for package %s doesn't match: %+#v",
91+
pkgPath, module.Replace) && ok
92+
return ok
8293
},
8394
)
8495
}
@@ -94,9 +105,11 @@ func TestEtcdModuleVersions(t *testing.T) {
94105
strings.HasSuffix(modulePath, "/v"+etcdVersionParts[0])
95106
},
96107
func(t *testing.T, pkgPath string, module *packages.Module) bool {
97-
return !assert.Equal(t, "v"+etcdVersion, module.Version,
108+
ok := assert.Equal(t, "v"+etcdVersion, module.Version,
98109
"Module version for package %s doesn't match: %+#v",
99110
)
111+
ok = assert.Nil(t, module.Replace) && ok
112+
return ok
100113
},
101114
)
102115
}
@@ -109,10 +122,11 @@ func TestContainerdModuleVersions(t *testing.T) {
109122
return modulePath == "github.com/containerd/containerd"
110123
},
111124
func(t *testing.T, pkgPath string, module *packages.Module) bool {
112-
return !assert.Equal(t, "v"+containerdVersion, module.Version,
125+
ok := assert.Equal(t, "v"+containerdVersion, module.Version,
113126
"Module version for package %s doesn't match: %+#v",
114-
pkgPath, module,
115127
)
128+
ok = assert.Nil(t, module.Replace) && ok
129+
return ok
116130
},
117131
)
118132
}
@@ -125,10 +139,11 @@ func TestKonnectivityModuleVersions(t *testing.T) {
125139
return strings.HasPrefix(modulePath, "sigs.k8s.io/apiserver-network-proxy/")
126140
},
127141
func(t *testing.T, pkgPath string, module *packages.Module) bool {
128-
return !assert.Equal(t, "v"+konnectivityVersion, module.Version,
142+
ok := assert.Equal(t, "v"+konnectivityVersion, module.Version,
129143
"Module version for package %s doesn't match: %+#v",
130-
pkgPath, module,
131144
)
145+
ok = assert.Nil(t, module.Replace) && ok
146+
return ok
132147
},
133148
)
134149
}
@@ -161,15 +176,10 @@ func checkPackageModules(t *testing.T, filter func(modulePath string) bool, chec
161176

162177
packages.Visit(pkgs, func(p *packages.Package) bool {
163178
if p.Module != nil && filter(p.Module.Path) {
164-
actual := p.Module
165-
for actual.Replace != nil {
166-
actual = actual.Replace
167-
}
168-
169-
if !failedModules[actual.Path] {
179+
if !failedModules[p.Module.Path] {
170180
numMatched++
171-
if !check(t, p.PkgPath, actual) {
172-
failedModules[actual.Path] = true
181+
if !check(t, p.PkgPath, p.Module) {
182+
failedModules[p.Module.Path] = true
173183
}
174184
}
175185
}

0 commit comments

Comments
 (0)