Skip to content

Commit f721a07

Browse files
author
Per Goncalves da Silva
committed
Address reviewer comments
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent 191bf91 commit f721a07

File tree

5 files changed

+75
-42
lines changed

5 files changed

+75
-42
lines changed

internal/operator-controller/applier/boxcutter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ func latestRevisionNumber(prevRevisions []ocv1.ClusterExtensionRevision) int64 {
372372
type BundleRenderer interface {
373373
Render(bundleFS fs.FS, ext *ocv1.ClusterExtension) ([]client.Object, error)
374374
}
375+
375376
type RegistryV1BundleRenderer struct {
376377
BundleRenderer render.BundleRenderer
377378
CertificateProvider render.CertificateProvider

internal/operator-controller/applier/helm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636

3737
// HelmChartProvider provides helm charts from bundle sources and cluster extensions
3838
type HelmChartProvider interface {
39-
HelmChart(bundle source.BundleSource, clusterExtension *ocv1.ClusterExtension) (*chart.Chart, error)
39+
Get(bundle source.BundleSource, clusterExtension *ocv1.ClusterExtension) (*chart.Chart, error)
4040
}
4141

4242
type HelmReleaseToObjectsConverter struct {
@@ -212,7 +212,7 @@ func (h *Helm) buildHelmChart(bundleFS fs.FS, ext *ocv1.ClusterExtension) (*char
212212
)
213213
}
214214
}
215-
return h.HelmChartProvider.HelmChart(source.FromFS(bundleFS), ext)
215+
return h.HelmChartProvider.Get(source.FromFS(bundleFS), ext)
216216
}
217217

218218
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,6 @@ type fakeRegistryV1HelmChartProvider struct {
649649
fn func(source.BundleSource, *ocv1.ClusterExtension) (*chart.Chart, error)
650650
}
651651

