From 751ba43ef7bad38147d6fb26ea598a6f032d7b41 Mon Sep 17 00:00:00 2001 From: "geetikab@vmware.com" Date: Wed, 1 Sep 2021 21:18:12 +0530 Subject: [PATCH] Add feature gate machinery Currently CAPG doesn't have capability of adding features via feature gates. This change would add feature gate machinery. Signed-off-by: Geetika Batra --- feature/feature.go | 42 ++++++++++++++++++++++++++++++++++++++++++ feature/gates.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 feature/feature.go create mode 100644 feature/gates.go diff --git a/feature/feature.go b/feature/feature.go new file mode 100644 index 000000000..c9cb95668 --- /dev/null +++ b/feature/feature.go @@ -0,0 +1,42 @@ +/* +Copyright 2020 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 feature + +import ( + "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/component-base/featuregate" +) + +const ( +// Every capg-specific feature gate should add method here following this template: +// +// // owner: @username +// // alpha: v1.X +// MyFeature featuregate.Feature = "MyFeature". + +) + +func init() { + runtime.Must(MutableGates.Add(defaultCAPGFeatureGates)) +} + +// defaultCAPGFeatureGates consists of all known capg-specific feature keys. +// To add a new feature, define a key for it above and add it here. +var defaultCAPGFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ + // Every feature should be initiated here: + +} diff --git a/feature/gates.go b/feature/gates.go new file mode 100644 index 000000000..bf73fb3ff --- /dev/null +++ b/feature/gates.go @@ -0,0 +1,34 @@ +/* +Copyright 2020 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 feature + +import ( + "k8s.io/component-base/featuregate" + "sigs.k8s.io/cluster-api/feature" +) + +var ( + // MutableGates is a mutable version of DefaultFeatureGate. + // Only top-level commands/options setup and the k8s.io/component-base/featuregate/testing package should make use of this. + // Tests that need to modify featuregate gates for the duration of their test should use: + // defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features., )() + MutableGates featuregate.MutableFeatureGate = feature.MutableGates + + // Gates is a shared global FeatureGate. + // Top-level commands/options setup that needs to modify this featuregate gate should use DefaultMutableFeatureGate. + Gates featuregate.FeatureGate = MutableGates +)