-
Notifications
You must be signed in to change notification settings - Fork 593
/
feature_gates.go
63 lines (51 loc) · 2.27 KB
/
feature_gates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package manager
import (
"fmt"
"github.com/go-logr/logr"
)
// -----------------------------------------------------------------------------
// Feature Gates - Vars & Consts
// -----------------------------------------------------------------------------
const (
// knativeFeature is the name of the feature-gate for enabling/disabling Knative.
knativeFeature = "Knative"
// gatewayFeature is the name of the feature-gate for enabling/disabling Gateway APIs.
gatewayFeature = "Gateway"
// gatewayAlphaFeature is the name of the feature-gate for enabling or
// disabling the Alpha maturity APIs and relevant features for Gateway API.
gatewayAlphaFeature = "GatewayAlpha"
// combinedRoutesFeature is the name of the feature-gate for the newer object
// translation logic that will combine routes for kong services when translating
// objects like Ingress instead of creating a route per path.
combinedRoutesFeature = "CombinedRoutes"
// featureGatesDocsURL provides a link to the documentation for feature gates in the KIC repository.
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()
// 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() map[string]bool {
return map[string]bool{
knativeFeature: false,
gatewayFeature: true,
gatewayAlphaFeature: false,
combinedRoutesFeature: true,
}
}