mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
Merge pull request #130019 from yongruilin/version-intro
KEP-4330: extend version information with more detailed version fields
This commit is contained in:
commit
23d6377028
20
api/openapi-spec/swagger.json
generated
20
api/openapi-spec/swagger.json
generated
@ -19711,6 +19711,14 @@
|
|||||||
"compiler": {
|
"compiler": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"emulationMajor": {
|
||||||
|
"description": "EmulationMajor is the major version of the emulation version",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"emulationMinor": {
|
||||||
|
"description": "EmulationMinor is the minor version of the emulation version",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"gitCommit": {
|
"gitCommit": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -19724,9 +19732,19 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"major": {
|
"major": {
|
||||||
|
"description": "Major is the major version of the binary version",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"minCompatibilityMajor": {
|
||||||
|
"description": "MinCompatibilityMajor is the major version of the minimum compatibility version",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"minCompatibilityMinor": {
|
||||||
|
"description": "MinCompatibilityMinor is the minor version of the minimum compatibility version",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"minor": {
|
"minor": {
|
||||||
|
"description": "Minor is the minor version of the binary version",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"platform": {
|
"platform": {
|
||||||
@ -87657,7 +87675,7 @@
|
|||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"description": "get the code version",
|
"description": "get the version information for this server",
|
||||||
"operationId": "getCodeVersion",
|
"operationId": "getCodeVersion",
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/json"
|
"application/json"
|
||||||
|
20
api/openapi-spec/v3/version_openapi.json
generated
20
api/openapi-spec/v3/version_openapi.json
generated
@ -12,6 +12,14 @@
|
|||||||
"default": "",
|
"default": "",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"emulationMajor": {
|
||||||
|
"description": "EmulationMajor is the major version of the emulation version",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"emulationMinor": {
|
||||||
|
"description": "EmulationMinor is the minor version of the emulation version",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"gitCommit": {
|
"gitCommit": {
|
||||||
"default": "",
|
"default": "",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@ -30,10 +38,20 @@
|
|||||||
},
|
},
|
||||||
"major": {
|
"major": {
|
||||||
"default": "",
|
"default": "",
|
||||||
|
"description": "Major is the major version of the binary version",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"minCompatibilityMajor": {
|
||||||
|
"description": "MinCompatibilityMajor is the major version of the minimum compatibility version",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"minCompatibilityMinor": {
|
||||||
|
"description": "MinCompatibilityMinor is the minor version of the minimum compatibility version",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"minor": {
|
"minor": {
|
||||||
"default": "",
|
"default": "",
|
||||||
|
"description": "Minor is the minor version of the binary version",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"platform": {
|
"platform": {
|
||||||
@ -72,7 +90,7 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
"/version/": {
|
"/version/": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "get the code version",
|
"description": "get the version information for this server",
|
||||||
"operationId": "getCodeVersion",
|
"operationId": "getCodeVersion",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
|
@ -243,8 +243,14 @@ func TestVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
expectedInfo := utilversion.Get()
|
expectedInfo := utilversion.Get()
|
||||||
kubeVersion := compatibility.DefaultKubeEffectiveVersionForTest().BinaryVersion()
|
kubeVersion := compatibility.DefaultKubeEffectiveVersionForTest().BinaryVersion()
|
||||||
|
emulationVersion := compatibility.DefaultKubeEffectiveVersionForTest().EmulationVersion()
|
||||||
|
minCompatibilityVersion := compatibility.DefaultKubeEffectiveVersionForTest().MinCompatibilityVersion()
|
||||||
expectedInfo.Major = fmt.Sprintf("%d", kubeVersion.Major())
|
expectedInfo.Major = fmt.Sprintf("%d", kubeVersion.Major())
|
||||||
expectedInfo.Minor = fmt.Sprintf("%d", kubeVersion.Minor())
|
expectedInfo.Minor = fmt.Sprintf("%d", kubeVersion.Minor())
|
||||||
|
expectedInfo.EmulationMajor = fmt.Sprintf("%d", emulationVersion.Major())
|
||||||
|
expectedInfo.EmulationMinor = fmt.Sprintf("%d", emulationVersion.Minor())
|
||||||
|
expectedInfo.MinCompatibilityMajor = fmt.Sprintf("%d", minCompatibilityVersion.Major())
|
||||||
|
expectedInfo.MinCompatibilityMinor = fmt.Sprintf("%d", minCompatibilityVersion.Minor())
|
||||||
|
|
||||||
if !reflect.DeepEqual(expectedInfo, info) {
|
if !reflect.DeepEqual(expectedInfo, info) {
|
||||||
t.Errorf("Expected %#v, Got %#v", expectedInfo, info)
|
t.Errorf("Expected %#v, Got %#v", expectedInfo, info)
|
||||||
|
42
pkg/generated/openapi/zz_generated.openapi.go
generated
42
pkg/generated/openapi/zz_generated.openapi.go
generated
@ -58924,16 +58924,46 @@ func schema_k8sio_apimachinery_pkg_version_Info(ref common.ReferenceCallback) co
|
|||||||
Properties: map[string]spec.Schema{
|
Properties: map[string]spec.Schema{
|
||||||
"major": {
|
"major": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Default: "",
|
Description: "Major is the major version of the binary version",
|
||||||
Type: []string{"string"},
|
Default: "",
|
||||||
Format: "",
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"minor": {
|
"minor": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Default: "",
|
Description: "Minor is the minor version of the binary version",
|
||||||
Type: []string{"string"},
|
Default: "",
|
||||||
Format: "",
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emulationMajor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "EmulationMajor is the major version of the emulation version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emulationMinor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "EmulationMinor is the minor version of the emulation version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"minCompatibilityMajor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "MinCompatibilityMajor is the major version of the minimum compatibility version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"minCompatibilityMinor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "MinCompatibilityMinor is the minor version of the minimum compatibility version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"gitVersion": {
|
"gitVersion": {
|
||||||
|
@ -6599,16 +6599,46 @@ func schema_k8sio_apimachinery_pkg_version_Info(ref common.ReferenceCallback) co
|
|||||||
Properties: map[string]spec.Schema{
|
Properties: map[string]spec.Schema{
|
||||||
"major": {
|
"major": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Default: "",
|
Description: "Major is the major version of the binary version",
|
||||||
Type: []string{"string"},
|
Default: "",
|
||||||
Format: "",
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"minor": {
|
"minor": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Default: "",
|
Description: "Minor is the minor version of the binary version",
|
||||||
Type: []string{"string"},
|
Default: "",
|
||||||
Format: "",
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emulationMajor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "EmulationMajor is the major version of the emulation version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emulationMinor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "EmulationMinor is the minor version of the emulation version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"minCompatibilityMajor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "MinCompatibilityMajor is the major version of the minimum compatibility version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"minCompatibilityMinor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "MinCompatibilityMinor is the minor version of the minimum compatibility version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"gitVersion": {
|
"gitVersion": {
|
||||||
|
@ -33,7 +33,6 @@ type Version struct {
|
|||||||
semver bool
|
semver bool
|
||||||
preRelease string
|
preRelease string
|
||||||
buildMetadata string
|
buildMetadata string
|
||||||
info apimachineryversion.Info
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -456,27 +455,28 @@ func (v *Version) Compare(other string) (int, error) {
|
|||||||
return v.compareInternal(ov), nil
|
return v.compareInternal(ov), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithInfo returns copy of the version object with requested info
|
// WithInfo returns copy of the version object.
|
||||||
|
// Deprecated: The Info field has been removed from the Version struct. This method no longer modifies the Version object.
|
||||||
func (v *Version) WithInfo(info apimachineryversion.Info) *Version {
|
func (v *Version) WithInfo(info apimachineryversion.Info) *Version {
|
||||||
result := *v
|
result := *v
|
||||||
result.info = info
|
|
||||||
return &result
|
return &result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Info returns the version information of a component.
|
||||||
|
// Deprecated: Use Info() from effective version instead.
|
||||||
func (v *Version) Info() *apimachineryversion.Info {
|
func (v *Version) Info() *apimachineryversion.Info {
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// in case info is empty, or the major and minor in info is different from the actual major and minor
|
// in case info is empty, or the major and minor in info is different from the actual major and minor
|
||||||
v.info.Major = itoa(v.Major())
|
return &apimachineryversion.Info{
|
||||||
v.info.Minor = itoa(v.Minor())
|
Major: Itoa(v.Major()),
|
||||||
if v.info.GitVersion == "" {
|
Minor: Itoa(v.Minor()),
|
||||||
v.info.GitVersion = v.String()
|
GitVersion: v.String(),
|
||||||
}
|
}
|
||||||
return &v.info
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func itoa(i uint) string {
|
func Itoa(i uint) string {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -16,5 +16,5 @@ limitations under the License.
|
|||||||
|
|
||||||
// +k8s:openapi-gen=true
|
// +k8s:openapi-gen=true
|
||||||
|
|
||||||
// Package version supplies the type for version information collected at build time.
|
// Package version supplies the type for version information.
|
||||||
package version
|
package version
|
||||||
|
@ -20,15 +20,25 @@ package version
|
|||||||
// TODO: Add []string of api versions supported? It's still unclear
|
// TODO: Add []string of api versions supported? It's still unclear
|
||||||
// how we'll want to distribute that information.
|
// how we'll want to distribute that information.
|
||||||
type Info struct {
|
type Info struct {
|
||||||
Major string `json:"major"`
|
// Major is the major version of the binary version
|
||||||
Minor string `json:"minor"`
|
Major string `json:"major"`
|
||||||
GitVersion string `json:"gitVersion"`
|
// Minor is the minor version of the binary version
|
||||||
GitCommit string `json:"gitCommit"`
|
Minor string `json:"minor"`
|
||||||
GitTreeState string `json:"gitTreeState"`
|
// EmulationMajor is the major version of the emulation version
|
||||||
BuildDate string `json:"buildDate"`
|
EmulationMajor string `json:"emulationMajor,omitempty"`
|
||||||
GoVersion string `json:"goVersion"`
|
// EmulationMinor is the minor version of the emulation version
|
||||||
Compiler string `json:"compiler"`
|
EmulationMinor string `json:"emulationMinor,omitempty"`
|
||||||
Platform string `json:"platform"`
|
// MinCompatibilityMajor is the major version of the minimum compatibility version
|
||||||
|
MinCompatibilityMajor string `json:"minCompatibilityMajor,omitempty"`
|
||||||
|
// MinCompatibilityMinor is the minor version of the minimum compatibility version
|
||||||
|
MinCompatibilityMinor string `json:"minCompatibilityMinor,omitempty"`
|
||||||
|
GitVersion string `json:"gitVersion"`
|
||||||
|
GitCommit string `json:"gitCommit"`
|
||||||
|
GitTreeState string `json:"gitTreeState"`
|
||||||
|
BuildDate string `json:"buildDate"`
|
||||||
|
GoVersion string `json:"goVersion"`
|
||||||
|
Compiler string `json:"compiler"`
|
||||||
|
Platform string `json:"platform"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns info as a human-friendly version string.
|
// String returns info as a human-friendly version string.
|
||||||
|
@ -1106,7 +1106,7 @@ func installAPI(name string, s *GenericAPIServer, c *Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
routes.Version{Version: c.EffectiveVersion.BinaryVersion().Info()}.Install(s.Handler.GoRestfulContainer)
|
routes.Version{Version: c.EffectiveVersion.Info()}.Install(s.Handler.GoRestfulContainer)
|
||||||
|
|
||||||
if c.EnableDiscovery {
|
if c.EnableDiscovery {
|
||||||
wrapped := discoveryendpoint.WrapAggregatedDiscoveryToHandler(s.DiscoveryGroupManager, s.AggregatedDiscoveryGroupManager)
|
wrapped := discoveryendpoint.WrapAggregatedDiscoveryToHandler(s.DiscoveryGroupManager, s.AggregatedDiscoveryGroupManager)
|
||||||
|
@ -47,6 +47,7 @@ import (
|
|||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
cliflag "k8s.io/component-base/cli/flag"
|
cliflag "k8s.io/component-base/cli/flag"
|
||||||
basecompatibility "k8s.io/component-base/compatibility"
|
basecompatibility "k8s.io/component-base/compatibility"
|
||||||
|
baseversion "k8s.io/component-base/version"
|
||||||
"k8s.io/klog/v2/ktesting"
|
"k8s.io/klog/v2/ktesting"
|
||||||
netutils "k8s.io/utils/net"
|
netutils "k8s.io/utils/net"
|
||||||
)
|
)
|
||||||
@ -277,9 +278,8 @@ func TestServerRunWithSNI(t *testing.T) {
|
|||||||
|
|
||||||
// launch server
|
// launch server
|
||||||
config := setUp(t)
|
config := setUp(t)
|
||||||
v := fakeVersion()
|
info := fakeVersionInfo()
|
||||||
config.EffectiveVersion = basecompatibility.NewEffectiveVersionFromString(v.String(), "", "")
|
config.EffectiveVersion = basecompatibility.NewEffectiveVersionFromString(fmt.Sprintf("%s.%s", info.Major, info.Minor), "", "")
|
||||||
|
|
||||||
config.EnableIndex = true
|
config.EnableIndex = true
|
||||||
secureOptions := (&SecureServingOptions{
|
secureOptions := (&SecureServingOptions{
|
||||||
BindAddress: netutils.ParseIPSloppy("127.0.0.1"),
|
BindAddress: netutils.ParseIPSloppy("127.0.0.1"),
|
||||||
@ -371,8 +371,8 @@ func TestServerRunWithSNI(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to connect with loopback client: %v", err)
|
t.Fatalf("failed to connect with loopback client: %v", err)
|
||||||
}
|
}
|
||||||
if expected := &v; !reflect.DeepEqual(got, expected) {
|
if expected := &info; !reflect.DeepEqual(got, expected) {
|
||||||
t.Errorf("loopback client didn't get correct version info: expected=%v got=%v", expected, got)
|
t.Errorf("loopback client didn't get correct version info: expected=%v got=%v", *expected, *got)
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -461,12 +461,15 @@ func certSignature(cert tls.Certificate) (string, error) {
|
|||||||
return x509CertSignature(x509Certs[0]), nil
|
return x509CertSignature(x509Certs[0]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fakeVersion() version.Info {
|
func fakeVersionInfo() version.Info {
|
||||||
return version.Info{
|
baseVer := baseversion.Get()
|
||||||
Major: "42",
|
baseVer.Major = "42"
|
||||||
Minor: "42",
|
baseVer.Minor = "42"
|
||||||
GitVersion: "42.42",
|
baseVer.EmulationMajor = "42"
|
||||||
}
|
baseVer.EmulationMinor = "42"
|
||||||
|
baseVer.MinCompatibilityMajor = "42"
|
||||||
|
baseVer.MinCompatibilityMinor = "41"
|
||||||
|
return baseVer
|
||||||
}
|
}
|
||||||
|
|
||||||
// generateSelfSignedCertKey creates a self-signed certificate and key for the given host.
|
// generateSelfSignedCertKey creates a self-signed certificate and key for the given host.
|
||||||
|
@ -39,10 +39,10 @@ func (v Version) Install(c *restful.Container) {
|
|||||||
// Set up a service to return the git code version.
|
// Set up a service to return the git code version.
|
||||||
versionWS := new(restful.WebService)
|
versionWS := new(restful.WebService)
|
||||||
versionWS.Path("/version")
|
versionWS.Path("/version")
|
||||||
versionWS.Doc("git code version from which this is built")
|
versionWS.Doc("get the version information for this server.")
|
||||||
versionWS.Route(
|
versionWS.Route(
|
||||||
versionWS.GET("/").To(v.handleVersion).
|
versionWS.GET("/").To(v.handleVersion).
|
||||||
Doc("get the code version").
|
Doc("get the version information for this server").
|
||||||
Operation("getCodeVersion").
|
Operation("getCodeVersion").
|
||||||
Produces(restful.MIME_JSON).
|
Produces(restful.MIME_JSON).
|
||||||
Consumes(restful.MIME_JSON).
|
Consumes(restful.MIME_JSON).
|
||||||
|
@ -55,11 +55,11 @@ func kubeEffectiveVersionFloors(binaryVersion *version.Version) *version.Version
|
|||||||
// 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.
|
// 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.
|
||||||
// Only used in tests.
|
// Only used in tests.
|
||||||
func DefaultKubeEffectiveVersionForTest() basecompatibility.MutableEffectiveVersion {
|
func DefaultKubeEffectiveVersionForTest() basecompatibility.MutableEffectiveVersion {
|
||||||
binaryVersion := version.MustParse(baseversion.DefaultKubeBinaryVersion).WithInfo(baseversion.Get())
|
binaryVersion := version.MustParse(baseversion.DefaultKubeBinaryVersion)
|
||||||
return basecompatibility.NewEffectiveVersion(binaryVersion, false, version.MustParse("0.0"), version.MustParse("0.0"))
|
return basecompatibility.NewEffectiveVersion(binaryVersion, false, version.MustParse("0.0"), version.MustParse("0.0"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultBuildBinaryVersion() *version.Version {
|
func defaultBuildBinaryVersion() *version.Version {
|
||||||
verInfo := baseversion.Get()
|
verInfo := baseversion.Get()
|
||||||
return version.MustParse(verInfo.String()).WithInfo(verInfo)
|
return version.MustParse(verInfo.String())
|
||||||
}
|
}
|
||||||
|
@ -2625,16 +2625,46 @@ func schema_k8sio_apimachinery_pkg_version_Info(ref common.ReferenceCallback) co
|
|||||||
Properties: map[string]spec.Schema{
|
Properties: map[string]spec.Schema{
|
||||||
"major": {
|
"major": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Default: "",
|
Description: "Major is the major version of the binary version",
|
||||||
Type: []string{"string"},
|
Default: "",
|
||||||
Format: "",
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"minor": {
|
"minor": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Default: "",
|
Description: "Minor is the minor version of the binary version",
|
||||||
Type: []string{"string"},
|
Default: "",
|
||||||
Format: "",
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emulationMajor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "EmulationMajor is the major version of the emulation version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emulationMinor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "EmulationMinor is the minor version of the emulation version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"minCompatibilityMajor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "MinCompatibilityMajor is the major version of the minimum compatibility version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"minCompatibilityMinor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "MinCompatibilityMinor is the minor version of the minimum compatibility version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"gitVersion": {
|
"gitVersion": {
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/version"
|
"k8s.io/apimachinery/pkg/util/version"
|
||||||
|
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
||||||
baseversion "k8s.io/component-base/version"
|
baseversion "k8s.io/component-base/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,6 +43,9 @@ type EffectiveVersion interface {
|
|||||||
// AllowedMinCompatibilityVersionRange returns the string of the allowed range of min compatibility version.
|
// AllowedMinCompatibilityVersionRange returns the string of the allowed range of min compatibility version.
|
||||||
// Used only for docs/help.
|
// Used only for docs/help.
|
||||||
AllowedMinCompatibilityVersionRange() string
|
AllowedMinCompatibilityVersionRange() string
|
||||||
|
|
||||||
|
// Info returns the version information of a component.
|
||||||
|
Info() *apimachineryversion.Info
|
||||||
}
|
}
|
||||||
|
|
||||||
type MutableEffectiveVersion interface {
|
type MutableEffectiveVersion interface {
|
||||||
@ -173,6 +177,34 @@ func (m *effectiveVersion) Validate() []error {
|
|||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Info returns the version information of a component.
|
||||||
|
// If the binary version is nil, it returns nil.
|
||||||
|
func (m *effectiveVersion) Info() *apimachineryversion.Info {
|
||||||
|
binVer := m.BinaryVersion()
|
||||||
|
if binVer == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
info := baseversion.Get()
|
||||||
|
info.Major = version.Itoa(binVer.Major())
|
||||||
|
info.Minor = version.Itoa(binVer.Minor())
|
||||||
|
if info.GitVersion == "" {
|
||||||
|
info.GitVersion = binVer.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
if ev := m.EmulationVersion(); ev != nil {
|
||||||
|
info.EmulationMajor = version.Itoa(ev.Major())
|
||||||
|
info.EmulationMinor = version.Itoa(ev.Minor())
|
||||||
|
}
|
||||||
|
|
||||||
|
if mcv := m.MinCompatibilityVersion(); mcv != nil {
|
||||||
|
info.MinCompatibilityMajor = version.Itoa(mcv.Major())
|
||||||
|
info.MinCompatibilityMinor = version.Itoa(mcv.Minor())
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info
|
||||||
|
}
|
||||||
|
|
||||||
// NewEffectiveVersion creates a MutableEffectiveVersion from the binaryVersion.
|
// NewEffectiveVersion creates a MutableEffectiveVersion from the binaryVersion.
|
||||||
// If useDefaultBuildBinaryVersion is true, the call of BinaryVersion() will always return the current binary version.
|
// If useDefaultBuildBinaryVersion is true, the call of BinaryVersion() will always return the current binary version.
|
||||||
// NewEffectiveVersion(binaryVersion, true) should only be used if the binary version is dynamic.
|
// NewEffectiveVersion(binaryVersion, true) should only be used if the binary version is dynamic.
|
||||||
@ -209,5 +241,5 @@ func NewEffectiveVersionFromString(binaryVer, emulationVerFloor, minCompatibilit
|
|||||||
|
|
||||||
func defaultBuildBinaryVersion() *version.Version {
|
func defaultBuildBinaryVersion() *version.Version {
|
||||||
verInfo := baseversion.Get()
|
verInfo := baseversion.Get()
|
||||||
return version.MustParse(verInfo.String()).WithInfo(verInfo)
|
return version.MustParse(verInfo.String())
|
||||||
}
|
}
|
||||||
|
@ -146,3 +146,126 @@ func TestSetEmulationVersion(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInfo(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
binaryVersion string
|
||||||
|
emulationVersion string
|
||||||
|
minCompatibilityVersion string
|
||||||
|
expectedMajor string
|
||||||
|
expectedMinor string
|
||||||
|
expectedEmulationMajor string
|
||||||
|
expectedEmulationMinor string
|
||||||
|
expectedMinCompatibilityMajor string
|
||||||
|
expectedMinCompatibilityMinor string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "normal case",
|
||||||
|
binaryVersion: "v1.34.0",
|
||||||
|
emulationVersion: "v1.32.0",
|
||||||
|
minCompatibilityVersion: "v1.31.0",
|
||||||
|
expectedMajor: "1",
|
||||||
|
expectedMinor: "34",
|
||||||
|
expectedEmulationMajor: "1",
|
||||||
|
expectedEmulationMinor: "32",
|
||||||
|
expectedMinCompatibilityMajor: "1",
|
||||||
|
expectedMinCompatibilityMinor: "31",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "default min compatibility version is emulation version - 1",
|
||||||
|
binaryVersion: "v1.34.0",
|
||||||
|
emulationVersion: "v1.32.0",
|
||||||
|
// minCompatibilityVersion not set, should default to v1.31.0
|
||||||
|
expectedMajor: "1",
|
||||||
|
expectedMinor: "34",
|
||||||
|
expectedEmulationMajor: "1",
|
||||||
|
expectedEmulationMinor: "32",
|
||||||
|
expectedMinCompatibilityMajor: "1",
|
||||||
|
expectedMinCompatibilityMinor: "31",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "emulation version same as binary version",
|
||||||
|
binaryVersion: "v1.34.0",
|
||||||
|
emulationVersion: "v1.34.0",
|
||||||
|
// minCompatibilityVersion not set, should default to v1.33.0
|
||||||
|
expectedMajor: "1",
|
||||||
|
expectedMinor: "34",
|
||||||
|
expectedEmulationMajor: "1",
|
||||||
|
expectedEmulationMinor: "34",
|
||||||
|
expectedMinCompatibilityMajor: "1",
|
||||||
|
expectedMinCompatibilityMinor: "33",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty binary version",
|
||||||
|
binaryVersion: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with pre-release and build metadata",
|
||||||
|
binaryVersion: "v1.34.0-alpha.1+abc123",
|
||||||
|
emulationVersion: "v1.32.0",
|
||||||
|
// minCompatibilityVersion not set, should default to v1.31.0
|
||||||
|
expectedMajor: "1",
|
||||||
|
expectedMinor: "34",
|
||||||
|
expectedEmulationMajor: "1",
|
||||||
|
expectedEmulationMinor: "32",
|
||||||
|
expectedMinCompatibilityMajor: "1",
|
||||||
|
expectedMinCompatibilityMinor: "31",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "override default min compatibility version",
|
||||||
|
binaryVersion: "v1.34.0",
|
||||||
|
emulationVersion: "v1.32.0",
|
||||||
|
minCompatibilityVersion: "v1.32.0", // explicitly set to same as emulation version
|
||||||
|
expectedMajor: "1",
|
||||||
|
expectedMinor: "34",
|
||||||
|
expectedEmulationMajor: "1",
|
||||||
|
expectedEmulationMinor: "32",
|
||||||
|
expectedMinCompatibilityMajor: "1",
|
||||||
|
expectedMinCompatibilityMinor: "32",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
var effective MutableEffectiveVersion
|
||||||
|
if test.binaryVersion == "" {
|
||||||
|
effective = &effectiveVersion{}
|
||||||
|
} else {
|
||||||
|
effective = NewEffectiveVersionFromString(test.binaryVersion, "", "")
|
||||||
|
if test.emulationVersion != "" {
|
||||||
|
effective.SetEmulationVersion(version.MustParse(test.emulationVersion))
|
||||||
|
}
|
||||||
|
if test.minCompatibilityVersion != "" {
|
||||||
|
effective.SetMinCompatibilityVersion(version.MustParse(test.minCompatibilityVersion))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
info := effective.Info()
|
||||||
|
if info == nil {
|
||||||
|
if test.expectedMajor != "" {
|
||||||
|
t.Fatalf("expected info, got nil")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.Major != test.expectedMajor {
|
||||||
|
t.Errorf("expected major %s, got %s", test.expectedMajor, info.Major)
|
||||||
|
}
|
||||||
|
if info.Minor != test.expectedMinor {
|
||||||
|
t.Errorf("expected minor %s, got %s", test.expectedMinor, info.Minor)
|
||||||
|
}
|
||||||
|
if info.EmulationMajor != test.expectedEmulationMajor {
|
||||||
|
t.Errorf("expected emulation major %s, got %s", test.expectedEmulationMajor, info.EmulationMajor)
|
||||||
|
}
|
||||||
|
if info.EmulationMinor != test.expectedEmulationMinor {
|
||||||
|
t.Errorf("expected emulation minor %s, got %s", test.expectedEmulationMinor, info.EmulationMinor)
|
||||||
|
}
|
||||||
|
if info.MinCompatibilityMajor != test.expectedMinCompatibilityMajor {
|
||||||
|
t.Errorf("expected min compatibility major %s, got %s", test.expectedMinCompatibilityMajor, info.MinCompatibilityMajor)
|
||||||
|
}
|
||||||
|
if info.MinCompatibilityMinor != test.expectedMinCompatibilityMinor {
|
||||||
|
t.Errorf("expected min compatibility minor %s, got %s", test.expectedMinCompatibilityMinor, info.MinCompatibilityMinor)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -25,6 +25,8 @@ import (
|
|||||||
|
|
||||||
// Get returns the overall codebase version. It's for detecting
|
// Get returns the overall codebase version. It's for detecting
|
||||||
// what code a binary was built from.
|
// what code a binary was built from.
|
||||||
|
// The caller should use BinaryMajor and BinaryMinor to determine
|
||||||
|
// the binary version. The Major and Minor fields are still set by git version for backwards compatibility.
|
||||||
func Get() apimachineryversion.Info {
|
func Get() apimachineryversion.Info {
|
||||||
// These variables typically come from -ldflags settings and in
|
// These variables typically come from -ldflags settings and in
|
||||||
// their absence fallback to the settings in ./base.go
|
// their absence fallback to the settings in ./base.go
|
||||||
|
@ -2625,16 +2625,46 @@ func schema_k8sio_apimachinery_pkg_version_Info(ref common.ReferenceCallback) co
|
|||||||
Properties: map[string]spec.Schema{
|
Properties: map[string]spec.Schema{
|
||||||
"major": {
|
"major": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Default: "",
|
Description: "Major is the major version of the binary version",
|
||||||
Type: []string{"string"},
|
Default: "",
|
||||||
Format: "",
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"minor": {
|
"minor": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Default: "",
|
Description: "Minor is the minor version of the binary version",
|
||||||
Type: []string{"string"},
|
Default: "",
|
||||||
Format: "",
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emulationMajor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "EmulationMajor is the major version of the emulation version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emulationMinor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "EmulationMinor is the minor version of the emulation version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"minCompatibilityMajor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "MinCompatibilityMajor is the major version of the minimum compatibility version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"minCompatibilityMinor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "MinCompatibilityMinor is the minor version of the minimum compatibility version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"gitVersion": {
|
"gitVersion": {
|
||||||
|
@ -2623,16 +2623,46 @@ func schema_k8sio_apimachinery_pkg_version_Info(ref common.ReferenceCallback) co
|
|||||||
Properties: map[string]spec.Schema{
|
Properties: map[string]spec.Schema{
|
||||||
"major": {
|
"major": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Default: "",
|
Description: "Major is the major version of the binary version",
|
||||||
Type: []string{"string"},
|
Default: "",
|
||||||
Format: "",
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"minor": {
|
"minor": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Default: "",
|
Description: "Minor is the minor version of the binary version",
|
||||||
Type: []string{"string"},
|
Default: "",
|
||||||
Format: "",
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emulationMajor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "EmulationMajor is the major version of the emulation version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emulationMinor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "EmulationMinor is the minor version of the emulation version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"minCompatibilityMajor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "MinCompatibilityMajor is the major version of the minimum compatibility version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"minCompatibilityMinor": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "MinCompatibilityMinor is the minor version of the minimum compatibility version",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"gitVersion": {
|
"gitVersion": {
|
||||||
|
@ -85,8 +85,14 @@ func TestClient(t *testing.T) {
|
|||||||
}
|
}
|
||||||
expectedInfo := utilversion.Get()
|
expectedInfo := utilversion.Get()
|
||||||
kubeVersion := compatibility.DefaultKubeEffectiveVersionForTest().BinaryVersion()
|
kubeVersion := compatibility.DefaultKubeEffectiveVersionForTest().BinaryVersion()
|
||||||
|
emulationVersion := compatibility.DefaultKubeEffectiveVersionForTest().EmulationVersion()
|
||||||
|
minCompatibilityVersion := compatibility.DefaultKubeEffectiveVersionForTest().MinCompatibilityVersion()
|
||||||
expectedInfo.Major = fmt.Sprintf("%d", kubeVersion.Major())
|
expectedInfo.Major = fmt.Sprintf("%d", kubeVersion.Major())
|
||||||
expectedInfo.Minor = fmt.Sprintf("%d", kubeVersion.Minor())
|
expectedInfo.Minor = fmt.Sprintf("%d", kubeVersion.Minor())
|
||||||
|
expectedInfo.EmulationMajor = fmt.Sprintf("%d", emulationVersion.Major())
|
||||||
|
expectedInfo.EmulationMinor = fmt.Sprintf("%d", emulationVersion.Minor())
|
||||||
|
expectedInfo.MinCompatibilityMajor = fmt.Sprintf("%d", minCompatibilityVersion.Major())
|
||||||
|
expectedInfo.MinCompatibilityMinor = fmt.Sprintf("%d", minCompatibilityVersion.Minor())
|
||||||
|
|
||||||
if e, a := expectedInfo, *info; !reflect.DeepEqual(e, a) {
|
if e, a := expectedInfo, *info; !reflect.DeepEqual(e, a) {
|
||||||
t.Errorf("expected %#v, got %#v", e, a)
|
t.Errorf("expected %#v, got %#v", e, a)
|
||||||
|
Loading…
Reference in New Issue
Block a user