Skip to content

Instantly share code, notes, and snippets.

@aojea
Last active November 27, 2023 14:07
Show Gist options
  • Save aojea/7da734626e4a5287ff26461362db1c18 to your computer and use it in GitHub Desktop.
Save aojea/7da734626e4a5287ff26461362db1c18 to your computer and use it in GitHub Desktop.
Kubernetes features evolution
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)
+ }
+}
# 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 {
@aojea
Copy link
Author

aojea commented Nov 27, 2023

for i in $(seq 22 28) ; do git checkout upstream/release-1.${i} ; go run cmd/genfeatures/genfeatures.go > /tmp/features_1.${i}.csv ; done

For previous versions generate the patch in each branch

git checkout upstream/release-1.21
git diff -R upstream/release-1.22..HEAD -- staging/src/k8s.io/component-base/featuregate/feature_gate.go > 1.patch
git apply 1.patch
go run -mod=mod cmd/genfeatures/genfeatures.go > /tmp/features_1.21.csv 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment