@@ -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