mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Restore honoring --version build ID overrides
This commit is contained in:
parent
8991b8ea60
commit
906d15782c
@ -64,7 +64,13 @@ function run_kube_apiserver() {
|
|||||||
# Enable features
|
# Enable features
|
||||||
ENABLE_FEATURE_GATES=""
|
ENABLE_FEATURE_GATES=""
|
||||||
|
|
||||||
|
VERSION_OVERRIDE=""
|
||||||
|
if [[ "${CUSTOM_VERSION_SUFFIX:-}" != "" ]]; then
|
||||||
|
VERSION_OVERRIDE="--version=$("${THIS_PLATFORM_BIN}/kube-apiserver" --version | awk '{print $2}')${CUSTOM_VERSION_SUFFIX:-}"
|
||||||
|
fi
|
||||||
|
|
||||||
"${THIS_PLATFORM_BIN}/kube-apiserver" \
|
"${THIS_PLATFORM_BIN}/kube-apiserver" \
|
||||||
|
${VERSION_OVERRIDE:+"${VERSION_OVERRIDE}"} \
|
||||||
--bind-address="127.0.0.1" \
|
--bind-address="127.0.0.1" \
|
||||||
--authorization-mode="${AUTHORIZATION_MODE}" \
|
--authorization-mode="${AUTHORIZATION_MODE}" \
|
||||||
--secure-port="${SECURE_API_PORT}" \
|
--secure-port="${SECURE_API_PORT}" \
|
||||||
@ -185,6 +191,14 @@ fi
|
|||||||
kube::log::status "Running kubectl tests for kube-apiserver"
|
kube::log::status "Running kubectl tests for kube-apiserver"
|
||||||
|
|
||||||
setup
|
setup
|
||||||
|
|
||||||
|
# Test custom version invocation
|
||||||
|
CUSTOM_VERSION_SUFFIX=-custom run_kube_apiserver
|
||||||
|
kube::test::if_has_string "$(kubectl get --raw /version)" "gitVersion.*-custom"
|
||||||
|
kill "${APISERVER_PID}" 1>&2 2>/dev/null
|
||||||
|
wait "${APISERVER_PID}" || true
|
||||||
|
unset APISERVER_PID
|
||||||
|
|
||||||
run_kube_apiserver
|
run_kube_apiserver
|
||||||
run_kube_controller_manager
|
run_kube_controller_manager
|
||||||
create_node
|
create_node
|
||||||
|
@ -41,6 +41,9 @@ type MutableEffectiveVersion interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type effectiveVersion struct {
|
type effectiveVersion struct {
|
||||||
|
// When true, BinaryVersion() returns the current binary version
|
||||||
|
useDefaultBuildBinaryVersion atomic.Bool
|
||||||
|
// Holds the last binary version stored in Set()
|
||||||
binaryVersion atomic.Pointer[version.Version]
|
binaryVersion atomic.Pointer[version.Version]
|
||||||
// If the emulationVersion is set by the users, it could only contain major and minor versions.
|
// If the emulationVersion is set by the users, it could only contain major and minor versions.
|
||||||
// In tests, emulationVersion could be the same as the binary version, or set directly,
|
// In tests, emulationVersion could be the same as the binary version, or set directly,
|
||||||
@ -51,6 +54,9 @@ type effectiveVersion struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *effectiveVersion) BinaryVersion() *version.Version {
|
func (m *effectiveVersion) BinaryVersion() *version.Version {
|
||||||
|
if m.useDefaultBuildBinaryVersion.Load() {
|
||||||
|
return defaultBuildBinaryVersion()
|
||||||
|
}
|
||||||
return m.binaryVersion.Load()
|
return m.binaryVersion.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +95,7 @@ func majorMinor(ver *version.Version) *version.Version {
|
|||||||
|
|
||||||
func (m *effectiveVersion) Set(binaryVersion, emulationVersion, minCompatibilityVersion *version.Version) {
|
func (m *effectiveVersion) Set(binaryVersion, emulationVersion, minCompatibilityVersion *version.Version) {
|
||||||
m.binaryVersion.Store(binaryVersion)
|
m.binaryVersion.Store(binaryVersion)
|
||||||
|
m.useDefaultBuildBinaryVersion.Store(false)
|
||||||
m.emulationVersion.Store(majorMinor(emulationVersion))
|
m.emulationVersion.Store(majorMinor(emulationVersion))
|
||||||
m.minCompatibilityVersion.Store(majorMinor(minCompatibilityVersion))
|
m.minCompatibilityVersion.Store(majorMinor(minCompatibilityVersion))
|
||||||
}
|
}
|
||||||
@ -104,7 +111,7 @@ func (m *effectiveVersion) SetMinCompatibilityVersion(minCompatibilityVersion *v
|
|||||||
func (m *effectiveVersion) Validate() []error {
|
func (m *effectiveVersion) Validate() []error {
|
||||||
var errs []error
|
var errs []error
|
||||||
// Validate only checks the major and minor versions.
|
// Validate only checks the major and minor versions.
|
||||||
binaryVersion := m.binaryVersion.Load().WithPatch(0)
|
binaryVersion := m.BinaryVersion().WithPatch(0)
|
||||||
emulationVersion := m.emulationVersion.Load()
|
emulationVersion := m.emulationVersion.Load()
|
||||||
minCompatibilityVersion := m.minCompatibilityVersion.Load()
|
minCompatibilityVersion := m.minCompatibilityVersion.Load()
|
||||||
|
|
||||||
@ -123,10 +130,11 @@ func (m *effectiveVersion) Validate() []error {
|
|||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEffectiveVersion(binaryVersion *version.Version) MutableEffectiveVersion {
|
func newEffectiveVersion(binaryVersion *version.Version, useDefaultBuildBinaryVersion bool) MutableEffectiveVersion {
|
||||||
effective := &effectiveVersion{}
|
effective := &effectiveVersion{}
|
||||||
compatVersion := binaryVersion.SubtractMinor(1)
|
compatVersion := binaryVersion.SubtractMinor(1)
|
||||||
effective.Set(binaryVersion, binaryVersion, compatVersion)
|
effective.Set(binaryVersion, binaryVersion, compatVersion)
|
||||||
|
effective.useDefaultBuildBinaryVersion.Store(useDefaultBuildBinaryVersion)
|
||||||
return effective
|
return effective
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,25 +143,29 @@ func NewEffectiveVersion(binaryVer string) MutableEffectiveVersion {
|
|||||||
return &effectiveVersion{}
|
return &effectiveVersion{}
|
||||||
}
|
}
|
||||||
binaryVersion := version.MustParse(binaryVer)
|
binaryVersion := version.MustParse(binaryVer)
|
||||||
return newEffectiveVersion(binaryVersion)
|
return newEffectiveVersion(binaryVersion, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultBuildBinaryVersion() *version.Version {
|
||||||
|
verInfo := baseversion.Get()
|
||||||
|
return version.MustParse(verInfo.String()).WithInfo(verInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultBuildEffectiveVersion returns the MutableEffectiveVersion based on the
|
// DefaultBuildEffectiveVersion returns the MutableEffectiveVersion based on the
|
||||||
// current build information.
|
// current build information.
|
||||||
func DefaultBuildEffectiveVersion() MutableEffectiveVersion {
|
func DefaultBuildEffectiveVersion() MutableEffectiveVersion {
|
||||||
verInfo := baseversion.Get()
|
binaryVersion := defaultBuildBinaryVersion()
|
||||||
binaryVersion := version.MustParse(verInfo.String()).WithInfo(verInfo)
|
|
||||||
if binaryVersion.Major() == 0 && binaryVersion.Minor() == 0 {
|
if binaryVersion.Major() == 0 && binaryVersion.Minor() == 0 {
|
||||||
return DefaultKubeEffectiveVersion()
|
return DefaultKubeEffectiveVersion()
|
||||||
}
|
}
|
||||||
return newEffectiveVersion(binaryVersion)
|
return newEffectiveVersion(binaryVersion, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultKubeEffectiveVersion returns the MutableEffectiveVersion based on the
|
// DefaultKubeEffectiveVersion returns the MutableEffectiveVersion based on the
|
||||||
// latest K8s release.
|
// latest K8s release.
|
||||||
func DefaultKubeEffectiveVersion() MutableEffectiveVersion {
|
func DefaultKubeEffectiveVersion() MutableEffectiveVersion {
|
||||||
binaryVersion := version.MustParse(baseversion.DefaultKubeBinaryVersion).WithInfo(baseversion.Get())
|
binaryVersion := version.MustParse(baseversion.DefaultKubeBinaryVersion).WithInfo(baseversion.Get())
|
||||||
return newEffectiveVersion(binaryVersion)
|
return newEffectiveVersion(binaryVersion, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateKubeEffectiveVersion validates the EmulationVersion is equal to the binary version at 1.31 for kube components.
|
// ValidateKubeEffectiveVersion validates the EmulationVersion is equal to the binary version at 1.31 for kube components.
|
||||||
|
Loading…
Reference in New Issue
Block a user