Skip to content

Commit 37c2f8b

Browse files
committed
(rukpak) extend bundle renderer to accept config opts
Introduce BundleConfig that contains InstallConfig and DeploymentConfig.
1 parent d95f426 commit 37c2f8b

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

internal/operator-controller/applier/helm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type Preflight interface {
5757
}
5858

5959
type BundleToHelmChartConverter interface {
60-
ToHelmChart(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error)
60+
ToHelmChart(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error)
6161
}
6262

6363
type Helm struct {
@@ -222,7 +222,7 @@ func (h *Helm) buildHelmChart(bundleFS fs.FS, ext *ocv1.ClusterExtension) (*char
222222
}
223223
}
224224

225-
return h.BundleToHelmChartConverter.ToHelmChart(source.FromFS(bundleFS), ext.Spec.Namespace, watchNamespace)
225+
return h.BundleToHelmChartConverter.ToHelmChart(source.FromFS(bundleFS), ext.Spec.Namespace, map[string]interface{}{"watchNamespace": watchNamespace})
226226
}
227227

228228
func (h *Helm) renderClientOnlyRelease(ctx context.Context, ext *ocv1.ClusterExtension, chrt *chart.Chart, values chartutil.Values, post postrender.PostRenderer) (*release.Release, error) {

internal/operator-controller/applier/helm_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ func TestApply_InstallationWithSingleOwnNamespaceInstallSupportEnabled(t *testin
559559
},
560560
},
561561
BundleToHelmChartConverter: &fakeBundleToHelmChartConverter{
562-
fn: func(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
563-
require.Equal(t, expectedWatchNamespace, watchNamespace)
562+
fn: func(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
563+
require.Equal(t, expectedWatchNamespace, config["watchNamespace"])
564564
return nil, nil
565565
},
566566
},
@@ -597,8 +597,8 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
597597
},
598598
},
599599
BundleToHelmChartConverter: &fakeBundleToHelmChartConverter{
600-
fn: func(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
601-
require.Equal(t, expectedWatchNamespace, watchNamespace)
600+
fn: func(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
601+
require.Equal(t, expectedWatchNamespace, config["watchNamespace"])
602602
return nil, nil
603603
},
604604
},
@@ -617,7 +617,7 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
617617
},
618618
},
619619
BundleToHelmChartConverter: &fakeBundleToHelmChartConverter{
620-
fn: func(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
620+
fn: func(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
621621
return nil, errors.New("some error")
622622
},
623623
},
@@ -629,9 +629,9 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
629629
}
630630

631631
type fakeBundleToHelmChartConverter struct {
632-
fn func(source.BundleSource, string, string) (*chart.Chart, error)
632+
fn func(source.BundleSource, string, map[string]interface{}) (*chart.Chart, error)
633633
}
634634

635-
func (f fakeBundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
636-
return f.fn(bundle, installNamespace, watchNamespace)
635+
func (f fakeBundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
636+
return f.fn(bundle, installNamespace, config)
637637
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@ type BundleToHelmChartConverter struct {
1717
IsWebhookSupportEnabled bool
1818
}
1919

20-
func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
20+
func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
2121
rv1, err := bundle.GetBundle()
2222
if err != nil {
2323
return nil, err
2424
}
2525

26+
var opts []render.Option
27+
28+
opts = append(opts, render.WithCertificateProvider(r.CertificateProvider))
29+
30+
if watchNs, exists := config["watchNamespace"]; exists {
31+
opts = append(opts, render.WithTargetNamespaces(watchNs.([]string)...))
32+
}
33+
2634
if len(rv1.CSV.Spec.APIServiceDefinitions.Owned) > 0 {
2735
return nil, fmt.Errorf("unsupported bundle: apiServiceDefintions are not supported")
2836
}
@@ -39,11 +47,7 @@ func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, ins
3947
return nil, fmt.Errorf("unsupported bundle: webhookDefinitions are not supported")
4048
}
4149

42-
objs, err := r.BundleRenderer.Render(
43-
rv1, installNamespace,
44-
render.WithTargetNamespaces(watchNamespace),
45-
render.WithCertificateProvider(r.CertificateProvider),
46-
)
50+
objs, err := r.BundleRenderer.Render(rv1, installNamespace, opts...)
4751

4852
if err != nil {
4953
return nil, fmt.Errorf("error rendering bundle: %w", err)

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Test_BundleToHelmChartConverter_ToHelmChart_ReturnsBundleSourceFailures(t *
2424
var failingBundleSource FakeBundleSource = func() (bundle.RegistryV1, error) {
2525
return bundle.RegistryV1{}, errors.New("some error")
2626
}
27-
_, err := converter.ToHelmChart(failingBundleSource, "install-namespace", "watch-namespace")
27+
_, err := converter.ToHelmChart(failingBundleSource, "install-namespace", map[string]interface{}{"watchNamespace": "watch-namespace"})
2828
require.Error(t, err)
2929
require.Contains(t, err.Error(), "some error")
3030
}
@@ -46,7 +46,7 @@ func Test_BundleToHelmChartConverter_ToHelmChart_ReturnsBundleRendererFailures(t
4646
},
4747
)
4848

49-
_, err := converter.ToHelmChart(b, "install-namespace", "")
49+
_, err := converter.ToHelmChart(b, "install-namespace", map[string]interface{}{"watchNamespace": ""})
5050
require.Error(t, err)
5151
require.Contains(t, err.Error(), "some error")
5252
}
@@ -56,11 +56,14 @@ func Test_BundleToHelmChartConverter_ToHelmChart_NoAPIServiceDefinitions(t *test
5656

5757
b := source.FromBundle(
5858
bundle.RegistryV1{
59-
CSV: MakeCSV(WithOwnedAPIServiceDescriptions(v1alpha1.APIServiceDescription{})),
59+
CSV: MakeCSV(
60+
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces),
61+
WithOwnedAPIServiceDescriptions(v1alpha1.APIServiceDescription{}),
62+
),
6063
},
6164
)
6265

