Skip to content

Commit de21b0e

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

2 files changed

Lines changed: 30 additions & 17 deletions

File tree

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)