Merge pull request #130930 from siyuanfoundation/help

chore: update emulation version help msg.
This commit is contained in:
Kubernetes Prow Robot 2025-03-19 17:54:58 -07:00 committed by GitHub
commit b4c6895d0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 23 deletions

View File

@ -91,6 +91,7 @@ func (s *Server) InstallAPIs(restStorageProviders ...RESTStorageProvider) error
// used later in the loop to filter the served resource by those that have expired.
resourceExpirationEvaluatorOpts := genericapiserver.ResourceExpirationEvaluatorOptions{
CurrentVersion: s.GenericAPIServer.EffectiveVersion.EmulationVersion(),
Prerelease: s.GenericAPIServer.EffectiveVersion.BinaryVersion().PreRelease(),
EmulationForwardCompatible: s.GenericAPIServer.EmulationForwardCompatible,
RuntimeConfigEmulationForwardCompatible: s.GenericAPIServer.RuntimeConfigEmulationForwardCompatible,
}

View File

@ -66,6 +66,9 @@ type ResourceExpirationEvaluator interface {
type ResourceExpirationEvaluatorOptions struct {
// CurrentVersion is the current version of the apiserver.
CurrentVersion *apimachineryversion.Version
// Prerelease holds an optional prerelease portion of the version.
// This is used to determine if the current binary is an alpha.
Prerelease string
// EmulationForwardCompatible indicates whether the apiserver should serve resources that are introduced after the current version,
// when resources of the same group and resource name but with lower priority are served.
EmulationForwardCompatible bool
@ -76,7 +79,8 @@ type ResourceExpirationEvaluatorOptions struct {
func NewResourceExpirationEvaluator(currentVersion *apimachineryversion.Version) (ResourceExpirationEvaluator, error) {
opts := ResourceExpirationEvaluatorOptions{
CurrentVersion: currentVersion,
CurrentVersion: apimachineryversion.MajorMinor(currentVersion.Major(), currentVersion.Minor()),
Prerelease: currentVersion.PreRelease(),
}
return NewResourceExpirationEvaluatorFromOptions(opts)
}
@ -94,8 +98,8 @@ func NewResourceExpirationEvaluatorFromOptions(opts ResourceExpirationEvaluatorO
}
// Only keeps the major and minor versions from input version.
ret.currentVersion = apimachineryversion.MajorMinor(currentVersion.Major(), currentVersion.Minor())
ret.isAlpha = strings.Contains(currentVersion.PreRelease(), "alpha")
ret.isAlphaZero = strings.Contains(currentVersion.PreRelease(), "alpha.0")
ret.isAlpha = strings.Contains(opts.Prerelease, "alpha")
ret.isAlphaZero = strings.Contains(opts.Prerelease, "alpha.0")
if envString, ok := os.LookupEnv("KUBE_APISERVER_STRICT_REMOVED_API_HANDLING_IN_ALPHA"); !ok {
// do nothing

View File

@ -234,8 +234,8 @@ func (r *componentGlobalsRegistry) AddFlags(fs *pflag.FlagSet) {
fs.StringSliceVar(&r.emulationVersionConfig, "emulated-version", r.emulationVersionConfig, ""+
"The versions different components emulate their capabilities (APIs, features, ...) of.\n"+
"If set, the component will emulate the behavior of this version instead of the underlying binary version.\n"+
"Version format could only be major.minor, for example: '--emulated-version=wardle=1.2,kube=1.31'. Options are:\n"+strings.Join(r.unsafeVersionFlagOptions(true), "\n")+
"If the component is not specified, defaults to \"kube\"")
"Version format could only be major.minor, for example: '--emulated-version=wardle=1.2,kube=1.31'.\nOptions are: "+strings.Join(r.unsafeVersionFlagOptions(true), ",")+
"\nIf the component is not specified, defaults to \"kube\"")
if r.featureGatesConfigFlags == nil {
r.featureGatesConfigFlags = cliflag.NewColonSeparatedMultimapStringStringAllowDefaultEmptyKey(&r.featureGatesConfig)

View File

@ -57,7 +57,7 @@ func TestEffectiveVersionRegistry(t *testing.T) {
func testRegistry(t *testing.T) *componentGlobalsRegistry {
r := NewComponentGlobalsRegistry()
verKube := NewEffectiveVersionFromString("1.31", "1.31", "1.30")
verKube := NewEffectiveVersionFromString("1.31.1-beta.0.353", "1.31", "1.30")
fgKube := featuregate.NewVersionedFeatureGate(version.MustParse("0.0"))
err := fgKube.AddVersioned(map[featuregate.Feature]featuregate.VersionedSpecs{
"kubeA": {
@ -103,13 +103,13 @@ func testRegistry(t *testing.T) *componentGlobalsRegistry {
func TestVersionFlagOptions(t *testing.T) {
r := testRegistry(t)
emuVers := strings.Join(r.unsafeVersionFlagOptions(true), "\n")
expectedEmuVers := "kube=1.31..1.31 (default=1.31)\ntest=2.8..2.8 (default=2.8)"
emuVers := strings.Join(r.unsafeVersionFlagOptions(true), ",")
expectedEmuVers := "kube=1.31..1.31(default:1.31),test=2.8..2.8(default:2.8)"
if emuVers != expectedEmuVers {
t.Errorf("wanted emulation version flag options to be: %s, got %s", expectedEmuVers, emuVers)
}
minCompVers := strings.Join(r.unsafeVersionFlagOptions(false), "\n")
expectedMinCompVers := "kube=1.30..1.31 (default=1.30)\ntest=2.7..2.8 (default=2.7)"
minCompVers := strings.Join(r.unsafeVersionFlagOptions(false), ",")
expectedMinCompVers := "kube=1.30..1.31(default:1.30),test=2.7..2.8(default:2.7)"
if minCompVers != expectedMinCompVers {
t.Errorf("wanted min compatibility version flag options to be: %s, got %s", expectedMinCompVers, minCompVers)
}
@ -119,13 +119,13 @@ func TestVersionFlagOptionsWithMapping(t *testing.T) {
r := testRegistry(t)
utilruntime.Must(r.SetEmulationVersionMapping(testComponent, DefaultKubeComponent,
func(from *version.Version) *version.Version { return version.MajorMinor(1, from.Minor()+23) }))
emuVers := strings.Join(r.unsafeVersionFlagOptions(true), "\n")
expectedEmuVers := "test=2.8..2.8 (default=2.8)"
emuVers := strings.Join(r.unsafeVersionFlagOptions(true), ",")
expectedEmuVers := "test=2.8..2.8(default:2.8)"
if emuVers != expectedEmuVers {
t.Errorf("wanted emulation version flag options to be: %s, got %s", expectedEmuVers, emuVers)
}
minCompVers := strings.Join(r.unsafeVersionFlagOptions(false), "\n")
expectedMinCompVers := "kube=1.30..1.31 (default=1.30)\ntest=2.7..2.8 (default=2.7)"
minCompVers := strings.Join(r.unsafeVersionFlagOptions(false), ",")
expectedMinCompVers := "kube=1.30..1.31(default:1.30),test=2.7..2.8(default:2.7)"
if minCompVers != expectedMinCompVers {
t.Errorf("wanted min compatibility version flag options to be: %s, got %s", expectedMinCompVers, minCompVers)
}

View File

@ -79,13 +79,7 @@ func (m *effectiveVersion) BinaryVersion() *version.Version {
}
func (m *effectiveVersion) EmulationVersion() *version.Version {
ver := m.emulationVersion.Load()
if ver != nil {
// Emulation version can have "alpha" as pre-release to continue serving expired apis while we clean up the test.
// The pre-release should not be accessible to the users.
return ver.WithPreRelease(m.BinaryVersion().PreRelease())
}
return ver
return m.emulationVersion.Load()
}
func (m *effectiveVersion) MinCompatibilityVersion() *version.Version {
@ -140,7 +134,7 @@ func (m *effectiveVersion) AllowedEmulationVersionRange() string {
floor = version.MajorMinor(0, 0)
}
return fmt.Sprintf("%s..%s (default=%s)", floor.String(), binaryVersion.String(), m.EmulationVersion().String())
return fmt.Sprintf("%s..%s(default:%s)", floor.String(), binaryVersion.String(), m.EmulationVersion().String())
}
func (m *effectiveVersion) AllowedMinCompatibilityVersionRange() string {
@ -157,7 +151,7 @@ func (m *effectiveVersion) AllowedMinCompatibilityVersionRange() string {
floor = version.MajorMinor(0, 0)
}
return fmt.Sprintf("%s..%s (default=%s)", floor.String(), binaryVersion.String(), m.MinCompatibilityVersion().String())
return fmt.Sprintf("%s..%s(default:%s)", floor.String(), binaryVersion.String(), m.MinCompatibilityVersion().String())
}
func (m *effectiveVersion) Validate() []error {