mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +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": {
|
||||
"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": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -19724,9 +19732,19 @@
|
||||
"type": "string"
|
||||
},
|
||||
"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"
|
||||
},
|
||||
"minor": {
|
||||
"description": "Minor is the minor version of the binary version",
|
||||
"type": "string"
|
||||
},
|
||||
"platform": {
|
||||
@ -87657,7 +87675,7 @@
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"description": "get the code version",
|
||||
"description": "get the version information for this server",
|
||||
"operationId": "getCodeVersion",
|
||||
"produces": [
|
||||
"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": "",
|
||||
"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": {
|
||||
"default": "",
|
||||
"type": "string"
|
||||
@ -30,10 +38,20 @@
|
||||
},
|
||||
"major": {
|
||||
"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"
|
||||
},
|
||||
"minor": {
|
||||
"default": "",
|
||||
"description": "Minor is the minor version of the binary version",
|
||||
"type": "string"
|
||||
},
|
||||
"platform": {
|
||||
@ -72,7 +90,7 @@
|
||||
"paths": {
|
||||
"/version/": {
|
||||
"get": {
|
||||
"description": "get the code version",
|
||||
"description": "get the version information for this server",
|
||||
"operationId": "getCodeVersion",
|
||||
"responses": {
|
||||
"200": {
|
||||
|
@ -243,8 +243,14 @@ func TestVersion(t *testing.T) {
|
||||
}
|
||||
expectedInfo := utilversion.Get()
|
||||
kubeVersion := compatibility.DefaultKubeEffectiveVersionForTest().BinaryVersion()
|
||||
emulationVersion := compatibility.DefaultKubeEffectiveVersionForTest().EmulationVersion()
|
||||
minCompatibilityVersion := compatibility.DefaultKubeEffectiveVersionForTest().MinCompatibilityVersion()
|
||||
expectedInfo.Major = fmt.Sprintf("%d", kubeVersion.Major())
|
||||
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) {
|
||||
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{
|
||||
"major": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "Major is the major version of the binary version",
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"minor": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "Minor is the minor version of the binary version",
|
||||
Default: "",
|
||||
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": {
|
||||
|
@ -6599,16 +6599,46 @@ func schema_k8sio_apimachinery_pkg_version_Info(ref common.ReferenceCallback) co
|
||||
Properties: map[string]spec.Schema{
|
||||
"major": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "Major is the major version of the binary version",
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"minor": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "Minor is the minor version of the binary version",
|
||||
Default: "",
|
||||
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": {
|
||||
|
@ -33,7 +33,6 @@ type Version struct {
|
||||
semver bool
|
||||
preRelease string
|
||||
buildMetadata string
|
||||
info apimachineryversion.Info
|
||||
}
|
||||
|
||||
var (
|
||||
@ -456,27 +455,28 @@ func (v *Version) Compare(other string) (int, error) {
|
||||
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 {
|
||||
result := *v
|
||||
result.info = info
|
||||
return &result
|
||||
}
|
||||
|
||||
// Info returns the version information of a component.
|
||||
// Deprecated: Use Info() from effective version instead.
|
||||
func (v *Version) Info() *apimachineryversion.Info {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
// 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())
|
||||
v.info.Minor = itoa(v.Minor())
|
||||
if v.info.GitVersion == "" {
|
||||
v.info.GitVersion = v.String()
|
||||
return &apimachineryversion.Info{
|
||||
Major: Itoa(v.Major()),
|
||||
Minor: Itoa(v.Minor()),
|
||||
GitVersion: v.String(),
|
||||
}
|
||||
return &v.info
|
||||
}
|
||||
|
||||
func itoa(i uint) string {
|
||||
func Itoa(i uint) string {
|
||||
if i == 0 {
|
||||
return ""
|
||||
}
|
||||
|
@ -16,5 +16,5 @@ limitations under the License.
|
||||
|
||||
// +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
|
||||
|
@ -20,15 +20,25 @@ package version
|
||||
// TODO: Add []string of api versions supported? It's still unclear
|
||||
// how we'll want to distribute that information.
|
||||
type Info struct {
|
||||
Major string `json:"major"`
|
||||
Minor string `json:"minor"`
|
||||
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"`
|
||||
// Major is the major version of the binary version
|
||||
Major string `json:"major"`
|
||||
// Minor is the minor version of the binary version
|
||||
Minor string `json:"minor"`
|
||||
// EmulationMajor is the major version of the emulation version
|
||||
EmulationMajor string `json:"emulationMajor,omitempty"`
|
||||
// EmulationMinor is the minor version of the emulation version
|
||||
EmulationMinor string `json:"emulationMinor,omitempty"`
|
||||
// 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.
|
||||
|
@ -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 {
|
||||
wrapped := discoveryendpoint.WrapAggregatedDiscoveryToHandler(s.DiscoveryGroupManager, s.AggregatedDiscoveryGroupManager)
|
||||
|
@ -47,6 +47,7 @@ import (
|
||||
restclient "k8s.io/client-go/rest"
|
||||
cliflag "k8s.io/component-base/cli/flag"
|
||||
basecompatibility "k8s.io/component-base/compatibility"
|
||||
baseversion "k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2/ktesting"
|
||||
netutils "k8s.io/utils/net"
|
||||
)
|
||||
@ -277,9 +278,8 @@ func TestServerRunWithSNI(t *testing.T) {
|
||||
|
||||
// launch server
|
||||
config := setUp(t)
|
||||
v := fakeVersion()
|
||||
config.EffectiveVersion = basecompatibility.NewEffectiveVersionFromString(v.String(), "", "")
|
||||
|
||||
info := fakeVersionInfo()
|
||||
config.EffectiveVersion = basecompatibility.NewEffectiveVersionFromString(fmt.Sprintf("%s.%s", info.Major, info.Minor), "", "")
|
||||
config.EnableIndex = true
|
||||
secureOptions := (&SecureServingOptions{
|
||||
BindAddress: netutils.ParseIPSloppy("127.0.0.1"),
|
||||
@ -371,8 +371,8 @@ func TestServerRunWithSNI(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to connect with loopback client: %v", err)
|
||||
}
|
||||
if expected := &v; !reflect.DeepEqual(got, expected) {
|
||||
t.Errorf("loopback client didn't get correct version info: expected=%v got=%v", expected, got)
|
||||
if expected := &info; !reflect.DeepEqual(got, expected) {
|
||||
t.Errorf("loopback client didn't get correct version info: expected=%v got=%v", *expected, *got)
|
||||
}
|
||||
|
||||
select {
|
||||
@ -461,12 +461,15 @@ func certSignature(cert tls.Certificate) (string, error) {
|
||||
return x509CertSignature(x509Certs[0]), nil
|
||||
}
|
||||
|
||||
func fakeVersion() version.Info {
|
||||
return version.Info{
|
||||
Major: "42",
|
||||
Minor: "42",
|
||||
GitVersion: "42.42",
|
||||
}
|
||||
func fakeVersionInfo() version.Info {
|
||||
baseVer := baseversion.Get()
|
||||
baseVer.Major = "42"
|
||||
baseVer.Minor = "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.
|
||||
|
@ -39,10 +39,10 @@ func (v Version) Install(c *restful.Container) {
|
||||
// Set up a service to return the git code version.
|
||||
versionWS := new(restful.WebService)
|
||||
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.GET("/").To(v.handleVersion).
|
||||
Doc("get the code version").
|
||||
Doc("get the version information for this server").
|
||||
Operation("getCodeVersion").
|
||||
Produces(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.
|
||||
// Only used in tests.
|
||||
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"))
|
||||
}
|
||||
|
||||
func defaultBuildBinaryVersion() *version.Version {
|
||||
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{
|
||||
"major": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "Major is the major version of the binary version",
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"minor": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "Minor is the minor version of the binary version",
|
||||
Default: "",
|
||||
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": {
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
apimachineryversion "k8s.io/apimachinery/pkg/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.
|
||||
// Used only for docs/help.
|
||||
AllowedMinCompatibilityVersionRange() string
|
||||
|
||||
// Info returns the version information of a component.
|
||||
Info() *apimachineryversion.Info
|
||||
}
|
||||
|
||||
type MutableEffectiveVersion interface {
|
||||
@ -173,6 +177,34 @@ func (m *effectiveVersion) Validate() []error {
|
||||
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.
|
||||
// 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.
|
||||
@ -209,5 +241,5 @@ func NewEffectiveVersionFromString(binaryVer, emulationVerFloor, minCompatibilit
|
||||
|
||||
func defaultBuildBinaryVersion() *version.Version {
|
||||
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
|
||||
// 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 {
|
||||
// These variables typically come from -ldflags settings and in
|
||||
// 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{
|
||||
"major": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "Major is the major version of the binary version",
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"minor": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "Minor is the minor version of the binary version",
|
||||
Default: "",
|
||||
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": {
|
||||
|
@ -2623,16 +2623,46 @@ func schema_k8sio_apimachinery_pkg_version_Info(ref common.ReferenceCallback) co
|
||||
Properties: map[string]spec.Schema{
|
||||
"major": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "Major is the major version of the binary version",
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"minor": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "Minor is the minor version of the binary version",
|
||||
Default: "",
|
||||
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": {
|
||||
|
@ -85,8 +85,14 @@ func TestClient(t *testing.T) {
|
||||
}
|
||||
expectedInfo := utilversion.Get()
|
||||
kubeVersion := compatibility.DefaultKubeEffectiveVersionForTest().BinaryVersion()
|
||||
emulationVersion := compatibility.DefaultKubeEffectiveVersionForTest().EmulationVersion()
|
||||
minCompatibilityVersion := compatibility.DefaultKubeEffectiveVersionForTest().MinCompatibilityVersion()
|
||||
expectedInfo.Major = fmt.Sprintf("%d", kubeVersion.Major())
|
||||
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) {
|
||||
t.Errorf("expected %#v, got %#v", e, a)
|
||||
|
Loading…
Reference in New Issue
Block a user