63-
_, err := converter.ToHelmChart(b, "install-namespace", "")
66+
_, err := converter.ToHelmChart(b, "install-namespace", map[string]interface{}{"watchNamespace": ""})
6467
require.Error(t, err)
6568
require.Contains(t, err.Error(), "unsupported bundle: apiServiceDefintions are not supported")
6669
}
@@ -72,11 +75,14 @@ func Test_BundleToHelmChartConverter_ToHelmChart_NoWebhooksWithoutCertProvider(t
7275

7376
b := source.FromBundle(
7477
bundle.RegistryV1{
75-
CSV: MakeCSV(WithWebhookDefinitions(v1alpha1.WebhookDescription{})),
78+
CSV: MakeCSV(
79+
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces),
80+
WithWebhookDefinitions(v1alpha1.WebhookDescription{}),
81+
),
7682
},
7783
)
7884

79-
_, err := converter.ToHelmChart(b, "install-namespace", "")
85+
_, err := converter.ToHelmChart(b, "install-namespace", map[string]interface{}{"watchNamespace": ""})
8086
require.Error(t, err)
8187
require.Contains(t, err.Error(), "webhookDefinitions are not supported")
8288
}
@@ -88,11 +94,14 @@ func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksSupportDisabled(t *test
8894

8995
b := source.FromBundle(
9096
bundle.RegistryV1{
91-
CSV: MakeCSV(WithWebhookDefinitions(v1alpha1.WebhookDescription{})),
97+
CSV: MakeCSV(
98+
WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces),
99+
WithWebhookDefinitions(v1alpha1.WebhookDescription{}),
100+
),
92101
},
93102
)
94103

95-
_, err := converter.ToHelmChart(b, "install-namespace", "")
104+
_, err := converter.ToHelmChart(b, "install-namespace", map[string]interface{}{"watchNamespace": ""})
96105
require.Error(t, err)
97106
require.Contains(t, err.Error(), "webhookDefinitions are not supported")
98107
}
@@ -112,7 +121,7 @@ func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksWithCertProvider(t *tes
112121
},
113122
)
114123

115-
_, err := converter.ToHelmChart(b, "install-namespace", "")
124+
_, err := converter.ToHelmChart(b, "install-namespace", map[string]interface{}{"watchNamespace": ""})
116125
require.NoError(t, err)
117126
}
118127

@@ -142,7 +151,7 @@ func Test_BundleToHelmChartConverter_ToHelmChart_BundleRendererIntegration(t *te
142151
},
143152
)
144153

145-
_, err := converter.ToHelmChart(b, expectedInstallNamespace, expectedWatchNamespace)
154+
_, err := converter.ToHelmChart(b, expectedInstallNamespace, map[string]interface{}{"watchNamespace": expectedWatchNamespace})
146155
require.NoError(t, err)
147156
}
148157

@@ -181,7 +190,7 @@ func Test_BundleToHelmChartConverter_ToHelmChart_Success(t *testing.T) {
181190
},
182191
)
183192

184-
chart, err := converter.ToHelmChart(b, "install-namespace", "")
193+
chart, err := converter.ToHelmChart(b, "install-namespace", map[string]interface{}{"watchNamespace": ""})
185194
require.NoError(t, err)
186195
require.NotNil(t, chart)
187196
require.NotNil(t, chart.Metadata)

0 commit comments

Comments
 (0)