Skip to content

Commit 23d6377

Browse files
authored
Merge pull request kubernetes#130019 from yongruilin/version-intro
KEP-4330: extend version information with more detailed version fields
2 parents 129661b + 14934b4 commit 23d6377

File tree

19 files changed

+436
-68
lines changed

19 files changed

+436
-68
lines changed

api/openapi-spec/swagger.json

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/openapi-spec/v3/version_openapi.json

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controlplane/instance_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,14 @@ func TestVersion(t *testing.T) {
243243
}
244244
expectedInfo := utilversion.Get()
245245
kubeVersion := compatibility.DefaultKubeEffectiveVersionForTest().BinaryVersion()
246+
emulationVersion := compatibility.DefaultKubeEffectiveVersionForTest().EmulationVersion()
247+
minCompatibilityVersion := compatibility.DefaultKubeEffectiveVersionForTest().MinCompatibilityVersion()
246248
expectedInfo.Major = fmt.Sprintf("%d", kubeVersion.Major())
247249
expectedInfo.Minor = fmt.Sprintf("%d", kubeVersion.Minor())
250+
expectedInfo.EmulationMajor = fmt.Sprintf("%d", emulationVersion.Major())
251+
expectedInfo.EmulationMinor = fmt.Sprintf("%d", emulationVersion.Minor())
252+
expectedInfo.MinCompatibilityMajor = fmt.Sprintf("%d", minCompatibilityVersion.Major())
253+
expectedInfo.MinCompatibilityMinor = fmt.Sprintf("%d", minCompatibilityVersion.Minor())
248254

