Skip to content

Commit c56a811

Browse files
authored
(rukpak) Add config support for reg+v1 bundle to chart converter (#2166)
Put watch namespace in config.
1 parent 182a0a6 commit c56a811

File tree

5 files changed

+64
-25
lines changed

5 files changed

+64
-25
lines changed

internal/operator-controller/applier/helm.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
ocv1 "github.com/operator-framework/operator-controller/api/v1"
2828
"github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
2929
"github.com/operator-framework/operator-controller/internal/operator-controller/features"
30+
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle"
3031
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
3132
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/preflights/crdupgradesafety"
3233
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util"
@@ -57,7 +58,7 @@ type Preflight interface {
5758
}
5859

5960
type BundleToHelmChartConverter interface {
60-
ToHelmChart(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error)
61+
ToHelmChart(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error)
6162
}
6263

6364
type Helm struct {
@@ -222,7 +223,10 @@ func (h *Helm) buildHelmChart(bundleFS fs.FS, ext *ocv1.ClusterExtension) (*char
222223
}
223224
}
224225

225-
return h.BundleToHelmChartConverter.ToHelmChart(source.FromFS(bundleFS), ext.Spec.Namespace, watchNamespace)
226+
bundleConfig := map[string]interface{}{
227+
bundle.BundleConfigWatchNamespaceKey: watchNamespace,
228+
}
229+
return h.BundleToHelmChartConverter.ToHelmChart(source.FromFS(bundleFS), ext.Spec.Namespace, bundleConfig)
226230
}
227231

228232
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: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/operator-framework/operator-controller/internal/operator-controller/applier"
2929
"github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
3030
"github.com/operator-framework/operator-controller/internal/operator-controller/features"
31+
registryv1Bundle "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle"
3132
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
3233
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
3334
)
@@ -559,8 +560,8 @@ func TestApply_InstallationWithSingleOwnNamespaceInstallSupportEnabled(t *testin
559560
},
560561
},
561562
BundleToHelmChartConverter: &fakeBundleToHelmChartConverter{
562-
fn: func(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
563-
require.Equal(t, expectedWatchNamespace, watchNamespace)
563+
fn: func(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
564+
require.Equal(t, expectedWatchNamespace, config[registryv1Bundle.BundleConfigWatchNamespaceKey])
564565
return nil, nil
565566
},
566567
},
@@ -574,7 +575,7 @@ func TestApply_InstallationWithSingleOwnNamespaceInstallSupportEnabled(t *testin
574575
Config: &ocv1.ClusterExtensionConfig{
575576
ConfigType: ocv1.ClusterExtensionConfigTypeInline,
576577
Inline: &apiextensionsv1.JSON{
577-
Raw: []byte(fmt.Sprintf(`{"watchNamespace":"%s"}`, expectedWatchNamespace)),
578+
Raw: []byte(fmt.Sprintf(`{"%s":"%s"}`, registryv1Bundle.BundleConfigWatchNamespaceKey, expectedWatchNamespace)),
578579
},
579580
},
580581
},
@@ -597,8 +598,8 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
597598
},
598599
},
599600
BundleToHelmChartConverter: &fakeBundleToHelmChartConverter{
600-
fn: func(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
601-
require.Equal(t, expectedWatchNamespace, watchNamespace)
601+
fn: func(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
602+
require.Equal(t, expectedWatchNamespace, config[registryv1Bundle.BundleConfigWatchNamespaceKey])
602603
return nil, nil
603604
},
604605
},
@@ -617,7 +618,7 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
617618
},
618619
},
619620
BundleToHelmChartConverter: &fakeBundleToHelmChartConverter{
620-
fn: func(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
621+
fn: func(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
621622
return nil, errors.New("some error")
622623
},
623624
},
@@ -629,9 +630,9 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
629630
}
630631

631632
type fakeBundleToHelmChartConverter struct {
632-
fn func(source.BundleSource, string, string) (*chart.Chart, error)
633+
fn func(source.BundleSource, string, map[string]interface{}) (*chart.Chart, error)
633634
}
634635

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

internal/operator-controller/rukpak/bundle/registryv1.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import (
77
"github.com/operator-framework/api/pkg/operators/v1alpha1"
88
)
99

10+
const (
11+
BundleConfigWatchNamespaceKey = "watchNamespace"
12+
)
13+
1014
type RegistryV1 struct {
1115
PackageName string
1216
CSV v1alpha1.ClusterServiceVersion

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"helm.sh/helm/v3/pkg/chart"
99

10+
bundlepkg "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle"
1011
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
1112
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render"
1213
)
@@ -17,12 +18,21 @@ type BundleToHelmChartConverter struct {
1718
IsWebhookSupportEnabled bool
1819
}
1920

