@@ -21,6 +21,7 @@ import (
2121 "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
2222 "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render"
2323 . "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing"
24+ "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion"
2425)
2526
2627func Test_RegistryV1HelmChartProvider_Get_ReturnsBundleSourceFailures (t * testing.T ) {
@@ -51,7 +52,7 @@ func Test_RegistryV1HelmChartProvider_Get_ReturnsBundleRendererFailures(t *testi
5152
5253 b := source .FromBundle (
5354 bundle.RegistryV1 {
54- CSV : MakeCSV ( WithInstallModeSupportFor (v1alpha1 .InstallModeTypeAllNamespaces )),
55+ CSV : clusterserviceversion . Builder (). WithInstallModeSupportFor (v1alpha1 .InstallModeTypeAllNamespaces ). Build ( ),
5556 },
5657 )
5758
@@ -70,7 +71,7 @@ func Test_RegistryV1HelmChartProvider_Get_NoAPIServiceDefinitions(t *testing.T)
7071
7172 b := source .FromBundle (
7273 bundle.RegistryV1 {
73- CSV : MakeCSV ( WithOwnedAPIServiceDescriptions (v1alpha1.APIServiceDescription {})),
74+ CSV : clusterserviceversion . Builder (). WithOwnedAPIServiceDescriptions (v1alpha1.APIServiceDescription {}). Build ( ),
7475 },
7576 )
7677
@@ -85,14 +86,86 @@ func Test_RegistryV1HelmChartProvider_Get_NoAPIServiceDefinitions(t *testing.T)
8586 require .Contains (t , err .Error (), "unsupported bundle: apiServiceDefintions are not supported" )
8687}
8788
89+ func Test_RegistryV1HelmChartProvider_Get_SingleOwnNamespace (t * testing.T ) {
90+ t .Run ("rejects bundles without AllNamespaces install mode support if SingleOwnNamespace is not enabled" , func (t * testing.T ) {
91+ provider := applier.RegistryV1HelmChartProvider {}
92+
93+ b := source .FromBundle (
94+ bundle.RegistryV1 {
95+ CSV : clusterserviceversion .Builder ().WithInstallModeSupportFor (v1alpha1 .InstallModeTypeOwnNamespace ).Build (),
96+ },
97+ )
98+
99+ ext := & ocv1.ClusterExtension {
100+ Spec : ocv1.ClusterExtensionSpec {
101+ Namespace : "install-namespace" ,
102+ },
103+ }
104+
105+ _ , err := provider .Get (b , ext )
106+ require .Error (t , err )
107+ require .Contains (t , err .Error (), "unsupported bundle: bundle does not support AllNamespaces install mode" )
108+ })
109+ t .Run ("accepts bundles with SingleNamespace install mode support if SingleOwnNamespace is enabled" , func (t * testing.T ) {
110+ // TODO: this will be removed in a follow-up PR that will refactor GetWatchNamespace's location
111+ featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .SingleOwnNamespaceInstallSupport , true )
112+ provider := applier.RegistryV1HelmChartProvider {
113+ IsSingleOwnNamespaceEnabled : true ,
114+ }
115+
116+ b := source .FromBundle (
117+ bundle.RegistryV1 {
118+ CSV : clusterserviceversion .Builder ().WithInstallModeSupportFor (v1alpha1 .InstallModeTypeSingleNamespace ).Build (),
119+ },
120+ )
121+
122+ ext := & ocv1.ClusterExtension {
123+ Spec : ocv1.ClusterExtensionSpec {
124+ Namespace : "install-namespace" ,
125+ Config : & ocv1.ClusterExtensionConfig {
126+ ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
127+ Inline : & apiextensionsv1.JSON {
128+ Raw : []byte (`{"watchNamespace": "some-namespace"}` ),
129+ },
130+ },
131+ },
132+ }
133+
134+ _ , err := provider .Get (b , ext )
135+ require .NoError (t , err )
136+ })
137+ t .Run ("accepts bundles with OwnNamespace install mode support if SingleOwnNamespace is enabled" , func (t * testing.T ) {
138+ // TODO: this will be removed in a follow-up PR that will refactor GetWatchNamespace's location
139+ featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .SingleOwnNamespaceInstallSupport , true )
140+ provider := applier.RegistryV1HelmChartProvider {
141+ IsSingleOwnNamespaceEnabled : true ,
142+ }
143+
144+ b := source .FromBundle (
145+ bundle.RegistryV1 {
146+ CSV : clusterserviceversion .Builder ().WithInstallModeSupportFor (v1alpha1 .InstallModeTypeOwnNamespace ).Build (),
147+ },
148+ )
149+
150+ ext := & ocv1.ClusterExtension {
151+ Spec : ocv1.ClusterExtensionSpec {
152+ Namespace : "install-namespace" ,
153+ },
154+ }
155+
156+ _ , err := provider .Get (b , ext )
157+ require .NoError (t , err )
158+ })
159+ }
160+
88161func Test_RegistryV1HelmChartProvider_Get_NoWebhooksWithoutCertProvider (t * testing.T ) {
89162 provider := applier.RegistryV1HelmChartProvider {
90163 IsWebhookSupportEnabled : true ,
91164 }
92165
93166 b := source .FromBundle (
94167 bundle.RegistryV1 {
95- CSV : MakeCSV ( WithWebhookDefinitions (v1alpha1.WebhookDescription {})),
168+ CSV : clusterserviceversion . Builder (). WithWebhookDefinitions (v1alpha1.WebhookDescription {}). Build ( ),
96169 },
97170 )
98171
@@ -114,7 +187,7 @@ func Test_RegistryV1HelmChartProvider_Get_WebhooksSupportDisabled(t *testing.T)
114187
115188 b := source .FromBundle (
116189 bundle.RegistryV1 {
117- CSV : MakeCSV ( WithWebhookDefinitions (v1alpha1.WebhookDescription {})),
190+ CSV : clusterserviceversion . Builder (). WithWebhookDefinitions (v1alpha1.WebhookDescription {}). Build ( ),
118191 },
119192 )
120193
@@ -137,10 +210,9 @@ func Test_RegistryV1HelmChartProvider_Get_WebhooksWithCertProvider(t *testing.T)
137210
138211 b := source .FromBundle (
139212 bundle.RegistryV1 {
140- CSV : MakeCSV (
141- WithInstallModeSupportFor (v1alpha1 .InstallModeTypeAllNamespaces ),
142- WithWebhookDefinitions (v1alpha1.WebhookDescription {}),
143- ),
213+ CSV : clusterserviceversion .Builder ().
214+ WithInstallModeSupportFor (v1alpha1 .InstallModeTypeAllNamespaces ).
215+ WithWebhookDefinitions (v1alpha1.WebhookDescription {}).Build (),
144216 },
145217 )
146218
@@ -173,7 +245,7 @@ func Test_RegistryV1HelmChartProvider_Get_BundleRendererIntegration(t *testing.T
173245
174246 b := source .FromBundle (
175247 bundle.RegistryV1 {
176- CSV : MakeCSV ( WithInstallModeSupportFor (v1alpha1 .InstallModeTypeAllNamespaces , v1alpha1 .InstallModeTypeSingleNamespace )),
248+ CSV : clusterserviceversion . Builder (). WithInstallModeSupportFor (v1alpha1 .InstallModeTypeAllNamespaces , v1alpha1 .InstallModeTypeSingleNamespace ). Build ( ),
177249 },
178250 )
179251
@@ -243,10 +315,9 @@ func Test_RegistryV1HelmChartProvider_Get_Success(t *testing.T) {
243315
244316 b := source .FromBundle (
245317 bundle.RegistryV1 {
246- CSV : MakeCSV (
247- WithAnnotations (map [string ]string {"foo" : "bar" }),
248- WithInstallModeSupportFor (v1alpha1 .InstallModeTypeAllNamespaces ),
249- ),
318+ CSV : clusterserviceversion .Builder ().
319+ WithAnnotations (map [string ]string {"foo" : "bar" }).
320+ WithInstallModeSupportFor (v1alpha1 .InstallModeTypeAllNamespaces ).Build (),
250321 Others : []unstructured.Unstructured {
251322 * ToUnstructuredT (t , & corev1.Service {
252323 TypeMeta : metav1.TypeMeta {
0 commit comments