Last active
November 27, 2023 14:07
-
-
Save aojea/7da734626e4a5287ff26461362db1c18 to your computer and use it in GitHub Desktop.
Kubernetes features evolution
This file contains hidden or 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
diff --git a/cmd/genfeatures/genfeatures.go b/cmd/genfeatures/genfeatures.go | |
new file mode 100644 | |
index 00000000000..953305e2715 | |
--- /dev/null | |
+++ b/cmd/genfeatures/genfeatures.go | |
@@ -0,0 +1,43 @@ | |
+/* | |
+Copyright 2023 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 main | |
+ | |
+import ( | |
+ "encoding/csv" | |
+ "log" | |
+ "os" | |
+ "strconv" | |
+ | |
+ "k8s.io/apiserver/pkg/util/feature" | |
+ _ "k8s.io/kubernetes/pkg/features" // load the defaultKubernetesFeatureGates | |
+) | |
+ | |
+// generate a CSV with the existing features and the following headers | |
+// name, default, lock_to_default, state | |
+func main() { | |
+ records := [][]string{{"name", "default", "lock_to_default", "state"}} | |
+ | |
+ for k, v := range feature.DefaultMutableFeatureGate.GetAll() { | |
+ records = append(records, []string{string(k), strconv.FormatBool(v.Default), strconv.FormatBool(v.LockToDefault), string(v.PreRelease)}) | |
+ } | |
+ | |
+ w := csv.NewWriter(os.Stdout) | |
+ w.WriteAll(records) | |
+ if err := w.Error(); err != nil { | |
+ log.Fatal(err) | |
+ } | |
+} |
This file contains hidden or 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
# part of Jordan's ba6b4c5a18c455867f11036a7208962e84012a86 | |
# needed for versions previous to 1.22 | |
diff --git a/staging/src/k8s.io/component-base/featuregate/feature_gate.go b/staging/src/k8s.io/component-base/featuregate/feature_gate.go | |
index c805ffb01b5..c7166d80b84 100644 | |
--- a/staging/src/k8s.io/component-base/featuregate/feature_gate.go | |
+++ b/staging/src/k8s.io/component-base/featuregate/feature_gate.go | |
@@ -109,6 +109,8 @@ type MutableFeatureGate interface { | |
SetFromMap(m map[string]bool) error | |
// Add adds features to the featureGate. | |
Add(features map[Feature]FeatureSpec) error | |
+ // GetAll returns a copy of the map of known feature names to feature specs. | |
+ GetAll() map[Feature]FeatureSpec | |
} | |
// featureGate implements FeatureGate as well as pflag.Value for flag parsing. | |
@@ -290,6 +292,15 @@ func (f *featureGate) Add(features map[Feature]FeatureSpec) error { | |
return nil | |
} | |
+// GetAll returns a copy of the map of known feature names to feature specs. | |
+func (f *featureGate) GetAll() map[Feature]FeatureSpec { | |
+ retval := map[Feature]FeatureSpec{} | |
+ for k, v := range f.known.Load().(map[Feature]FeatureSpec) { | |
+ retval[k] = v | |
+ } | |
+ return retval | |
+} | |
+ | |
// Enabled returns true if the key is enabled. If the key is not known, this call will panic. | |
func (f *featureGate) Enabled(key Feature) bool { | |
if v, ok := f.enabled.Load().(map[Feature]bool)[key]; ok { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For previous versions generate the patch in each branch