Skip to content

Commit 99ae491

Browse files
author
Per Goncalves da Silva
committed
Add Boxcutter FG mapping
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent 050f9d2 commit 99ae491

File tree

13 files changed

+331
-83
lines changed

13 files changed

+331
-83
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/TwiN/deepmerge v0.2.2
77
github.com/blang/semver/v4 v4.0.0
88
github.com/go-logr/logr v1.4.3
9-
github.com/openshift/api v0.0.0-20251111013132-5c461e21bdb7
9+
github.com/openshift/api v0.0.0-20251118143053-b6fddd3c8174
1010
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee
1111
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235
1212
github.com/openshift/library-go v0.0.0-20251107090138-0de9712313a5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
296296
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
297297
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
298298
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
299-
github.com/openshift/api v0.0.0-20251111013132-5c461e21bdb7 h1:fdvcDJySvjVJctbPbdLPoMiMk+bls34+eq6tWOqdFZg=
300-
github.com/openshift/api v0.0.0-20251111013132-5c461e21bdb7/go.mod h1:d5uzF0YN2nQQFA0jIEWzzOZ+edmo6wzlGLvx5Fhz4uY=
299+
github.com/openshift/api v0.0.0-20251118143053-b6fddd3c8174 h1:lXwzB9GOX9LS3ZyrK5x6QBm/XF+Azfy1ZRXIeOR5olE=
300+
github.com/openshift/api v0.0.0-20251118143053-b6fddd3c8174/go.mod h1:d5uzF0YN2nQQFA0jIEWzzOZ+edmo6wzlGLvx5Fhz4uY=
301301
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee h1:+Sp5GGnjHDhT/a/nQ1xdp43UscBMr7G5wxsYotyhzJ4=
302302
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee/go.mod h1:8jcm8UPtg2mCAsxfqKil1xrmRMI3a+XU2TZ9fF8A7TE=
303303
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235 h1:9JBeIXmnHlpXTQPi7LPmu1jdxznBhAE7bb1K+3D8gxY=

internal/featuregates/mapper.go

Lines changed: 79 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,120 @@
11
package featuregates
22

33
import (
4-
"errors"
5-
"strings"
4+
"errors"
5+
"strings"
66

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"
99

10-
"github.com/openshift/cluster-olm-operator/pkg/helmvalues"
10+
"github.com/openshift/cluster-olm-operator/pkg/helmvalues"
1111
)
1212

1313
// Add your new upstream feature gate here
1414
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"
2627
)
2728

2829
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
3132
}
3233

3334
// Mapper knows the mapping between downstream and upstream feature gates for both OLM components
3435

3536
type gateMapFunc map[configv1.FeatureGateName]func(*helmvalues.HelmValues, bool) error
3637

3738
type Mapper struct {
38-
featureGates gateMapFunc
39+
featureGates gateMapFunc
3940
}
4041

4142
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...)
4647
}
4748
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)
5253
}
5354

5455
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)
5960
}
6061

6162
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}
100104
}
101105

102106
// DownstreamFeatureGates returns a list of all downstream feature gates
103107
// which have an upstream mapping configured
104108
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
110114
}
111115

112116
// UpstreamForDownstream returns upstream feature gates which are configured
113117
// for a given downstream feature gate
114118
func (m *Mapper) UpstreamForDownstream(downstreamGate configv1.FeatureGateName) func(*helmvalues.HelmValues, bool) error {
115-
return m.featureGates[downstreamGate]
119+
return m.featureGates[downstreamGate]
116120
}

internal/featuregates/mapper_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestMapper_DownstreamFeatureGates(t *testing.T) {
3434
features.FeatureGateNewOLMOwnSingleNamespace,
3535
features.FeatureGateNewOLMWebhookProviderOpenshiftServiceCA,
3636
features.FeatureGateNewOLMCatalogdAPIV1Metas,
37+
features.FeatureGateNewOLMBoxCutterRuntime,
3738
}
3839

3940
if len(gates) != len(expectedGates) {
@@ -68,6 +69,12 @@ func TestMapper_UpstreamForDownstream(t *testing.T) {
6869
enabled: false,
6970
expectFunc: true,
7071
},
72+
{
73+
name: "valid downstream gate - boxcutter runtime",
74+
downstreamGate: features.FeatureGateNewOLMBoxCutterRuntime,
75+
enabled: false,
76+
expectFunc: true,
77+
},
7178
{
7279
name: "valid downstream gate - webhook provider",
7380
downstreamGate: features.FeatureGateNewOLMWebhookProviderOpenshiftServiceCA,

0 commit comments

Comments
 (0)