249255
if !reflect.DeepEqual(expectedInfo, info) {
250256
t.Errorf("Expected %#v, Got %#v", expectedInfo, info)

pkg/generated/openapi/zz_generated.openapi.go

Lines changed: 36 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apiextensions-apiserver/pkg/generated/openapi/zz_generated.openapi.go

Lines changed: 36 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apimachinery/pkg/util/version/version.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ type Version struct {
3333
semver bool
3434
preRelease string
3535
buildMetadata string
36-
info apimachineryversion.Info
3736
}
3837

3938
var (
@@ -456,27 +455,28 @@ func (v *Version) Compare(other string) (int, error) {
456455
return v.compareInternal(ov), nil
457456
}
458457

459-
// WithInfo returns copy of the version object with requested info
458+
// WithInfo returns copy of the version object.
459+
// Deprecated: The Info field has been removed from the Version struct. This method no longer modifies the Version object.
460460
func (v *Version) WithInfo(info apimachineryversion.Info) *Version {
461461
result := *v
462-
result.info = info
463462
return &result
464463
}
465464

465+
// Info returns the version information of a component.
466+
// Deprecated: Use Info() from effective version instead.
466467
func (v *Version) Info() *apimachineryversion.Info {
467468
if v == nil {
468469
return nil
469470
}
470471
// in case info is empty, or the major and minor in info is different from the actual major and minor
471-
v.info.Major = itoa(v.Major())
472-
v.info.Minor = itoa(v.Minor())
473-
if v.info.GitVersion == "" {
474-
v.info.GitVersion = v.String()
472+
return &apimachineryversion.Info{
473+
Major: Itoa(v.Major()),
474+
Minor: Itoa(v.Minor()),
475+
GitVersion: v.String(),
475476
}
476-
return &v.info
477477
}
478478

479-
func itoa(i uint) string {
479+
func Itoa(i uint) string {
480480
if i == 0 {
481481
return ""
482482
}

staging/src/k8s.io/apimachinery/pkg/version/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ limitations under the License.
1616

1717
// +k8s:openapi-gen=true
1818

19-
// Package version supplies the type for version information collected at build time.
19+
// Package version supplies the type for version information.
2020
package version

staging/src/k8s.io/apimachinery/pkg/version/types.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,25 @@ package version
2020
// TODO: Add []string of api versions supported? It's still unclear
2121
// how we'll want to distribute that information.
2222
type Info struct {
23-
Major string `json:"major"`
24-
Minor string `json:"minor"`
25-
GitVersion string `json:"gitVersion"`
26-
GitCommit string `json:"gitCommit"`
27-
GitTreeState string `json:"gitTreeState"`
28-
BuildDate string `json:"buildDate"`
29-
GoVersion string `json:"goVersion"`
30-
Compiler string `json:"compiler"`
31-
Platform string `json:"platform"`
23+
// Major is the major version of the binary version
24+
Major string `json:"major"`
25+
// Minor is the minor version of the binary version
26+
Minor string `json:"minor"`
27+
// EmulationMajor is the major version of the emulation version
28+
EmulationMajor string `json:"emulationMajor,omitempty"`
29+
// EmulationMinor is the minor version of the emulation version
30+
EmulationMinor string `json:"emulationMinor,omitempty"`
31+
// MinCompatibilityMajor is the major version of the minimum compatibility version
32+
MinCompatibilityMajor string `json:"minCompatibilityMajor,omitempty"`
33+
// MinCompatibilityMinor is the minor version of the minimum compatibility version
34+
MinCompatibilityMinor string `json:"minCompatibilityMinor,omitempty"`
35+
GitVersion string `json:"gitVersion"`
36+
GitCommit string `json:"gitCommit"`
37+
GitTreeState string `json:"gitTreeState"`
38+
BuildDate string `json:"buildDate"`
39+
GoVersion string `json:"goVersion"`
40+
Compiler string `json:"compiler"`
41+
Platform string `json:"platform"`
3242
}
3343

3444
// String returns info as a human-friendly version string.

staging/src/k8s.io/apiserver/pkg/server/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ func installAPI(name string, s *GenericAPIServer, c *Config) {
11061106
}
11071107
}
11081108

1109-
routes.Version{Version: c.EffectiveVersion.BinaryVersion().Info()}.Install(s.Handler.GoRestfulContainer)
1109+
routes.Version{Version: c.EffectiveVersion.Info()}.Install(s.Handler.GoRestfulContainer)
11101110

11111111
if c.EnableDiscovery {
11121112
wrapped := discoveryendpoint.WrapAggregatedDiscoveryToHandler(s.DiscoveryGroupManager, s.AggregatedDiscoveryGroupManager)

staging/src/k8s.io/apiserver/pkg/server/options/serving_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
restclient "k8s.io/client-go/rest"
4848
cliflag "k8s.io/component-base/cli/flag"
4949
basecompatibility "k8s.io/component-base/compatibility"
50+
baseversion "k8s.io/component-base/version"
5051
"k8s.io/klog/v2/ktesting"
5152
netutils "k8s.io/utils/net"
5253
)
@@ -277,9 +278,8 @@ func TestServerRunWithSNI(t *testing.T) {
277278

278279
// launch server
279280
config := setUp(t)
280-
v := fakeVersion()
281-
config.EffectiveVersion = basecompatibility.NewEffectiveVersionFromString(v.String(), "", "")
282-
281+
info := fakeVersionInfo()
282+
config.EffectiveVersion = basecompatibility.NewEffectiveVersionFromString(fmt.Sprintf("%s.%s", info.Major, info.Minor), "", "")
283283
config.EnableIndex = true
284284
secureOptions := (&SecureServingOptions{
285285
BindAddress: netutils.ParseIPSloppy("127.0.0.1"),
@@ -371,8 +371,8 @@ func TestServerRunWithSNI(t *testing.T) {
371371
if err != nil {
372372
t.Fatalf("failed to connect with loopback client: %v", err)
373373
}
374-
if expected := &v; !reflect.DeepEqual(got, expected) {
375-
t.Errorf("loopback client didn't get correct version info: expected=%v got=%v", expected, got)
374+
if expected := &info; !reflect.DeepEqual(got, expected) {
375+
t.Errorf("loopback client didn't get correct version info: expected=%v got=%v", *expected, *got)
376376
}
377377

378378
select {
@@ -461,12 +461,15 @@ func certSignature(cert tls.Certificate) (string, error) {
461461
return x509CertSignature(x509Certs[0]), nil
462462
}
463463

464-
func fakeVersion() version.Info {
465-
return version.Info{
466-
Major: "42",
467-
Minor: "42",
468-
GitVersion: "42.42",
469-
}
464+
func fakeVersionInfo() version.Info {
465+
baseVer := baseversion.Get()
466+
baseVer.Major = "42"
467+
baseVer.Minor = "42"
468+
baseVer.EmulationMajor = "42"
469+
baseVer.EmulationMinor = "42"
470+
baseVer.MinCompatibilityMajor = "42"
471+
baseVer.MinCompatibilityMinor = "41"
472+
return baseVer
470473
}
471474

472475
// generateSelfSignedCertKey creates a self-signed certificate and key for the given host.

staging/src/k8s.io/apiserver/pkg/server/routes/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func (v Version) Install(c *restful.Container) {
3939
// Set up a service to return the git code version.
4040
versionWS := new(restful.WebService)
4141
versionWS.Path("/version")
42-
versionWS.Doc("git code version from which this is built")
42+
versionWS.Doc("get the version information for this server.")
4343
versionWS.Route(
4444
versionWS.GET("/").To(v.handleVersion).
45-
Doc("get the code version").
45+
Doc("get the version information for this server").
4646
Operation("getCodeVersion").
4747
Produces(restful.MIME_JSON).
4848
Consumes(restful.MIME_JSON).

staging/src/k8s.io/apiserver/pkg/util/compatibility/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ func kubeEffectiveVersionFloors(binaryVersion *version.Version) *version.Version
5555
// We do not enforce the N-3..N emulation version range in tests so that the tests would not automatically fail when there is a version bump.
5656
// Only used in tests.
5757
func DefaultKubeEffectiveVersionForTest() basecompatibility.MutableEffectiveVersion {
58-
binaryVersion := version.MustParse(baseversion.DefaultKubeBinaryVersion).WithInfo(baseversion.Get())
58+
binaryVersion := version.MustParse(baseversion.DefaultKubeBinaryVersion)
5959
return basecompatibility.NewEffectiveVersion(binaryVersion, false, version.MustParse("0.0"), version.MustParse("0.0"))
6060
}
6161

6262
func defaultBuildBinaryVersion() *version.Version {
6363
verInfo := baseversion.Get()
64-
return version.MustParse(verInfo.String()).WithInfo(verInfo)
64+
return version.MustParse(verInfo.String())
6565
}

0 commit comments

Comments
 (0)