Skip to content

Commit 7d1643b

Browse files
authored
Merge pull request kubernetes#129411 from yongruilin/compatibility-version-migration
chore: migrate logging featuregates to versioned
2 parents 6c445ca + 4f7ce75 commit 7d1643b

File tree

4 files changed

+48
-33
lines changed

4 files changed

+48
-33
lines changed

staging/src/k8s.io/component-base/logs/api/v1/kube_features.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1
1818

1919
import (
20+
"k8s.io/apimachinery/pkg/util/version"
2021
"k8s.io/component-base/featuregate"
2122
)
2223

@@ -31,17 +32,16 @@ const (
3132
// used by a call chain.
3233
ContextualLogging featuregate.Feature = "ContextualLogging"
3334

34-
// contextualLoggingDefault is now true because the feature reached beta
35-
// and performance comparisons showed no relevant degradation when
36-
// enabling it.
37-
contextualLoggingDefault = true
38-
3935
// Allow fine-tuning of experimental, alpha-quality logging options.
4036
//
4137
// Per https://groups.google.com/g/kubernetes-sig-architecture/c/Nxsc7pfe5rw/m/vF2djJh0BAAJ
4238
// we want to avoid a proliferation of feature gates. This feature gate:
4339
// - will guard *a group* of logging options whose quality level is alpha.
4440
// - will never graduate to beta or stable.
41+
//
42+
// IMPORTANT: Unlike typical feature gates, LoggingAlphaOptions is NOT affected by
43+
// emulation version changes. Its behavior remains constant regardless of the
44+
// emulation version being used.
4545
LoggingAlphaOptions featuregate.Feature = "LoggingAlphaOptions"
4646

4747
// Allow fine-tuning of experimental, beta-quality logging options.
@@ -51,22 +51,32 @@ const (
5151
// - will guard *a group* of logging options whose quality level is beta.
5252
// - is thus *introduced* as beta
5353
// - will never graduate to stable.
54+
//
55+
// IMPORTANT: Unlike typical feature gates, LoggingBetaOptions is NOT affected by
56+
// emulation version changes. Its behavior remains constant regardless of the
57+
// emulation version being used.
5458
LoggingBetaOptions featuregate.Feature = "LoggingBetaOptions"
5559

5660
// Stable logging options. Always enabled.
5761
LoggingStableOptions featuregate.Feature = "LoggingStableOptions"
5862
)
5963

60-
func featureGates() map[featuregate.Feature]featuregate.FeatureSpec {
61-
return map[featuregate.Feature]featuregate.FeatureSpec{
62-
ContextualLogging: {Default: contextualLoggingDefault, PreRelease: featuregate.Beta},
63-
64-
LoggingAlphaOptions: {Default: false, PreRelease: featuregate.Alpha},
65-
LoggingBetaOptions: {Default: true, PreRelease: featuregate.Beta},
64+
func featureGates() map[featuregate.Feature]featuregate.VersionedSpecs {
65+
return map[featuregate.Feature]featuregate.VersionedSpecs{
66+
ContextualLogging: {
67+
{Version: version.MustParse("1.24"), Default: false, PreRelease: featuregate.Alpha},
68+
{Version: version.MustParse("1.30"), Default: true, PreRelease: featuregate.Beta},
69+
},
70+
LoggingAlphaOptions: {
71+
{Version: version.MustParse("1.24"), Default: false, PreRelease: featuregate.Alpha},
72+
},
73+
LoggingBetaOptions: {
74+
{Version: version.MustParse("1.24"), Default: true, PreRelease: featuregate.Beta},
75+
},
6676
}
6777
}
6878

6979
// AddFeatureGates adds all feature gates used by this package.
70-
func AddFeatureGates(mutableFeatureGate featuregate.MutableFeatureGate) error {
71-
return mutableFeatureGate.Add(featureGates()) //nolint:forbidigo // The logging feature gates are by design unversioned (perpetual alpha/beta).
80+
func AddFeatureGates(mutableFeatureGate featuregate.MutableVersionedFeatureGate) error {
81+
return mutableFeatureGate.AddVersioned(featureGates())
7282
}

staging/src/k8s.io/component-base/logs/api/v1/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func Validate(c *LoggingConfiguration, featureGate featuregate.FeatureGate, fldP
153153
errs = append(errs, field.Invalid(fldPath.Child("format"), c.Format, "Unsupported log format"))
154154
} else if format != nil {
155155
if format.feature != LoggingStableOptions {
156-
enabled := featureGates()[format.feature].Default
156+
enabled := featureGates()[format.feature][len(featureGates()[format.feature])-1].Default
157157
if featureGate != nil {
158158
enabled = featureGate.Enabled(format.feature)
159159
}
@@ -228,7 +228,7 @@ func apply(c *LoggingConfiguration, options *LoggingOptions, featureGate feature
228228
p := &parameters{
229229
C: c,
230230
Options: options,
231-
ContextualLoggingEnabled: contextualLoggingDefault,
231+
ContextualLoggingEnabled: true,
232232
}
233233
if featureGate != nil {
234234
p.ContextualLoggingEnabled = featureGate.Enabled(ContextualLogging)
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1 @@
1-
- name: ContextualLogging
2-
versionedSpecs:
3-
- default: true
4-
lockToDefault: false
5-
preRelease: Beta
6-
version: ""
7-
- name: LoggingAlphaOptions
8-
versionedSpecs:
9-
- default: false
10-
lockToDefault: false
11-
preRelease: Alpha
12-
version: ""
13-
- name: LoggingBetaOptions
14-
versionedSpecs:
15-
- default: true
16-
lockToDefault: false
17-
preRelease: Beta
18-
version: ""
1+
[]

test/featuregates_linter/test_data/versioned_feature_list.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,16 @@
248248
lockToDefault: false
249249
preRelease: Beta
250250
version: "1.30"
251+
- name: ContextualLogging
252+
versionedSpecs:
253+
- default: false
254+
lockToDefault: false
255+
preRelease: Alpha
256+
version: "1.24"
257+
- default: true
258+
lockToDefault: false
259+
preRelease: Beta
260+
version: "1.30"
251261
- name: CoordinatedLeaderElection
252262
versionedSpecs:
253263
- default: false
@@ -738,6 +748,18 @@
738748
lockToDefault: true
739749
preRelease: GA
740750
version: "1.31"
751+
- name: LoggingAlphaOptions
752+
versionedSpecs:
753+
- default: false
754+
lockToDefault: false
755+
preRelease: Alpha
756+
version: "1.24"
757+
- name: LoggingBetaOptions
758+
versionedSpecs:
759+
- default: true
760+
lockToDefault: false
761+
preRelease: Beta
762+
version: "1.24"
741763
- name: MatchLabelKeysInPodAffinity
742764
versionedSpecs:
743765
- default: false

0 commit comments

Comments
 (0)