@@ -36,6 +36,15 @@ import (
3636 "github.com/operator-framework/operator-controller/internal/operator-controller/applier"
3737 "github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
3838 "github.com/operator-framework/operator-controller/internal/operator-controller/labels"
39+ "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/bundlefs"
40+ "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion"
41+ )
42+
43+ var (
44+ dummyBundle = bundlefs .Builder ().
45+ WithPackageName ("test-package" ).
46+ WithCSV (clusterserviceversion .Builder ().WithName ("test-csv" ).Build ()).
47+ Build ()
3948)
4049
4150func Test_SimpleRevisionGenerator_GenerateRevisionFromHelmRelease (t * testing.T ) {
@@ -195,7 +204,7 @@ func Test_SimpleRevisionGenerator_GenerateRevision(t *testing.T) {
195204 },
196205 }
197206
198- rev , err := b .GenerateRevision (t .Context (), fstest. MapFS {} , ext , map [string ]string {}, map [string ]string {})
207+ rev , err := b .GenerateRevision (t .Context (), dummyBundle , ext , map [string ]string {}, map [string ]string {})
199208 require .NoError (t , err )
200209
201210 t .Log ("by checking the olm.operatorframework.io/owner-name label is set to the name of the ClusterExtension" )
@@ -254,8 +263,82 @@ func Test_SimpleRevisionGenerator_GenerateRevision(t *testing.T) {
254263 }, rev .Spec .Phases )
255264}
256265
266+ func Test_SimpleRevisionGenerator_GenerateRevision_BundleAnnotations (t * testing.T ) {
267+ r := & FakeManifestProvider {
268+ GetFn : func (_ fs.FS , _ * ocv1.ClusterExtension ) ([]client.Object , error ) {
269+ return []client.Object {}, nil
270+ },
271+ }
272+
273+ b := applier.SimpleRevisionGenerator {
274+ Scheme : k8scheme .Scheme ,
275+ ManifestProvider : r ,
276+ }
277+
278+ ext := & ocv1.ClusterExtension {
279+ ObjectMeta : metav1.ObjectMeta {
280+ Name : "test-extension" ,
281+ },
282+ Spec : ocv1.ClusterExtensionSpec {
283+ Namespace : "test-namespace" ,
284+ ServiceAccount : ocv1.ServiceAccountReference {
285+ Name : "test-sa" ,
286+ },
287+ },
288+ }
289+
290+ t .Run ("bundle properties are copied to the olm.properties annotation" , func (t * testing.T ) {
291+ bundleFS := bundlefs .Builder ().
292+ WithPackageName ("test-package" ).
293+ WithBundleProperty ("olm.bundle.property" , "some-value" ).
294+ WithBundleProperty ("olm.another.bundle.property" , "some-other-value" ).
295+ WithCSV (clusterserviceversion .Builder ().WithName ("test-csv" ).Build ()).
296+ Build ()
297+
298+ rev , err := b .GenerateRevision (t .Context (), bundleFS , ext , map [string ]string {}, map [string ]string {})
299+ require .NoError (t , err )
300+
301+ t .Log ("by checking bundle properties are added to the revision annotations" )
302+ require .NotNil (t , rev .Annotations )
303+ require .JSONEq (t , `[{"type":"olm.bundle.property","value":"some-value"},{"type":"olm.another.bundle.property","value":"some-other-value"}]` , rev .Annotations ["olm.properties" ])
304+ })
305+
306+ t .Run ("olm.properties should not be present if there are no bundle properties" , func (t * testing.T ) {
307+ bundleFS := bundlefs .Builder ().
308+ WithPackageName ("test-package" ).
309+ WithCSV (clusterserviceversion .Builder ().WithName ("test-csv" ).Build ()).
310+ Build ()
311+
312+ rev , err := b .GenerateRevision (t .Context (), bundleFS , ext , map [string ]string {}, map [string ]string {})
313+ require .NoError (t , err )
314+
315+ t .Log ("by checking olm.properties is not present in the revision annotations" )
316+ _ , ok := rev .Annotations ["olm.properties" ]
317+ require .False (t , ok , "olm.properties should not be present in the revision annotations" )
318+ })
319+
320+ t .Run ("csv annotations are not added to the revision annotations" , func (t * testing.T ) {
321+ bundleFS := bundlefs .Builder ().
322+ WithPackageName ("test-package" ).
323+ WithBundleProperty ("olm.bundle.property" , "some-value" ).
324+ WithCSV (clusterserviceversion .Builder ().
325+ WithName ("test-csv" ).
326+ WithAnnotations (map [string ]string {
327+ "some.csv.annotation" : "some-other-value" ,
328+ }).
329+ Build ()).
330+ Build ()
331+
332+ rev , err := b .GenerateRevision (t .Context (), bundleFS , ext , map [string ]string {}, map [string ]string {})
333+ require .NoError (t , err )
334+
335+ t .Log ("by checking csv annotations are not added to the revision annotations" )
336+ _ , ok := rev .Annotations ["olm.csv.annotation" ]
337+ require .False (t , ok , "csv annotation should not be present in the revision annotations" )
338+ })
339+ }
340+
257341func Test_SimpleRevisionGenerator_Renderer_Integration (t * testing.T ) {
258- bundleFS := fstest.MapFS {}
259342 ext := & ocv1.ClusterExtension {
260343 ObjectMeta : metav1.ObjectMeta {
261344 Name : "test-extension" ,
@@ -264,7 +347,7 @@ func Test_SimpleRevisionGenerator_Renderer_Integration(t *testing.T) {
264347 r := & FakeManifestProvider {
265348 GetFn : func (b fs.FS , e * ocv1.ClusterExtension ) ([]client.Object , error ) {
266349 t .Log ("by checking renderer was called with the correct parameters" )
267- require .Equal (t , bundleFS , b )
350+ require .Equal (t , dummyBundle , b )
268351 require .Equal (t , ext , e )
269352 return nil , nil
270353 },
@@ -274,7 +357,7 @@ func Test_SimpleRevisionGenerator_Renderer_Integration(t *testing.T) {
274357 ManifestProvider : r ,
275358 }
276359
277- _ , err := b .GenerateRevision (t .Context (), bundleFS , ext , map [string ]string {}, map [string ]string {})
360+ _ , err := b .GenerateRevision (t .Context (), dummyBundle , ext , map [string ]string {}, map [string ]string {})
278361 require .NoError (t , err )
279362}
280363
@@ -312,7 +395,7 @@ func Test_SimpleRevisionGenerator_AppliesObjectLabelsAndRevisionAnnotations(t *t
312395 "other" : "value" ,
313396 }
314397
315- rev , err := b .GenerateRevision (t .Context (), fstest. MapFS {} , & ocv1.ClusterExtension {
398+ rev , err := b .GenerateRevision (t .Context (), dummyBundle , & ocv1.ClusterExtension {
316399 Spec : ocv1.ClusterExtensionSpec {
317400 Namespace : "test-namespace" ,
318401 ServiceAccount : ocv1.ServiceAccountReference {Name : "test-sa" },
@@ -386,7 +469,7 @@ func Test_SimpleRevisionGenerator_PropagatesProgressDeadlineMinutes(t *testing.T
386469 ext .Spec .ProgressDeadlineMinutes = * pd
387470 }
388471
389- rev , err := b .GenerateRevision (t .Context (), fstest. MapFS {} , ext , empty , empty )
472+ rev , err := b .GenerateRevision (t .Context (), dummyBundle , ext , empty , empty )
390473 require .NoError (t , err )
391474 require .Equal (t , tc .want .progressDeadlineMinutes , rev .Spec .ProgressDeadlineMinutes )
392475 })
0 commit comments