20-
func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
21+
func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
2122
rv1, err := bundle.GetBundle()
2223
if err != nil {
2324
return nil, err
2425
}
2526

27+
opts := []render.Option{
28+
render.WithCertificateProvider(r.CertificateProvider),
29+
}
30+
if config != nil {
31+
if watchNs, ok := config[bundlepkg.BundleConfigWatchNamespaceKey].(string); ok {
32+
opts = append(opts, render.WithTargetNamespaces(watchNs))
33+
}
34+
}
35+
2636
if len(rv1.CSV.Spec.APIServiceDefinitions.Owned) > 0 {
2737
return nil, fmt.Errorf("unsupported bundle: apiServiceDefintions are not supported")
2838
}
@@ -39,11 +49,7 @@ func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, ins
3949
return nil, fmt.Errorf("unsupported bundle: webhookDefinitions are not supported")
4050
}
4151

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

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

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ 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+
config := map[string]interface{}{
28+
bundle.BundleConfigWatchNamespaceKey: "watch-namespace",
29+
}
30+
_, err := converter.ToHelmChart(failingBundleSource, "install-namespace", config)
2831
require.Error(t, err)
2932
require.Contains(t, err.Error(), "some error")
3033
}
@@ -46,7 +49,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_ReturnsBundleRendererFailures(t
4649
},
4750
)
4851

49-
_, err := converter.ToHelmChart(b, "install-namespace", "")
52+
config := map[string]interface{}{
53+
bundle.BundleConfigWatchNamespaceKey: "",
54+
}
55+
_, err := converter.ToHelmChart(b, "install-namespace", config)
5056
require.Error(t, err)
5157
require.Contains(t, err.Error(), "some error")
5258
}
@@ -60,7 +66,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_NoAPIServiceDefinitions(t *test
6066
},
6167
)
6268

63-
_, err := converter.ToHelmChart(b, "install-namespace", "")
69+
config := map[string]interface{}{
70+
bundle.BundleConfigWatchNamespaceKey: "",
71+
}
72+
_, err := converter.ToHelmChart(b, "install-namespace", config)
6473
require.Error(t, err)
6574
require.Contains(t, err.Error(), "unsupported bundle: apiServiceDefintions are not supported")
6675
}
@@ -76,7 +85,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_NoWebhooksWithoutCertProvider(t
7685
},
7786
)
7887

79-
_, err := converter.ToHelmChart(b, "install-namespace", "")
88+
config := map[string]interface{}{
89+
bundle.BundleConfigWatchNamespaceKey: "",
90+
}
91+
_, err := converter.ToHelmChart(b, "install-namespace", config)
8092
require.Error(t, err)
8193
require.Contains(t, err.Error(), "webhookDefinitions are not supported")
8294
}
@@ -92,7 +104,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksSupportDisabled(t *test
92104
},
93105
)
94106

95-
_, err := converter.ToHelmChart(b, "install-namespace", "")
107+
config := map[string]interface{}{
108+
bundle.BundleConfigWatchNamespaceKey: "",
109+
}
110+
_, err := converter.ToHelmChart(b, "install-namespace", config)
96111
require.Error(t, err)
97112
require.Contains(t, err.Error(), "webhookDefinitions are not supported")
98113
}
@@ -112,7 +127,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksWithCertProvider(t *tes
112127
},
113128
)
114129

115-
_, err := converter.ToHelmChart(b, "install-namespace", "")
130+
config := map[string]interface{}{
131+
bundle.BundleConfigWatchNamespaceKey: "",
132+
}
133+
_, err := converter.ToHelmChart(b, "install-namespace", config)
116134
require.NoError(t, err)
117135
}
118136

@@ -142,7 +160,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_BundleRendererIntegration(t *te
142160
},
143161
)
144162

145-
_, err := converter.ToHelmChart(b, expectedInstallNamespace, expectedWatchNamespace)
163+
config := map[string]interface{}{
164+
bundle.BundleConfigWatchNamespaceKey: expectedWatchNamespace,
165+
}
166+
_, err := converter.ToHelmChart(b, expectedInstallNamespace, config)
146167
require.NoError(t, err)
147168
}
148169

@@ -181,7 +202,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_Success(t *testing.T) {
181202
},
182203
)
183204

184-
chart, err := converter.ToHelmChart(b, "install-namespace", "")
205+
config := map[string]interface{}{
206+
bundle.BundleConfigWatchNamespaceKey: "",
207+
}
208+
chart, err := converter.ToHelmChart(b, "install-namespace", config)
185209
require.NoError(t, err)
186210
require.NotNil(t, chart)
187211
require.NotNil(t, chart.Metadata)

0 commit comments

Comments
 (0)