Skip to content

Commit

Permalink
feat: add feature gates to the controller manager
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneutt committed Oct 27, 2021
1 parent 9d82b0f commit b5fdfd8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
k8s.io/apiextensions-apiserver v0.22.2
k8s.io/apimachinery v0.22.2
k8s.io/client-go v0.22.2
k8s.io/component-base v0.22.2
knative.dev/networking v0.0.0-20210914225408-69ad45454096
knative.dev/pkg v0.0.0-20210919202233-5ae482141474
knative.dev/serving v0.26.0
Expand Down Expand Up @@ -118,7 +119,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/component-base v0.22.2 // indirect
k8s.io/klog/v2 v2.9.0 // indirect
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e // indirect
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a // indirect
Expand Down
8 changes: 8 additions & 0 deletions internal/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/pflag"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
cliflag "k8s.io/component-base/cli/flag"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kong/kubernetes-ingress-controller/v2/internal/adminapi"
Expand Down Expand Up @@ -81,6 +82,9 @@ type Config struct {
EnableProfiling bool
EnableConfigDumps bool
DumpSensitiveConfig bool

// Feature Gates
FeatureGates map[string]bool
}

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -182,6 +186,10 @@ func (c *Config) FlagSet() *pflag.FlagSet {
flagSet.Int("stderrthreshold", 0, "DEPRECATED: has no effect and will be removed in future releases (see github issue #1297)")
flagSet.Bool("update-status-on-shutdown", false, `DEPRECATED: no longer has any effect and will be removed in a later release (see github issue #1304)`)

// Feature Gates (see FEATURE_GATES.md)
flagSet.Var(cliflag.NewMapStringBool(&c.FeatureGates), "feature-gates", "A set of key=value pairs that describe feature gates for alpha/beta/experimental features. "+
fmt.Sprintf("See the Feature Gates documentation for information and available options: %s", featureGatesDocsURL))

return flagSet
}

Expand Down
52 changes: 52 additions & 0 deletions internal/manager/feature_gates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package manager

import (
"fmt"

"github.com/go-logr/logr"

"github.com/kong/kubernetes-ingress-controller/v2/internal/util"
)

// featureGatesDocsURL provides a link to the documentation for feature gates in the KIC repository
const featureGatesDocsURL = "https:/Kong/kubernetes-ingress-controller/blob/main/FEATURE_GATES.md"

// setupFeatureGates converts feature gates to controller enablement
func setupFeatureGates(setupLog logr.Logger, c *Config) error {
// if there are no configurations then bail out
if len(c.FeatureGates) < 1 {
setupLog.V(util.DebugLevel).Info("no feature gates configured")
return nil
}

// generate a map of feature gates by string names to their controller enablement
ctrlMap := getFeatureGateControllerMapping(c)

// find each feature gate option and process it
for feature, enabled := range c.FeatureGates {
setupLog.Info("found configuration option for gated feature", "feature", feature, "enabled", enabled)
ctrlEnabled, ok := ctrlMap[feature]
if !ok {
return fmt.Errorf("%s is not a valid feature, please see the documentation: %s", feature, featureGatesDocsURL)
}
*ctrlEnabled = enabled
}

return nil
}

// getFeatureGateControllerMapping provides a map[string]*bool for a given *Config where the keys
// reference pointers to the enablement value for the controller of relevant feature gates by name.
//
// NOTE: if you're adding a new feature gate, it needs to be added here.
func getFeatureGateControllerMapping(c *Config) map[string]*bool {
return map[string]*bool{
"KongPlugin": &c.KongPluginEnabled,
"KongClusterPlugin": &c.KongClusterPluginEnabled,
"KongIngress": &c.KongIngressEnabled,
"TCPIngress": &c.TCPIngressEnabled,
"UDPIngress": &c.UDPIngressEnabled,
"KongConsumer": &c.KongConsumerEnabled,
"Knative": &c.KnativeIngressEnabled,
}
}
5 changes: 5 additions & 0 deletions internal/manager/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func Run(ctx context.Context, c *Config, diagnostic util.ConfigDumpDiagnostic) e
utilruntime.Must(configurationv1beta1.AddToScheme(scheme))
utilruntime.Must(knativev1alpha1.AddToScheme(scheme))

setupLog.Info("getting enabled options and features")
if err := setupFeatureGates(setupLog, c); err != nil {
return fmt.Errorf("failed to configure feature gates: %w", err)
}

setupLog.Info("getting the kubernetes client configuration")
kubeconfig, err := c.GetKubeconfig()
if err != nil {
Expand Down

0 comments on commit b5fdfd8

Please sign in to comment.