-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add feature gates to the controller manager
- Loading branch information
Showing
4 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
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, | ||
} | ||
} |
This file contains 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