@@ -64,6 +64,42 @@ func Test_RegistryV1ManifestProvider_Integration(t *testing.T) {
6464 require .Contains (t , err .Error (), "some error" )
6565 })
6666
67+ t .Run ("surfaces bundle config unmarshall errors" , func (t * testing.T ) {
68+ provider := applier.RegistryV1ManifestProvider {
69+ BundleRenderer : render.BundleRenderer {
70+ ResourceGenerators : []render.ResourceGenerator {
71+ func (rv1 * bundle.RegistryV1 , opts render.Options ) ([]client.Object , error ) {
72+ return nil , nil
73+ },
74+ },
75+ },
76+ // must be true for now as we only unmarshal configuration when this feature is on
77+ // once we go GA and remove IsSingleOwnNamespaceEnabled it's ok to just delete this
78+ IsSingleOwnNamespaceEnabled : true ,
79+ }
80+
81+ // The contents of the bundle are not important for this tesy, only that it be a valid bundle
82+ // to avoid errors in the deserialization process
83+ bundleFS := bundlefs .Builder ().WithPackageName ("test" ).
84+ WithCSV (clusterserviceversion .Builder ().WithInstallModeSupportFor (v1alpha1 .InstallModeTypeSingleNamespace ).Build ()).Build ()
85+
86+ ext := & ocv1.ClusterExtension {
87+ Spec : ocv1.ClusterExtensionSpec {
88+ Namespace : "install-namespace" ,
89+ Config : & ocv1.ClusterExtensionConfig {
90+ ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
91+ Inline : & apiextensionsv1.JSON {
92+ Raw : []byte (`{"watchNamespace": "install-namespace"}` ),
93+ },
94+ },
95+ },
96+ }
97+
98+ _ , err := provider .Get (bundleFS , ext )
99+ require .Error (t , err )
100+ require .Contains (t , err .Error (), "invalid bundle configuration" )
101+ })
102+
67103 t .Run ("returns rendered manifests" , func (t * testing.T ) {
68104 provider := applier.RegistryV1ManifestProvider {
69105 BundleRenderer : registryv1 .Renderer ,
@@ -188,77 +224,6 @@ func Test_RegistryV1ManifestProvider_WebhookSupport(t *testing.T) {
188224 })
189225}
190226
191- func Test_RegistryV1ManifestProvider_ConfigUnmarshalling (t * testing.T ) {
192- for _ , tc := range []struct {
193- name string
194- configBytes []byte
195- expectedErrMessage string
196- }{
197- {
198- name : "accepts json config" ,
199- configBytes : []byte (`{"watchNamespace": "some-namespace"}` ),
200- },
201- {
202- name : "accepts yaml config" ,
203- configBytes : []byte (`watchNamespace: some-namespace` ),
204- },
205- {
206- name : "rejects invalid json" ,
207- configBytes : []byte (`{"hello` ),
208- expectedErrMessage : `invalid bundle configuration: error unmarshalling registry+v1 configuration: found unexpected end of stream` ,
209- },
210- {
211- name : "rejects valid json that isn't of object type" ,
212- configBytes : []byte (`true` ),
213- expectedErrMessage : `invalid bundle configuration: error unmarshalling registry+v1 configuration: input is not a valid JSON object` ,
214- },
215- {
216- name : "rejects additional fields" ,
217- configBytes : []byte (`somekey: somevalue` ),
218- expectedErrMessage : `invalid bundle configuration: error unmarshalling registry+v1 configuration: unknown field "somekey"` ,
219- },
220- {
221- name : "rejects valid json but invalid registry+v1" ,
222- configBytes : []byte (`{"watchNamespace": {"hello": "there"}}` ),
223- expectedErrMessage : `invalid bundle configuration: error unmarshalling registry+v1 configuration: invalid value type for field "watchNamespace": expected "string" but got "object"` ,
224- },
225- } {
226- t .Run (tc .name , func (t * testing.T ) {
227- provider := applier.RegistryV1ManifestProvider {
228- BundleRenderer : render.BundleRenderer {
229- ResourceGenerators : []render.ResourceGenerator {
230- func (rv1 * bundle.RegistryV1 , opts render.Options ) ([]client.Object , error ) {
231- return nil , nil
232- },
233- },
234- },
235- IsSingleOwnNamespaceEnabled : true ,
236- }
237-
238- bundleFS := bundlefs .Builder ().WithPackageName ("test" ).
239- WithCSV (clusterserviceversion .Builder ().WithInstallModeSupportFor (v1alpha1 .InstallModeTypeSingleNamespace ).Build ()).Build ()
240-
241- _ , err := provider .Get (bundleFS , & ocv1.ClusterExtension {
242- Spec : ocv1.ClusterExtensionSpec {
243- Namespace : "install-namespace" ,
244- Config : & ocv1.ClusterExtensionConfig {
245- ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
246- Inline : & apiextensionsv1.JSON {
247- Raw : tc .configBytes ,
248- },
249- },
250- },
251- })
252- if tc .expectedErrMessage != "" {
253- require .Error (t , err )
254- require .Contains (t , err .Error (), tc .expectedErrMessage )
255- } else {
256- require .NoError (t , err )
257- }
258- })
259- }
260- }
261-
262227func Test_RegistryV1ManifestProvider_SingleOwnNamespaceSupport (t * testing.T ) {
263228 t .Run ("rejects bundles without AllNamespaces install mode when Single/OwnNamespace install mode support is disabled" , func (t * testing.T ) {
264229 provider := applier.RegistryV1ManifestProvider {
@@ -276,6 +241,54 @@ func Test_RegistryV1ManifestProvider_SingleOwnNamespaceSupport(t *testing.T) {
276241 require .Equal (t , "unsupported bundle: bundle does not support AllNamespaces install mode" , err .Error ())
277242 })
278243
244+ t .Run ("rejects bundles without AllNamespaces install mode and with SingleNamespace support when Single/OwnNamespace install mode support is enabled" , func (t * testing.T ) {
245+ expectedWatchNamespace := "some-namespace"
246+ provider := applier.RegistryV1ManifestProvider {
247+ BundleRenderer : render.BundleRenderer {
248+ ResourceGenerators : []render.ResourceGenerator {
249+ func (rv1 * bundle.RegistryV1 , opts render.Options ) ([]client.Object , error ) {
250+ t .Log ("ensure watch namespace is appropriately configured" )
251+ require .Equal (t , []string {expectedWatchNamespace }, opts .TargetNamespaces )
252+ return nil , nil
253+ },
254+ },
255+ },
256+ IsSingleOwnNamespaceEnabled : false ,
257+ }
258+
259+ bundleFS := bundlefs .Builder ().WithPackageName ("test" ).
260+ WithCSV (clusterserviceversion .Builder ().WithInstallModeSupportFor (v1alpha1 .InstallModeTypeSingleNamespace ).Build ()).Build ()
261+
262+ _ , err := provider .Get (bundleFS , & ocv1.ClusterExtension {
263+ Spec : ocv1.ClusterExtensionSpec {
264+ Namespace : "install-namespace" ,
265+ Config : & ocv1.ClusterExtensionConfig {
266+ ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
267+ Inline : & apiextensionsv1.JSON {
268+ Raw : []byte (`{"watchNamespace": "` + expectedWatchNamespace + `"}` ),
269+ },
270+ },
271+ },
272+ })
273+ require .Error (t , err )
274+ require .Contains (t , err .Error (), "unsupported bundle" )
275+ })
276+
277+ t .Run ("rejects bundles without AllNamespaces install mode and with OwnNamespace support when Single/OwnNamespace install mode support is disabled" , func (t * testing.T ) {
278+ provider := applier.RegistryV1ManifestProvider {
279+ IsSingleOwnNamespaceEnabled : false ,
280+ }
281+ bundleFS := bundlefs .Builder ().WithPackageName ("test" ).
282+ WithCSV (clusterserviceversion .Builder ().WithInstallModeSupportFor (v1alpha1 .InstallModeTypeOwnNamespace ).Build ()).Build ()
283+ _ , err := provider .Get (bundleFS , & ocv1.ClusterExtension {
284+ Spec : ocv1.ClusterExtensionSpec {
285+ Namespace : "install-namespace" ,
286+ },
287+ })
288+ require .Error (t , err )
289+ require .Contains (t , err .Error (), "unsupported bundle" )
290+ })
291+
279292 t .Run ("accepts bundles without AllNamespaces install mode and with SingleNamespace support when Single/OwnNamespace install mode support is enabled" , func (t * testing.T ) {
280293 expectedWatchNamespace := "some-namespace"
281294 provider := applier.RegistryV1ManifestProvider {
0 commit comments