Skip to content

Commit b4c6895

Browse files
authored
Merge pull request kubernetes#130930 from siyuanfoundation/help
chore: update emulation version help msg.
2 parents 63bd581 + 0ec6566 commit b4c6895

File tree

5 files changed

+22
-23
lines changed

5 files changed

+22
-23
lines changed

pkg/controlplane/apiserver/apis.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (s *Server) InstallAPIs(restStorageProviders ...RESTStorageProvider) error
9191
// used later in the loop to filter the served resource by those that have expired.
9292
resourceExpirationEvaluatorOpts := genericapiserver.ResourceExpirationEvaluatorOptions{
9393
CurrentVersion: s.GenericAPIServer.EffectiveVersion.EmulationVersion(),
94+
Prerelease: s.GenericAPIServer.EffectiveVersion.BinaryVersion().PreRelease(),
9495
EmulationForwardCompatible: s.GenericAPIServer.EmulationForwardCompatible,
9596
RuntimeConfigEmulationForwardCompatible: s.GenericAPIServer.RuntimeConfigEmulationForwardCompatible,
9697
}

staging/src/k8s.io/apiserver/pkg/server/deleted_kinds.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ type ResourceExpirationEvaluator interface {
6666
type ResourceExpirationEvaluatorOptions struct {
6767
// CurrentVersion is the current version of the apiserver.
6868
CurrentVersion *apimachineryversion.Version
69+
// Prerelease holds an optional prerelease portion of the version.
70+
// This is used to determine if the current binary is an alpha.
71+
Prerelease string
6972
// EmulationForwardCompatible indicates whether the apiserver should serve resources that are introduced after the current version,
7073
// when resources of the same group and resource name but with lower priority are served.
7174
EmulationForwardCompatible bool
@@ -76,7 +79,8 @@ type ResourceExpirationEvaluatorOptions struct {
7679

7780
func NewResourceExpirationEvaluator(currentVersion *apimachineryversion.Version) (ResourceExpirationEvaluator, error) {
7881
opts := ResourceExpirationEvaluatorOptions{
79-
CurrentVersion: currentVersion,
82+
CurrentVersion: apimachineryversion.MajorMinor(currentVersion.Major(), currentVersion.Minor()),
83+
Prerelease: currentVersion.PreRelease(),
8084
}
8185
return NewResourceExpirationEvaluatorFromOptions(opts)
8286
}
@@ -94,8 +98,8 @@ func NewResourceExpirationEvaluatorFromOptions(opts ResourceExpirationEvaluatorO
9498
}
9599
// Only keeps the major and minor versions from input version.
96100
ret.currentVersion = apimachineryversion.MajorMinor(currentVersion.Major(), currentVersion.Minor())
97-
ret.isAlpha = strings.Contains(currentVersion.PreRelease(), "alpha")
98-
ret.isAlphaZero = strings.Contains(currentVersion.PreRelease(), "alpha.0")
101+
ret.isAlpha = strings.Contains(opts.Prerelease, "alpha")
102+
ret.isAlphaZero = strings.Contains(opts.Prerelease, "alpha.0")
99103

100104
if envString, ok := os.LookupEnv("KUBE_APISERVER_STRICT_REMOVED_API_HANDLING_IN_ALPHA"); !ok {
101105
// do nothing

staging/src/k8s.io/component-base/compatibility/registry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ func (r *componentGlobalsRegistry) AddFlags(fs *pflag.FlagSet) {
234234
fs.StringSliceVar(&r.emulationVersionConfig, "emulated-version", r.emulationVersionConfig, ""+
235235
"The versions different components emulate their capabilities (APIs, features, ...) of.\n"+
236236
"If set, the component will emulate the behavior of this version instead of the underlying binary version.\n"+
237-
"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")+
238-
"If the component is not specified, defaults to \"kube\"")
237+
"Version format could only be major.minor, for example: '--emulated-version=wardle=1.2,kube=1.31'.\nOptions are: "+strings.Join(r.unsafeVersionFlagOptions(true), ",")+
238+
"\nIf the component is not specified, defaults to \"kube\"")
239239

240240
if r.featureGatesConfigFlags == nil {
241241
r.featureGatesConfigFlags = cliflag.NewColonSeparatedMultimapStringStringAllowDefaultEmptyKey(&r.featureGatesConfig)

staging/src/k8s.io/component-base/compatibility/registry_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestEffectiveVersionRegistry(t *testing.T) {
5757

5858
func testRegistry(t *testing.T) *componentGlobalsRegistry {
5959
r := NewComponentGlobalsRegistry()
60-
verKube := NewEffectiveVersionFromString("1.31", "1.31", "1.30")
60+
verKube := NewEffectiveVersionFromString("1.31.1-beta.0.353", "1.31", "1.30")
6161
fgKube := featuregate.NewVersionedFeatureGate(version.MustParse("0.0"))
6262
err := fgKube.AddVersioned(map[featuregate.Feature]featuregate.VersionedSpecs{
6363
"kubeA": {
@@ -103,13 +103,13 @@ func testRegistry(t *testing.T) *componentGlobalsRegistry {
103103

104104
func TestVersionFlagOptions(t *testing.T) {
105105
r := testRegistry(t)
106-
emuVers := strings.Join(r.unsafeVersionFlagOptions(true), "\n")
107-
expectedEmuVers := "kube=1.31..1.31 (default=1.31)\ntest=2.8..2.8 (default=2.8)"
106+
emuVers := strings.Join(r.unsafeVersionFlagOptions(true), ",")
107+
expectedEmuVers := "kube=1.31..1.31(default:1.31),test=2.8..2.8(default:2.8)"
108108
if emuVers != expectedEmuVers {
109109
t.Errorf("wanted emulation version flag options to be: %s, got %s", expectedEmuVers, emuVers)
110110
}
111-
minCompVers := strings.Join(r.unsafeVersionFlagOptions(false), "\n")
112-
expectedMinCompVers := "kube=1.30..1.31 (default=1.30)\ntest=2.7..2.8 (default=2.7)"
111+
minCompVers := strings.Join(r.unsafeVersionFlagOptions(false), ",")
112+
expectedMinCompVers := "kube=1.30..1.31(default:1.30),test=2.7..2.8(default:2.7)"
113113
if minCompVers != expectedMinCompVers {
114114
t.Errorf("wanted min compatibility version flag options to be: %s, got %s", expectedMinCompVers, minCompVers)
115115
}
@@ -119,13 +119,13 @@ func TestVersionFlagOptionsWithMapping(t *testing.T) {
119119
r := testRegistry(t)
120120
utilruntime.Must(r.SetEmulationVersionMapping(testComponent, DefaultKubeComponent,
121121
func(from *version.Version) *version.Version { return version.MajorMinor(1, from.Minor()+23) }))
122-
emuVers := strings.Join(r.unsafeVersionFlagOptions(true), "\n")
123-
expectedEmuVers := "test=2.8..2.8 (default=2.8)"
122+
emuVers := strings.Join(r.unsafeVersionFlagOptions(true), ",")
123+
expectedEmuVers := "test=2.8..2.8(default:2.8)"
124124
if emuVers != expectedEmuVers {
125125
t.Errorf("wanted emulation version flag options to be: %s, got %s", expectedEmuVers, emuVers)
126126
}
127-
minCompVers := strings.Join(r.unsafeVersionFlagOptions(false), "\n")
128-
expectedMinCompVers := "kube=1.30..1.31 (default=1.30)\ntest=2.7..2.8 (default=2.7)"
127+
minCompVers := strings.Join(r.unsafeVersionFlagOptions(false), ",")
128+
expectedMinCompVers := "kube=1.30..1.31(default:1.30),test=2.7..2.8(default:2.7)"
129129
if minCompVers != expectedMinCompVers {
130130
t.Errorf("wanted min compatibility version flag options to be: %s, got %s", expectedMinCompVers, minCompVers)
131131
}

staging/src/k8s.io/component-base/compatibility/version.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,7 @@ func (m *effectiveVersion) BinaryVersion() *version.Version {
7979
}
8080

8181
func (m *effectiveVersion) EmulationVersion() *version.Version {
82-
ver := m.emulationVersion.Load()
83-
if ver != nil {
84-
// Emulation version can have "alpha" as pre-release to continue serving expired apis while we clean up the test.
85-
// The pre-release should not be accessible to the users.
86-
return ver.WithPreRelease(m.BinaryVersion().PreRelease())
87-
}
88-
return ver
82+
return m.emulationVersion.Load()
8983
}
9084

9185
func (m *effectiveVersion) MinCompatibilityVersion() *version.Version {
@@ -140,7 +134,7 @@ func (m *effectiveVersion) AllowedEmulationVersionRange() string {
140134
floor = version.MajorMinor(0, 0)
141135
}
142136

143-
return fmt.Sprintf("%s..%s (default=%s)", floor.String(), binaryVersion.String(), m.EmulationVersion().String())
137+
return fmt.Sprintf("%s..%s(default:%s)", floor.String(), binaryVersion.String(), m.EmulationVersion().String())
144138
}
145139

146140
func (m *effectiveVersion) AllowedMinCompatibilityVersionRange() string {
@@ -157,7 +151,7 @@ func (m *effectiveVersion) AllowedMinCompatibilityVersionRange() string {
157151
floor = version.MajorMinor(0, 0)
158152
}
159153

160-
return fmt.Sprintf("%s..%s (default=%s)", floor.String(), binaryVersion.String(), m.MinCompatibilityVersion().String())
154+
return fmt.Sprintf("%s..%s(default:%s)", floor.String(), binaryVersion.String(), m.MinCompatibilityVersion().String())
161155
}
162156

163157
func (m *effectiveVersion) Validate() []error {

0 commit comments

Comments
 (0)