Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
component-base/logs: add feature gates
It is useful to have the ability to control whether alpha or beta features are enabled. We can group features under LoggingAlphaOptions and LoggingBetaOptions because the configuration is designed so that each feature individually must be enabled via its own option. Currently, the JSON format itself is beta (graduated in 1.23) but additional options for it were only added in 1.23 and thus are still alpha: $ go run ./staging/src/k8s.io/component-base/logs/example/cmd/logger.go --logging-format=json --log-json-split-stream --log-json-info-buffer-size 1M --feature-gates LoggingBetaOptions=false [format: Forbidden: Log format json is BETA and disabled, see LoggingBetaOptions feature, options.json.splitStream: Forbidden: Feature LoggingAlphaOptions is disabled, options.json.infoBufferSize: Forbidden: Feature LoggingAlphaOptions is disabled] $ go run ./staging/src/k8s.io/component-base/logs/example/cmd/logger.go --logging-format=json --log-json-split-stream --log-json-info-buffer-size 1M [options.json.splitStream: Forbidden: Feature LoggingAlphaOptions is disabled, options.json.infoBufferSize: Forbidden: Feature LoggingAlphaOptions is disabled] This is the same approach that was taken for CPUManagerPolicyAlphaOptions and CPUManagerPolicyBetaOptions.
- Loading branch information
Showing
17 changed files
with
296 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1 | ||
|
||
import ( | ||
"k8s.io/component-base/featuregate" | ||
) | ||
|
||
const ( | ||
// owner: @pohly | ||
// alpha: v1.24 | ||
// beta: see LoggingBetaOptions | ||
// | ||
// Allow fine-tuning of experimental, alpha-quality logging options. | ||
// | ||
// Per https://groups.google.com/g/kubernetes-sig-architecture/c/Nxsc7pfe5rw/m/vF2djJh0BAAJ | ||
// we want to avoid a proliferation of feature gates. This feature gate: | ||
// - will guard *a group* of logging options whose quality level is alpha. | ||
// - will never graduate to beta or stable. | ||
LoggingAlphaOptions featuregate.Feature = "LoggingAlphaOptions" | ||
|
||
// owner: @pohly | ||
// alpha: see LoggingAlphaOptions | ||
// beta: v1.24 | ||
// | ||
// Allow fine-tuning of experimental, beta-quality logging options. | ||
// | ||
// Per https://groups.google.com/g/kubernetes-sig-architecture/c/Nxsc7pfe5rw/m/vF2djJh0BAAJ | ||
// we want to avoid a proliferation of feature gates. This feature gate: | ||
// - will guard *a group* of logging options whose quality level is beta. | ||
// - is thus *introduced* as beta | ||
// - will never graduate to stable. | ||
LoggingBetaOptions featuregate.Feature = "LoggingBetaOptions" | ||
) | ||
|
||
// FeatureGates defines the feature gates checked by | ||
// LoggingConfiguration.ValidateAndApply. They must be added to a MutableFeatureGate | ||
// by the user of the package, otherwise that function uses the defaults | ||
// defined here. | ||
var FeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ | ||
LoggingAlphaOptions: {Default: false, PreRelease: featuregate.Alpha}, | ||
LoggingBetaOptions: {Default: true, PreRelease: featuregate.Beta}, | ||
} |
47 changes: 47 additions & 0 deletions
47
staging/src/k8s.io/component-base/logs/api/v1/features_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1 | ||
|
||
import ( | ||
"k8s.io/component-base/featuregate" | ||
) | ||
|
||
var ( | ||
// pre-defined feature gates with the features from this package in a | ||
// certain state (default, all enabled, all disabled). | ||
defaultFeatureGate, enabledFeatureGate, disabledFeatureGate featuregate.FeatureGate | ||
) | ||
|
||
func init() { | ||
mutable := featuregate.NewFeatureGate() | ||
if err := mutable.Add(FeatureGates); err != nil { | ||
panic(err) | ||
} | ||
defaultFeatureGate = mutable | ||
enabled := mutable.DeepCopy() | ||
disabled := mutable.DeepCopy() | ||
for feature := range mutable.GetAll() { | ||
if err := enabled.SetFromMap(map[string]bool{string(feature): true}); err != nil { | ||
panic(err) | ||
} | ||
if err := disabled.SetFromMap(map[string]bool{string(feature): false}); err != nil { | ||
panic(err) | ||
} | ||
} | ||
enabledFeatureGate = enabled | ||
disabledFeatureGate = disabled | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.