652-
func (f fakeRegistryV1HelmChartProvider) HelmChart(bundle source.BundleSource, ext *ocv1.ClusterExtension) (*chart.Chart, error) {
652+
func (f fakeRegistryV1HelmChartProvider) Get(bundle source.BundleSource, ext *ocv1.ClusterExtension) (*chart.Chart, error) {
653653
return f.fn(bundle, ext)
654654
}

internal/operator-controller/applier/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type RegistryV1HelmChartProvider struct {
1818
IsWebhookSupportEnabled bool
1919
}
2020

21-
func (r *RegistryV1HelmChartProvider) HelmChart(bundle source.BundleSource, ext *ocv1.ClusterExtension) (*chart.Chart, error) {
21+
func (r *RegistryV1HelmChartProvider) Get(bundle source.BundleSource, ext *ocv1.ClusterExtension) (*chart.Chart, error) {
2222
rv1, err := bundle.GetBundle()
2323
if err != nil {
2424
return nil, err

internal/operator-controller/applier/provider_test.go

Lines changed: 70 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ import (
99
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
12+
featuregatetesting "k8s.io/component-base/featuregate/testing"
1213
"sigs.k8s.io/controller-runtime/pkg/client"
1314

1415
"github.com/operator-framework/api/pkg/operators/v1alpha1"
1516

1617
ocv1 "github.com/operator-framework/operator-controller/api/v1"
1718
"github.com/operator-framework/operator-controller/internal/operator-controller/applier"
19+
"github.com/operator-framework/operator-controller/internal/operator-controller/features"
1820
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle"
1921
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
2022
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render"
2123
. "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing"
2224
)
2325

24-
func Test_BundleToHelmChartConverter_ToHelmChart_ReturnsBundleSourceFailures(t *testing.T) {
26+
func Test_RegistryV1HelmChartProvider_Get_ReturnsBundleSourceFailures(t *testing.T) {
2527
provider := applier.RegistryV1HelmChartProvider{}
2628
var failingBundleSource FakeBundleSource = func() (bundle.RegistryV1, error) {
2729
return bundle.RegistryV1{}, errors.New("some error")
@@ -31,12 +33,12 @@ func Test_BundleToHelmChartConverter_ToHelmChart_ReturnsBundleSourceFailures(t *
3133
Namespace: "install-namespace",
3234
},
3335
}
34-
_, err := provider.HelmChart(failingBundleSource, ext)
36+
_, err := provider.Get(failingBundleSource, ext)
3537
require.Error(t, err)
3638
require.Contains(t, err.Error(), "some error")
3739
}
3840

39-
func Test_BundleToHelmChartConverter_ToHelmChart_ReturnsBundleRendererFailures(t *testing.T) {
41+
func Test_RegistryV1HelmChartProvider_Get_ReturnsBundleRendererFailures(t *testing.T) {
4042
provider := applier.RegistryV1HelmChartProvider{
4143
BundleRenderer: render.BundleRenderer{
4244
ResourceGenerators: []render.ResourceGenerator{
@@ -58,12 +60,12 @@ func Test_BundleToHelmChartConverter_ToHelmChart_ReturnsBundleRendererFailures(t
5860
Namespace: "install-namespace",
5961
},
6062
}
61-
_, err := provider.HelmChart(b, ext)
63+
_, err := provider.Get(b, ext)
6264
require.Error(t, err)
6365
require.Contains(t, err.Error(), "some error")
6466
}
6567

66-
func Test_BundleToHelmChartConverter_ToHelmChart_NoAPIServiceDefinitions(t *testing.T) {
68+
func Test_RegistryV1HelmChartProvider_Get_NoAPIServiceDefinitions(t *testing.T) {
6769
provider := applier.RegistryV1HelmChartProvider{}
6870

6971
b := source.FromBundle(
@@ -78,12 +80,12 @@ func Test_BundleToHelmChartConverter_ToHelmChart_NoAPIServiceDefinitions(t *test
7880
},
7981
}
8082

81-
_, err := provider.HelmChart(b, ext)
83+
_, err := provider.Get(b, ext)
8284
require.Error(t, err)
8385
require.Contains(t, err.Error(), "unsupported bundle: apiServiceDefintions are not supported")
8486
}
8587

86-
func Test_BundleToHelmChartConverter_ToHelmChart_NoWebhooksWithoutCertProvider(t *testing.T) {
88+
func Test_RegistryV1HelmChartProvider_Get_NoWebhooksWithoutCertProvider(t *testing.T) {
8789
provider := applier.RegistryV1HelmChartProvider{
8890
IsWebhookSupportEnabled: true,
8991
}
@@ -100,12 +102,12 @@ func Test_BundleToHelmChartConverter_ToHelmChart_NoWebhooksWithoutCertProvider(t
100102
},
101103
}
102104

103-
_, err := provider.HelmChart(b, ext)
105+
_, err := provider.Get(b, ext)
104106
require.Error(t, err)
105107
require.Contains(t, err.Error(), "webhookDefinitions are not supported")
106108
}
107109

108-
func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksSupportDisabled(t *testing.T) {
110+
func Test_RegistryV1HelmChartProvider_Get_WebhooksSupportDisabled(t *testing.T) {
109111
provider := applier.RegistryV1HelmChartProvider{
110112
IsWebhookSupportEnabled: false,
111113
}
@@ -122,12 +124,12 @@ func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksSupportDisabled(t *test
122124
},
123125
}
124126

125-
_, err := provider.HelmChart(b, ext)
127+
_, err := provider.Get(b, ext)
126128
require.Error(t, err)
127129
require.Contains(t, err.Error(), "webhookDefinitions are not supported")
128130
}
129131

130-
func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksWithCertProvider(t *testing.T) {
132+
func Test_RegistryV1HelmChartProvider_Get_WebhooksWithCertProvider(t *testing.T) {
131133
provider := applier.RegistryV1HelmChartProvider{
132134
CertificateProvider: FakeCertProvider{},
133135
IsWebhookSupportEnabled: true,
@@ -148,53 +150,83 @@ func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksWithCertProvider(t *tes
148150
},
149151
}
150152

151-
_, err := provider.HelmChart(b, ext)
153+
_, err := provider.Get(b, ext)
152154
require.NoError(t, err)
153155
}
154156

155-
func Test_BundleToHelmChartConverter_ToHelmChart_BundleRendererIntegration(t *testing.T) {
157+
func Test_RegistryV1HelmChartProvider_Get_BundleRendererIntegration(t *testing.T) {
156158
expectedInstallNamespace := "install-namespace"
157-
expectedWatchNamespace := ""
158159
expectedCertProvider := FakeCertProvider{}
160+
watchNamespace := "some-namespace"
159161

160-
provider := applier.RegistryV1HelmChartProvider{
161-
BundleRenderer: render.BundleRenderer{
162-
ResourceGenerators: []render.ResourceGenerator{
163-
func(rv1 *bundle.RegistryV1, opts render.Options) ([]client.Object, error) {
164-
// ensure correct options are being passed down to the bundle renderer
165-
require.Equal(t, expectedInstallNamespace, opts.InstallNamespace)
166-
require.Equal(t, []string{expectedWatchNamespace}, opts.TargetNamespaces)
167-
require.Equal(t, expectedCertProvider, opts.CertificateProvider)
168-
return nil, nil
162+
ext := &ocv1.ClusterExtension{
163+
Spec: ocv1.ClusterExtensionSpec{
164+
Namespace: "install-namespace",
165+
Config: &ocv1.ClusterExtensionConfig{
166+
ConfigType: ocv1.ClusterExtensionConfigTypeInline,
167+
Inline: &apiextensionsv1.JSON{
168+
Raw: []byte(`{"watchNamespace": "` + watchNamespace + `"}`),
169169
},
170170
},
171171
},
172-
CertificateProvider: expectedCertProvider,
173172
}
174173

175174
b := source.FromBundle(
176175
bundle.RegistryV1{
177-
CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)),
176+
CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace)),
178177
},
179178
)
180179

181-
ext := &ocv1.ClusterExtension{
182-
Spec: ocv1.ClusterExtensionSpec{
183-
Namespace: "install-namespace",
184-
Config: &ocv1.ClusterExtensionConfig{
185-
ConfigType: ocv1.ClusterExtensionConfigTypeInline,
186-
Inline: &apiextensionsv1.JSON{
187-
Raw: []byte(`{"watchNamespace": "` + expectedWatchNamespace + `"}`),
180+
t.Run("SingleOwnNamespace install mode support off", func(t *testing.T) {
181+
provider := applier.RegistryV1HelmChartProvider{
182+
BundleRenderer: render.BundleRenderer{
183+
ResourceGenerators: []render.ResourceGenerator{
184+
func(rv1 *bundle.RegistryV1, opts render.Options) ([]client.Object, error) {
185+
// ensure correct options are being passed down to the bundle renderer
186+
require.Equal(t, expectedInstallNamespace, opts.InstallNamespace)
187+
require.Equal(t, expectedCertProvider, opts.CertificateProvider)
188+
189+
// target namespaces should not set to {""} (AllNamespaces) if the SingleOwnNamespace feature flag is off
190+
t.Log("check that targetNamespaces option is set to AllNamespaces")
191+
require.Equal(t, []string{""}, opts.TargetNamespaces)
192+
return nil, nil
193+
},
188194
},
189195
},
190-
},
191-
}
196+
CertificateProvider: expectedCertProvider,
197+
}
198+
199+
_, err := provider.Get(b, ext)
200+
require.NoError(t, err)
201+
})
202+
203+
t.Run("feature on", func(t *testing.T) {
204+
featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.SingleOwnNamespaceInstallSupport, true)
205+
206+
provider := applier.RegistryV1HelmChartProvider{
207+
BundleRenderer: render.BundleRenderer{
208+
ResourceGenerators: []render.ResourceGenerator{
209+
func(rv1 *bundle.RegistryV1, opts render.Options) ([]client.Object, error) {
210+
// ensure correct options are being passed down to the bundle renderer
211+
require.Equal(t, expectedInstallNamespace, opts.InstallNamespace)
212+
require.Equal(t, expectedCertProvider, opts.CertificateProvider)
213+
214+
// targetNamespace must be set if the feature flag is on
215+
t.Log("check that targetNamespaces option is set")
216+
require.Equal(t, []string{watchNamespace}, opts.TargetNamespaces)
217+
return nil, nil
218+
},
219+
},
220+
},
221+
CertificateProvider: expectedCertProvider,
222+
}
192223

193-
_, err := provider.HelmChart(b, ext)
194-
require.NoError(t, err)
224+
_, err := provider.Get(b, ext)
225+
require.NoError(t, err)
226+
})
195227
}
196228

197-
func Test_BundleToHelmChartConverter_ToHelmChart_Success(t *testing.T) {
229+
func Test_RegistryV1HelmChartProvider_Get_Success(t *testing.T) {
198230
provider := applier.RegistryV1HelmChartProvider{
199231
BundleRenderer: render.BundleRenderer{
200232
ResourceGenerators: []render.ResourceGenerator{
@@ -235,7 +267,7 @@ func Test_BundleToHelmChartConverter_ToHelmChart_Success(t *testing.T) {
235267
},
236268
}
237269

238-
chart, err := provider.HelmChart(b, ext)
270+
chart, err := provider.Get(b, ext)
239271
require.NoError(t, err)
240272
require.NotNil(t, chart)
241273
require.NotNil(t, chart.Metadata)

0 commit comments

Comments
 (0)