Skip to content

Commit 9bb4d95

Browse files
Merge pull request #144 from tmshort/disable-feature-gates
OPRUN-4207: Update feature-gate processing to support disabled features
2 parents 4e312dc + 0380780 commit 9bb4d95

File tree

8 files changed

+1866
-190
lines changed

8 files changed

+1866
-190
lines changed

internal/featuregates/mapper.go

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package featuregates
22

33
import (
44
"errors"
5-
"sort"
65
"strings"
76

87
configv1 "github.com/openshift/api/config/v1"
98
"github.com/openshift/api/features"
9+
10+
"github.com/openshift/cluster-olm-operator/pkg/helmvalues"
1011
)
1112

1213
// Add your new upstream feature gate here
@@ -19,36 +20,60 @@ const (
1920
// SingleOwnNamespaceInstallSupport: Enables support for Single- and OwnNamespace install modes.
2021
SingleOwnNamespaceInstallSupport = "SingleOwnNamespaceInstallSupport"
2122
// WebhookProviderOpenshiftServiceCA: Enables support for the installation of bundles containing webhooks using the openshift-serviceca tls certificate provider
23+
// WebhookProviderCertManager: This is something that always needs to be disabled downstream
2224
WebhookProviderOpenshiftServiceCA = "WebhookProviderOpenshiftServiceCA"
25+
WebhookProviderCertManager = "WebhookProviderCertManager"
2326
)
2427

2528
type MapperInterface interface {
26-
OperatorControllerUpstreamForDownstream(downstreamGate configv1.FeatureGateName) []string
27-
OperatorControllerDownstreamFeatureGates() []configv1.FeatureGateName
28-
CatalogdUpstreamForDownstream(downstreamGate configv1.FeatureGateName) []string
29-
CatalogdDownstreamFeatureGates() []configv1.FeatureGateName
29+
UpstreamForDownstream(downstreamGate configv1.FeatureGateName) func(*helmvalues.HelmValues, bool) error
30+
DownstreamFeatureGates() []configv1.FeatureGateName
3031
}
3132

3233
// Mapper knows the mapping between downstream and upstream feature gates for both OLM components
34+
35+
type gateMapFunc map[configv1.FeatureGateName]func(*helmvalues.HelmValues, bool) error
36+
3337
type Mapper struct {
34-
operatorControllerGates map[configv1.FeatureGateName][]string
35-
catalogdGates map[configv1.FeatureGateName][]string
38+
featureGates gateMapFunc
3639
}
3740

