Skip to content

Commit 3a3380a

Browse files
author
Per G. da Silva
committed
Configure bundle to helm converter based on feature flags
Signed-off-by: Per G. da Silva <[email protected]>
1 parent 0952bae commit 3a3380a

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

cmd/operator-controller/main.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ import (
6767
"github.com/operator-framework/operator-controller/internal/operator-controller/resolve"
6868
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
6969
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/preflights/crdupgradesafety"
70+
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render"
71+
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/certproviders"
7072
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/registryv1"
7173
"github.com/operator-framework/operator-controller/internal/operator-controller/scheme"
7274
fsutil "github.com/operator-framework/operator-controller/internal/shared/util/fs"
@@ -190,7 +192,7 @@ func run() error {
190192
secretParts := strings.Split(cfg.globalPullSecret, "/")
191193
if len(secretParts) != 2 {
192194
err := fmt.Errorf("incorrect number of components")
193-
setupLog.Error(err, "value of global-pull-secret should be of the format <namespace>/<name>")
195+
setupLog.Error(err, "Value of global-pull-secret should be of the format <namespace>/<name>")
194196
return err
195197
}
196198
globalPullSecretKey = &k8stypes.NamespacedName{Name: secretParts[1], Namespace: secretParts[0]}
@@ -422,12 +424,23 @@ func run() error {
422424
preAuth = authorization.NewRBACPreAuthorizer(mgr.GetClient())
423425
}
424426

427+
// determine if a certificate provider should be set in the bundle renderer and feature support for the provider
428+
// based on the feature flag
429+
var certProvider render.CertificateProvider
430+
var isWebhookSupportEnabled bool
431+
if features.OperatorControllerFeatureGate.Enabled(features.WebhookProviderCertManager) {
432+
certProvider = certproviders.CertManagerCertificateProvider{}
433+
isWebhookSupportEnabled = true
434+
}
435+
425436
// now initialize the helmApplier, assigning the potentially nil preAuth
426437
helmApplier := &applier.Helm{
427438
ActionClientGetter: acg,
428439
Preflights: preflights,
429440
BundleToHelmChartConverter: &convert.BundleToHelmChartConverter{
430-
BundleRenderer: registryv1.Renderer,
441+
BundleRenderer: registryv1.Renderer,
442+
CertificateProvider: certProvider,
443+
IsWebhookSupportEnabled: isWebhookSupportEnabled,
431444
},
432445
PreAuthorizer: preAuth,
433446
}

internal/operator-controller/rukpak/convert/helm.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212
)
1313

1414
type BundleToHelmChartConverter struct {
15-
BundleRenderer render.BundleRenderer
16-
CertificateProvider render.CertificateProvider
15+
BundleRenderer render.BundleRenderer
16+
CertificateProvider render.CertificateProvider
17+
IsWebhookSupportEnabled bool
1718
}
1819

1920
func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
@@ -26,6 +27,14 @@ func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, ins
2627
return nil, fmt.Errorf("unsupported bundle: apiServiceDefintions are not supported")
2728
}
2829

30+
if len(rv1.CSV.Spec.WebhookDefinitions) > 0 {
31+
if !r.IsWebhookSupportEnabled {
32+
return nil, fmt.Errorf("unsupported bundle: webhookDefinitions are not supported")
33+
} else if r.CertificateProvider == nil {
34+
return nil, fmt.Errorf("unsupported bundle: webhookDefinitions are not supported: certificate provider is nil")
35+
}
36+
}
37+
2938
if r.CertificateProvider == nil && len(rv1.CSV.Spec.WebhookDefinitions) > 0 {
3039
return nil, fmt.Errorf("unsupported bundle: webhookDefinitions are not supported")
3140
}

internal/operator-controller/rukpak/convert/helm_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,25 @@ func Test_BundleToHelmChartConverter_ToHelmChart_NoAPIServiceDefinitions(t *test
6666
}
6767

6868
func Test_BundleToHelmChartConverter_ToHelmChart_NoWebhooksWithoutCertProvider(t *testing.T) {
69-
converter := convert.BundleToHelmChartConverter{}
69+
converter := convert.BundleToHelmChartConverter{
70+
IsWebhookSupportEnabled: true,
71+
}
72+
73+
b := source.FromBundle(
74+
bundle.RegistryV1{
75+
CSV: MakeCSV(WithWebhookDefinitions(v1alpha1.WebhookDescription{})),
76+
},
77+
)
78+
79+
_, err := converter.ToHelmChart(b, "install-namespace", "")
80+
require.Error(t, err)
81+
require.Contains(t, err.Error(), "webhookDefinitions are not supported")
82+
}
83+
84+
func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksSupportDisabled(t *testing.T) {
85+
converter := convert.BundleToHelmChartConverter{
86+
IsWebhookSupportEnabled: false,
87+
}
7088

7189
b := source.FromBundle(
7290
bundle.RegistryV1{
@@ -76,12 +94,13 @@ func Test_BundleToHelmChartConverter_ToHelmChart_NoWebhooksWithoutCertProvider(t
7694

7795
_, err := converter.ToHelmChart(b, "install-namespace", "")
7896
require.Error(t, err)
79-
require.Contains(t, err.Error(), "unsupported bundle: webhookDefinitions are not supported")
97+
require.Contains(t, err.Error(), "webhookDefinitions are not supported")
8098
}
8199

82100
func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksWithCertProvider(t *testing.T) {
83101
converter := convert.BundleToHelmChartConverter{
84-
CertificateProvider: FakeCertProvider{},
102+
CertificateProvider: FakeCertProvider{},
103+
IsWebhookSupportEnabled: true,
85104
}
86105

87106
b := source.FromBundle(

0 commit comments

Comments
 (0)