Skip to content

Commit a3094cc

Browse files
committed
feat: extend version information with more detailed version fields
- Add new version fields to version.Info struct: * EmulationMajor and EmulationMinor to track emulated version * MinCompatibilityMajor and MinCompatibilityMinor for compatibility tracking - Update related code to populate and use these new fields - Improve version information documentation and OpenAPI generation - Modify version routes and documentation to reflect new version information structure
1 parent cd451c6 commit a3094cc

File tree

18 files changed

+410
-55
lines changed

18 files changed

+410
-55
lines changed

api/openapi-spec/swagger.json

Lines changed: 20 additions & 2 deletions
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: 20 additions & 2 deletions
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,15 @@ func (v *Version) Info() *apimachineryversion.Info {
468468
return nil
469469
}
470470
// 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())
471+
v.info.Major = Itoa(v.Major())
472+
v.info.Minor = Itoa(v.Minor())
473473
if v.info.GitVersion == "" {
474474
v.info.GitVersion = v.String()
475475
}
476476
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
@@ -1108,7 +1108,7 @@ func installAPI(name string, s *GenericAPIServer, c *Config) {
11081108
}
11091109
}
11101110

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

11131113
if c.EnableDiscovery {
11141114
if c.FeatureGate.Enabled(genericfeatures.AggregatedDiscoveryEndpoint) {

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func TestServerRunWithSNI(t *testing.T) {
372372
t.Fatalf("failed to connect with loopback client: %v", err)
373373
}
374374
if expected := &v; !reflect.DeepEqual(got, expected) {
375-
t.Errorf("loopback client didn't get correct version info: expected=%v got=%v", expected, got)
375+
t.Errorf("loopback client didn't get correct version info: expected=%v got=%v", *expected, *got)
376376
}
377377

378378
select {
@@ -463,9 +463,13 @@ func certSignature(cert tls.Certificate) (string, error) {
463463

464464
func fakeVersion() version.Info {
465465
return version.Info{
466-
Major: "42",
467-
Minor: "42",
468-
GitVersion: "42.42",
466+
Major: "42",
467+
Minor: "42",
468+
EmulationMajor: "42",
469+
EmulationMinor: "42",
470+
MinCompatibilityMajor: "42",
471+
MinCompatibilityMinor: "41",
472+
GitVersion: "42.42",
469473
}
470474
}
471475

0 commit comments

Comments
 (0)