|
1 | 1 | package featuregates |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "errors" |
5 | | - "strings" |
| 4 | + "errors" |
| 5 | + "strings" |
6 | 6 |
|
7 | | - configv1 "github.com/openshift/api/config/v1" |
8 | | - "github.com/openshift/api/features" |
| 7 | + configv1 "github.com/openshift/api/config/v1" |
| 8 | + "github.com/openshift/api/features" |
9 | 9 |
|
10 | | - "github.com/openshift/cluster-olm-operator/pkg/helmvalues" |
| 10 | + "github.com/openshift/cluster-olm-operator/pkg/helmvalues" |
11 | 11 | ) |
12 | 12 |
|
13 | 13 | // Add your new upstream feature gate here |
14 | 14 | const ( |
15 | | - // ref: |
16 | | - // 1. https://github.com/operator-framework/operator-controller/pull/1643 |
17 | | - // 2. https://github.com/operator-framework/operator-controller/commit/5965d5c9ee56e9077dca39afa59047ece84ed97e#diff-bfcbe63805e38aeb1d57481bd753566c7ddf58702829e1c1ffd7698bd047de67R309 |
18 | | - APIV1MetasHandler = "APIV1MetasHandler" |
19 | | - PreflightPermissions = "PreflightPermissions" |
20 | | - // SingleOwnNamespaceInstallSupport: Enables support for Single- and OwnNamespace install modes. |
21 | | - SingleOwnNamespaceInstallSupport = "SingleOwnNamespaceInstallSupport" |
22 | | - // 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 |
24 | | - WebhookProviderOpenshiftServiceCA = "WebhookProviderOpenshiftServiceCA" |
25 | | - WebhookProviderCertManager = "WebhookProviderCertManager" |
| 15 | + // ref: |
| 16 | + // 1. https://github.com/operator-framework/operator-controller/pull/1643 |
| 17 | + // 2. https://github.com/operator-framework/operator-controller/commit/5965d5c9ee56e9077dca39afa59047ece84ed97e#diff-bfcbe63805e38aeb1d57481bd753566c7ddf58702829e1c1ffd7698bd047de67R309 |
| 18 | + APIV1MetasHandler = "APIV1MetasHandler" |
| 19 | + PreflightPermissions = "PreflightPermissions" |
| 20 | + // SingleOwnNamespaceInstallSupport: Enables support for Single- and OwnNamespace install modes. |
| 21 | + SingleOwnNamespaceInstallSupport = "SingleOwnNamespaceInstallSupport" |
| 22 | + // 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 |
| 24 | + WebhookProviderOpenshiftServiceCA = "WebhookProviderOpenshiftServiceCA" |
| 25 | + WebhookProviderCertManager = "WebhookProviderCertManager" |
| 26 | + NewOLMBoxCutterRuntime = "BoxcutterRuntime" |
26 | 27 | ) |
27 | 28 |
|
28 | 29 | type MapperInterface interface { |
29 | | - UpstreamForDownstream(downstreamGate configv1.FeatureGateName) func(*helmvalues.HelmValues, bool) error |
30 | | - DownstreamFeatureGates() []configv1.FeatureGateName |
| 30 | + UpstreamForDownstream(downstreamGate configv1.FeatureGateName) func(*helmvalues.HelmValues, bool) error |
| 31 | + DownstreamFeatureGates() []configv1.FeatureGateName |
31 | 32 | } |
32 | 33 |
|
33 | 34 | // Mapper knows the mapping between downstream and upstream feature gates for both OLM components |
34 | 35 |
|
35 | 36 | type gateMapFunc map[configv1.FeatureGateName]func(*helmvalues.HelmValues, bool) error |
36 | 37 |
|
37 | 38 | type Mapper struct { |
38 | | - featureGates gateMapFunc |
| 39 | + featureGates gateMapFunc |
39 | 40 | } |
40 | 41 |
|
41 | 42 | func enableFeature(v *helmvalues.HelmValues, addList, removeList, feature string) error { |
42 | | - var errs []error |
43 | | - errs = append(errs, v.RemoveListValue(removeList, feature)) |
44 | | - errs = append(errs, v.AddListValue(addList, feature)) |
45 | | - return errors.Join(errs...) |
| 43 | + var errs []error |
| 44 | + errs = append(errs, v.RemoveListValue(removeList, feature)) |
| 45 | + errs = append(errs, v.AddListValue(addList, feature)) |
| 46 | + return errors.Join(errs...) |
46 | 47 | } |
47 | 48 | func enableCatalogdFeature(v *helmvalues.HelmValues, enabled bool, feature string) error { |
48 | | - if enabled { |
49 | | - return enableFeature(v, helmvalues.EnableCatalogd, helmvalues.DisableCatalogd, feature) |
50 | | - } |
51 | | - return enableFeature(v, helmvalues.DisableCatalogd, helmvalues.EnableCatalogd, feature) |
| 49 | + if enabled { |
| 50 | + return enableFeature(v, helmvalues.EnableCatalogd, helmvalues.DisableCatalogd, feature) |
| 51 | + } |
| 52 | + return enableFeature(v, helmvalues.DisableCatalogd, helmvalues.EnableCatalogd, feature) |
52 | 53 | } |
53 | 54 |
|
54 | 55 | func enableOperatorControllerFeature(v *helmvalues.HelmValues, enabled bool, feature string) error { |
55 | | - if enabled { |
56 | | - return enableFeature(v, helmvalues.EnableOperatorController, helmvalues.DisableOperatorController, feature) |
57 | | - } |
58 | | - return enableFeature(v, helmvalues.DisableOperatorController, helmvalues.EnableOperatorController, feature) |
| 56 | + if enabled { |
| 57 | + return enableFeature(v, helmvalues.EnableOperatorController, helmvalues.DisableOperatorController, feature) |
| 58 | + } |
| 59 | + return enableFeature(v, helmvalues.DisableOperatorController, helmvalues.EnableOperatorController, feature) |
59 | 60 | } |
60 | 61 |
|
61 | 62 | func NewMapper() *Mapper { |
62 | | - // Add your downstream to upstream mapping here |
63 | | - |
64 | | - featureGates := gateMapFunc{ |
65 | | - // features.FeatureGateNewOLMMyDownstreamFeature: functon that returns a list of enabled and disabled gates |
66 | | - features.FeatureGateNewOLMPreflightPermissionChecks: func(v *helmvalues.HelmValues, enabled bool) error { |
67 | | - return enableOperatorControllerFeature(v, enabled, PreflightPermissions) |
68 | | - }, |
69 | | - features.FeatureGateNewOLMOwnSingleNamespace: func(v *helmvalues.HelmValues, enabled bool) error { |
70 | | - return enableOperatorControllerFeature(v, enabled, SingleOwnNamespaceInstallSupport) |
71 | | - }, |
72 | | - features.FeatureGateNewOLMWebhookProviderOpenshiftServiceCA: func(v *helmvalues.HelmValues, enabled bool) error { |
73 | | - var errs []error |
74 | | - errs = append(errs, enableOperatorControllerFeature(v, enabled, WebhookProviderOpenshiftServiceCA)) |
75 | | - // Always disable WebhookProviderCertManager |
76 | | - errs = append(errs, enableOperatorControllerFeature(v, false, WebhookProviderCertManager)) |
77 | | - return errors.Join(errs...) |
78 | | - }, |
79 | | - features.FeatureGateNewOLMCatalogdAPIV1Metas: func(v *helmvalues.HelmValues, enabled bool) error { |
80 | | - return enableCatalogdFeature(v, enabled, APIV1MetasHandler) |
81 | | - }, |
82 | | - } |
83 | | - |
84 | | - for _, m := range []gateMapFunc{featureGates} { |
85 | | - for downstreamGate := range m { |
86 | | - // features.FeatureGateNewOLM is a GA-enabled downstream feature gate. |
87 | | - // If there is a need to enable upstream alpha/beta features in the downstream GA release |
88 | | - // get approval via a merged openshift/enhancement describing the need, then carve out |
89 | | - // an exception in this failsafe code |
90 | | - if downstreamGate == features.FeatureGateNewOLM { |
91 | | - panic(errors.New("FeatureGateNewOLM used in mappings")) |
92 | | - } |
93 | | - if !strings.HasPrefix(string(downstreamGate), string(features.FeatureGateNewOLM)) { |
94 | | - panic(errors.New("all downstream feature gates must use NewOLM prefix by convention")) |
95 | | - } |
96 | | - } |
97 | | - } |
98 | | - |
99 | | - return &Mapper{featureGates: featureGates} |
| 63 | + // Add your downstream to upstream mapping here |
| 64 | + |
| 65 | + featureGates := gateMapFunc{ |
| 66 | + // features.FeatureGateNewOLMMyDownstreamFeature: functon that returns a list of enabled and disabled gates |
| 67 | + features.FeatureGateNewOLMPreflightPermissionChecks: func(v *helmvalues.HelmValues, enabled bool) error { |
| 68 | + return enableOperatorControllerFeature(v, enabled, PreflightPermissions) |
| 69 | + }, |
| 70 | + features.FeatureGateNewOLMOwnSingleNamespace: func(v *helmvalues.HelmValues, enabled bool) error { |
| 71 | + return enableOperatorControllerFeature(v, enabled, SingleOwnNamespaceInstallSupport) |
| 72 | + }, |
| 73 | + features.FeatureGateNewOLMWebhookProviderOpenshiftServiceCA: func(v *helmvalues.HelmValues, enabled bool) error { |
| 74 | + var errs []error |
| 75 | + errs = append(errs, enableOperatorControllerFeature(v, enabled, WebhookProviderOpenshiftServiceCA)) |
| 76 | + // Always disable WebhookProviderCertManager |
| 77 | + errs = append(errs, enableOperatorControllerFeature(v, false, WebhookProviderCertManager)) |
| 78 | + return errors.Join(errs...) |
| 79 | + }, |
| 80 | + features.FeatureGateNewOLMCatalogdAPIV1Metas: func(v *helmvalues.HelmValues, enabled bool) error { |
| 81 | + return enableCatalogdFeature(v, enabled, APIV1MetasHandler) |
| 82 | + }, |
| 83 | + features.FeatureGateNewOLMBoxCutterRuntime: func(v *helmvalues.HelmValues, enabled bool) error { |
| 84 | + return enableOperatorControllerFeature(v, enabled, NewOLMBoxCutterRuntime) |
| 85 | + }, |
| 86 | + } |
| 87 | + |
| 88 | + for _, m := range []gateMapFunc{featureGates} { |
| 89 | + for downstreamGate := range m { |
| 90 | + // features.FeatureGateNewOLM is a GA-enabled downstream feature gate. |
| 91 | + // If there is a need to enable upstream alpha/beta features in the downstream GA release |
| 92 | + // get approval via a merged openshift/enhancement describing the need, then carve out |
| 93 | + // an exception in this failsafe code |
| 94 | + if downstreamGate == features.FeatureGateNewOLM { |
| 95 | + panic(errors.New("FeatureGateNewOLM used in mappings")) |
| 96 | + } |
| 97 | + if !strings.HasPrefix(string(downstreamGate), string(features.FeatureGateNewOLM)) { |
| 98 | + panic(errors.New("all downstream feature gates must use NewOLM prefix by convention")) |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + return &Mapper{featureGates: featureGates} |
100 | 104 | } |
101 | 105 |
|
102 | 106 | // DownstreamFeatureGates returns a list of all downstream feature gates |
103 | 107 | // which have an upstream mapping configured |
104 | 108 | func (m *Mapper) DownstreamFeatureGates() []configv1.FeatureGateName { |
105 | | - keys := make([]configv1.FeatureGateName, 0, len(m.featureGates)) |
106 | | - for k := range m.featureGates { |
107 | | - keys = append(keys, k) |
108 | | - } |
109 | | - return keys |
| 109 | + keys := make([]configv1.FeatureGateName, 0, len(m.featureGates)) |
| 110 | + for k := range m.featureGates { |
| 111 | + keys = append(keys, k) |
| 112 | + } |
| 113 | + return keys |
110 | 114 | } |
111 | 115 |
|
112 | 116 | // UpstreamForDownstream returns upstream feature gates which are configured |
113 | 117 | // for a given downstream feature gate |
114 | 118 | func (m *Mapper) UpstreamForDownstream(downstreamGate configv1.FeatureGateName) func(*helmvalues.HelmValues, bool) error { |
115 | | - return m.featureGates[downstreamGate] |
| 119 | + return m.featureGates[downstreamGate] |
116 | 120 | } |
0 commit comments