From 9fe45a628de2e74d9cd73c3650fa2582aaac5213 Mon Sep 17 00:00:00 2001 From: Bryce Palmer Date: Thu, 8 Jun 2023 16:08:21 -0400 Subject: [PATCH] Add feature gates infrastructure (#90) --- cmd/manager/main.go | 13 ++++++++++--- go.mod | 4 ++-- pkg/features/features.go | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 pkg/features/features.go diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 89556c07..e70942e7 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -35,7 +35,10 @@ import ( "github.com/operator-framework/catalogd/internal/source" "github.com/operator-framework/catalogd/internal/version" corecontrollers "github.com/operator-framework/catalogd/pkg/controllers/core" + "github.com/operator-framework/catalogd/pkg/features" "github.com/operator-framework/catalogd/pkg/profile" + "github.com/spf13/pflag" + //+kubebuilder:scaffold:imports "github.com/operator-framework/catalogd/api/core/v1alpha1" ) @@ -70,13 +73,17 @@ func main() { // TODO: should we move the unpacker to some common place? Or... hear me out... should catalogd just be a rukpak provisioner? flag.StringVar(&unpackImage, "unpack-image", "quay.io/operator-framework/rukpak:v0.12.0", "The unpack image to use when unpacking catalog images") flag.StringVar(&sysNs, "system-ns", "catalogd-system", "The namespace catalogd uses for internal state, configuration, and workloads") + flag.BoolVar(&profiling, "profiling", false, "enable profiling endpoints to allow for using pprof") + flag.BoolVar(&catalogdVersion, "version", false, "print the catalogd version and exit") opts := zap.Options{ Development: true, } - flag.BoolVar(&profiling, "profiling", false, "enable profiling endpoints to allow for using pprof") - flag.BoolVar(&catalogdVersion, "version", false, "print the catalogd version and exit") opts.BindFlags(flag.CommandLine) - flag.Parse() + + // Combine both flagsets and parse them + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + features.CatalogdFeatureGate.AddFlag(pflag.CommandLine) + pflag.Parse() if catalogdVersion { fmt.Printf("%#v\n", version.Version()) diff --git a/go.mod b/go.mod index 0c840df3..88e3b018 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,11 @@ require ( github.com/onsi/ginkgo/v2 v2.9.7 github.com/onsi/gomega v1.27.7 github.com/operator-framework/operator-registry v1.26.3 + github.com/spf13/pflag v1.0.5 k8s.io/api v0.26.0 k8s.io/apimachinery v0.26.0 k8s.io/client-go v0.26.0 + k8s.io/component-base v0.26.0 k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 sigs.k8s.io/controller-runtime v0.14.0 ) @@ -57,7 +59,6 @@ require ( github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.37.0 // indirect github.com/prometheus/procfs v0.8.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.24.0 // indirect @@ -76,7 +77,6 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.26.0 // indirect - k8s.io/component-base v0.26.0 // indirect k8s.io/klog/v2 v2.80.1 // indirect k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect diff --git a/pkg/features/features.go b/pkg/features/features.go new file mode 100644 index 00000000..5069cf09 --- /dev/null +++ b/pkg/features/features.go @@ -0,0 +1,21 @@ +package features + +import ( + "k8s.io/component-base/featuregate" +) + +const ( +// Add new feature gates constants (strings) +// Ex: SomeFeature featuregate.Feature = "SomeFeature" +) + +var catalogdFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ + // Add new feature gate definitions + // Ex: SomeFeature: {...} +} + +var CatalogdFeatureGate featuregate.MutableFeatureGate = featuregate.NewFeatureGate() + +func init() { + CatalogdFeatureGate.Add(catalogdFeatureGates) +}