-
Notifications
You must be signed in to change notification settings - Fork 590
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
8 changed files
with
130 additions
and
6 deletions.
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
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,45 @@ | ||
package manager | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-logr/logr" | ||
) | ||
|
||
// featureGatesDocsURL provides a link to the documentation for feature gates in the KIC repository | ||
const featureGatesDocsURL = "https://github.com/Kong/kubernetes-ingress-controller/blob/main/FEATURE_GATES.md" | ||
|
||
// setupFeatureGates converts feature gates to controller enablement | ||
func setupFeatureGates(setupLog logr.Logger, c *Config) (map[string]bool, error) { | ||
// generate a map of feature gates by string names to their controller enablement | ||
ctrlMap := getFeatureGatesDefaults(c) | ||
|
||
// override the default settings | ||
for feature, enabled := range c.FeatureGates { | ||
setupLog.Info("found configuration option for gated feature", "feature", feature, "enabled", enabled) | ||
_, ok := ctrlMap[feature] | ||
if !ok { | ||
return ctrlMap, fmt.Errorf("%s is not a valid feature, please see the documentation: %s", feature, featureGatesDocsURL) | ||
} | ||
ctrlMap[feature] = enabled | ||
} | ||
|
||
return ctrlMap, nil | ||
} | ||
|
||
// getFeatureGatesDefaults initializes a feature gate map given the currently | ||
// supported feature gates options and derives defaults for them based on | ||
// manager configuration options if present. | ||
// | ||
// NOTE: if you're adding a new feature gate, it needs to be added here. | ||
func getFeatureGatesDefaults(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package manager | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/bombsimon/logrusr" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFeatureGates(t *testing.T) { | ||
t.Log("setting up configurations and logging for feature gates testing") | ||
out := new(bytes.Buffer) | ||
baseLogger := logrus.New() | ||
baseLogger.SetOutput(out) | ||
baseLogger.SetLevel(logrus.DebugLevel) | ||
setupLog := logrusr.NewLogger(baseLogger) | ||
config := new(Config) | ||
|
||
t.Log("verifying feature gates setup defaults when no feature gates are configured") | ||
fgs, err := setupFeatureGates(setupLog, config) | ||
assert.NoError(t, err) | ||
assert.Len(t, fgs, len(getFeatureGatesDefaults(config))) | ||
|
||
t.Log("configuring several valid feature gates options") | ||
config.FeatureGates = map[string]bool{ | ||
"KongClusterPlugin": true, | ||
"KongIngress": true, | ||
"TCPIngress": true, | ||
"UDPIngress": true, | ||
"Knative": true, | ||
} | ||
|
||
t.Log("verifying feature gates setup results when valid feature gates options are present") | ||
fgs, err = setupFeatureGates(setupLog, config) | ||
assert.NoError(t, err) | ||
assert.False(t, fgs["KongPlugin"]) | ||
assert.True(t, fgs["KongClusterPlugin"]) | ||
assert.True(t, fgs["KongIngress"]) | ||
assert.True(t, fgs["TCPIngress"]) | ||
assert.True(t, fgs["UDPIngress"]) | ||
assert.False(t, fgs["KongConsumer"]) | ||
assert.True(t, fgs["Knative"]) | ||
|
||
t.Log("configuring several invalid feature gates options") | ||
config.FeatureGates = map[string]bool{ | ||
"KongClusterPlugin": true, | ||
"KongIngress": true, | ||
"Batman": true, | ||
"TCPIngress": true, | ||
"UDPIngress": true, | ||
"Knative": true, | ||
} | ||
|
||
t.Log("verifying feature gates setup results when invalid feature gates options are present") | ||
_, err = setupFeatureGates(setupLog, config) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "Batman is not a valid feature") | ||
} |
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