3841
func NewMapper() *Mapper {
3942
// Add your downstream to upstream mapping here
40-
operatorControllerGates := map[configv1.FeatureGateName][]string{
41-
// features.FeatureGateNewOLMMyDownstreamFeature: {MyUpstreamControllerOperatorFeature}
42-
features.FeatureGateNewOLMPreflightPermissionChecks: {PreflightPermissions},
43-
features.FeatureGateNewOLMOwnSingleNamespace: {SingleOwnNamespaceInstallSupport},
44-
features.FeatureGateNewOLMWebhookProviderOpenshiftServiceCA: {WebhookProviderOpenshiftServiceCA},
45-
}
46-
catalogdGates := map[configv1.FeatureGateName][]string{
47-
// features.FeatureGateNewOLMMyDownstreamFeature: {MyUpstreamCatalogdFeature}
48-
features.FeatureGateNewOLMCatalogdAPIV1Metas: {APIV1MetasHandler},
43+
44+
featureGates := gateMapFunc{
45+
// features.FeatureGateNewOLMMyDownstreamFeature: functon that returns a list of enabled and disabled gates
46+
features.FeatureGateNewOLMPreflightPermissionChecks: func(v *helmvalues.HelmValues, enabled bool) error {
47+
if enabled {
48+
return v.AddListValue(helmvalues.EnableOperatorController, PreflightPermissions)
49+
}
50+
return v.AddListValue(helmvalues.DisableOperatorController, PreflightPermissions)
51+
},
52+
features.FeatureGateNewOLMOwnSingleNamespace: func(v *helmvalues.HelmValues, enabled bool) error {
53+
if enabled {
54+
return v.AddListValue(helmvalues.EnableOperatorController, SingleOwnNamespaceInstallSupport)
55+
}
56+
return v.AddListValue(helmvalues.DisableOperatorController, SingleOwnNamespaceInstallSupport)
57+
},
58+
features.FeatureGateNewOLMWebhookProviderOpenshiftServiceCA: func(v *helmvalues.HelmValues, enabled bool) error {
59+
var errs []error
60+
if enabled {
61+
errs = append(errs, v.AddListValue(helmvalues.EnableOperatorController, WebhookProviderOpenshiftServiceCA))
62+
} else {
63+
errs = append(errs, v.AddListValue(helmvalues.DisableOperatorController, WebhookProviderOpenshiftServiceCA))
64+
}
65+
errs = append(errs, v.AddListValue(helmvalues.DisableOperatorController, WebhookProviderCertManager))
66+
return errors.Join(errs...)
67+
},
68+
features.FeatureGateNewOLMCatalogdAPIV1Metas: func(v *helmvalues.HelmValues, enabled bool) error {
69+
if enabled {
70+
return v.AddListValue(helmvalues.EnableCatalogd, APIV1MetasHandler)
71+
}
72+
return v.AddListValue(helmvalues.DisableCatalogd, APIV1MetasHandler)
73+
},
4974
}
5075

51-
for _, m := range []map[configv1.FeatureGateName][]string{operatorControllerGates, catalogdGates} {
76+
for _, m := range []gateMapFunc{featureGates} {
5277
for downstreamGate := range m {
5378
// features.FeatureGateNewOLM is a GA-enabled downstream feature gate.
5479
// If there is a need to enable upstream alpha/beta features in the downstream GA release
@@ -63,48 +88,21 @@ func NewMapper() *Mapper {
6388
}
6489
}
6590

66-
return &Mapper{operatorControllerGates: operatorControllerGates, catalogdGates: catalogdGates}
67-
}
68-
69-
// OperatorControllerDownstreamFeatureGates returns a list of all downstream feature gates
70-
// which have an upstream mapping configured for the operator-controller component
71-
func (m *Mapper) OperatorControllerDownstreamFeatureGates() []configv1.FeatureGateName {
72-
return getKeys(m.operatorControllerGates)
91+
return &Mapper{featureGates: featureGates}
7392
}
7493

75-
// CatalogdDownstreamFeatureGates returns a list of all downstream feature gates
76-
// which have an upstream mapping configured for the catalogd component
77-
func (m *Mapper) CatalogdDownstreamFeatureGates() []configv1.FeatureGateName {
78-
return getKeys(m.catalogdGates)
79-
}
80-
81-
// OperatorControllerUpstreamForDownstream returns upstream feature gates which are configured
82-
// for a given downstream feature gate for the operator-controller component
83-
func (m *Mapper) OperatorControllerUpstreamForDownstream(downstreamGate configv1.FeatureGateName) []string {
84-
return m.operatorControllerGates[downstreamGate]
85-
}
86-
87-
// CatalogdUpstreamForDownstream returns upstream feature gates which are configured
88-
// for a given downstream feature gate for the catalogd component
89-
func (m *Mapper) CatalogdUpstreamForDownstream(downstreamGate configv1.FeatureGateName) []string {
90-
return m.catalogdGates[downstreamGate]
91-
}
92-
93-
// FormatAsEnabledArgs combines list of feature gate names into
94-
// an all-enabled arg format of <feature_gate_name1>=true,<feature_gate_name1>=true etc.
95-
func FormatAsEnabledArgs(enabledFeatureGates []string) string {
96-
args := make([]string, 0, len(enabledFeatureGates))
97-
sort.Strings(enabledFeatureGates)
98-
for _, gateName := range enabledFeatureGates {
99-
args = append(args, gateName+"=true")
100-
}
101-
return strings.Join(args, ",")
102-
}
103-
104-
func getKeys(m map[configv1.FeatureGateName][]string) []configv1.FeatureGateName {
105-
keys := make([]configv1.FeatureGateName, 0, len(m))
106-
for k := range m {
94+
// DownstreamFeatureGates returns a list of all downstream feature gates
95+
// which have an upstream mapping configured
96+
func (m *Mapper) DownstreamFeatureGates() []configv1.FeatureGateName {
97+
keys := make([]configv1.FeatureGateName, 0, len(m.featureGates))
98+
for k := range m.featureGates {
10799
keys = append(keys, k)
108100
}
109101
return keys
110102
}
103+
104+
// UpstreamForDownstream returns upstream feature gates which are configured
105+
// for a given downstream feature gate
106+
func (m *Mapper) UpstreamForDownstream(downstreamGate configv1.FeatureGateName) func(*helmvalues.HelmValues, bool) error {
107+
return m.featureGates[downstreamGate]
108+
}

0 commit comments

Comments
 (0)