@@ -419,6 +419,107 @@ func TestSolveOperators_WithGVKDependencies(t *testing.T) {
419
419
}
420
420
}
421
421
422
+ func TestSolveOperators_WithLabelDependencies (t * testing.T ) {
423
+ namespace := "olm"
424
+ catalog := registry.CatalogKey {"community" , namespace }
425
+
426
+ newSub := newSub (namespace , "packageA" , "alpha" , catalog )
427
+ subs := []* v1alpha1.Subscription {newSub }
428
+
429
+ deps := []* api.Dependency {
430
+ {
431
+ Type : "olm.label" ,
432
+ Value : `{"label":"lts"}` ,
433
+ },
434
+ }
435
+
436
+ props := []* api.Property {
437
+ {
438
+ Type : "olm.label" ,
439
+ Value : `{"label":"lts"}` ,
440
+ },
441
+ }
442
+
443
+ operatorBv1 := genOperator ("packageB.v1" , "1.0.0" , "" , "packageB" , "beta" , "community" , "olm" , nil , nil , nil , "" )
444
+ for _ , p := range props {
445
+ operatorBv1 .properties = append (operatorBv1 .properties , p )
446
+ }
447
+
448
+ fakeNamespacedOperatorCache := NamespacedOperatorCache {
449
+ snapshots : map [registry.CatalogKey ]* CatalogSnapshot {
450
+ registry.CatalogKey {
451
+ Namespace : "olm" ,
452
+ Name : "community" ,
453
+ }: {
454
+ key : registry.CatalogKey {
455
+ Namespace : "olm" ,
456
+ Name : "community" ,
457
+ },
458
+ operators : []* Operator {
459
+ genOperator ("packageA" , "0.0.1" , "" , "packageA" , "alpha" , "community" , "olm" , nil , nil , deps , "" ),
460
+ operatorBv1 ,
461
+ },
462
+ },
463
+ },
464
+ }
465
+ satResolver := SatResolver {
466
+ cache : getFakeOperatorCache (fakeNamespacedOperatorCache ),
467
+ }
468
+
469
+ operators , err := satResolver .SolveOperators ([]string {"olm" }, nil , subs )
470
+ assert .NoError (t , err )
471
+ assert .Equal (t , 2 , len (operators ))
472
+
473
+ expected := OperatorSet {
474
+ "packageA" : genOperator ("packageA" , "0.0.1" , "" , "packageA" , "alpha" , "community" , "olm" , nil , nil , deps , "" ),
475
+ "packageB.v1" : operatorBv1 ,
476
+ }
477
+ for k := range expected {
478
+ require .NotNil (t , operators [k ])
479
+ assert .EqualValues (t , k , operators [k ].Identifier ())
480
+ }
481
+ }
482
+
483
+ func TestSolveOperators_WithUnsatisfiableLabelDependencies (t * testing.T ) {
484
+ namespace := "olm"
485
+ catalog := registry.CatalogKey {"community" , namespace }
486
+
487
+ newSub := newSub (namespace , "packageA" , "alpha" , catalog )
488
+ subs := []* v1alpha1.Subscription {newSub }
489
+
490
+ deps := []* api.Dependency {
491
+ {
492
+ Type : "olm.label" ,
493
+ Value : `{"label":"lts"}` ,
494
+ },
495
+ }
496
+
497
+ fakeNamespacedOperatorCache := NamespacedOperatorCache {
498
+ snapshots : map [registry.CatalogKey ]* CatalogSnapshot {
499
+ registry.CatalogKey {
500
+ Namespace : "olm" ,
501
+ Name : "community" ,
502
+ }: {
503
+ key : registry.CatalogKey {
504
+ Namespace : "olm" ,
505
+ Name : "community" ,
506
+ },
507
+ operators : []* Operator {
508
+ genOperator ("packageA" , "0.0.1" , "" , "packageA" , "alpha" , "community" , "olm" , nil , nil , deps , "" ),
509
+ genOperator ("packageB.v1" , "1.0.0" , "" , "packageB" , "alpha" , "community" , "olm" , nil , nil , nil , "" ),
510
+ },
511
+ },
512
+ },
513
+ }
514
+ satResolver := SatResolver {
515
+ cache : getFakeOperatorCache (fakeNamespacedOperatorCache ),
516
+ }
517
+
518
+ operators , err := satResolver .SolveOperators ([]string {"olm" }, nil , subs )
519
+ assert .Error (t , err )
520
+ assert .Equal (t , 0 , len (operators ))
521
+ }
522
+
422
523
func TestSolveOperators_WithNestedGVKDependencies (t * testing.T ) {
423
524
APISet := APISet {opregistry.APIKey {"g" , "v" , "k" , "ks" }: struct {}{}}
424
525
Provides := APISet
@@ -596,7 +697,7 @@ func TestSolveOperators_PreferCatalogInSameNamespace(t *testing.T) {
596
697
597
698
csv := existingOperator (namespace , "packageA.v1" , "packageA" , "alpha" , "" , Provides , nil , nil , nil )
598
699
csvs := []* v1alpha1.ClusterServiceVersion {csv }
599
- sub := existingSub (namespace ,"packageA.v1" , "packageA" , "alpha" , catalog )
700
+ sub := existingSub (namespace , "packageA.v1" , "packageA" , "alpha" , catalog )
600
701
subs := []* v1alpha1.Subscription {sub }
601
702
602
703
fakeNamespacedOperatorCache := NamespacedOperatorCache {
@@ -789,7 +890,7 @@ func TestSolveOperators_SubscriptionlessOperatorsSatisfyDependencies(t *testing.
789
890
assert .NoError (t , err )
790
891
assert .Equal (t , 2 , len (operators ))
791
892
expected := OperatorSet {
792
- "packageA.v1" : stripBundle (genOperator ("packageA.v1" , "" , "" , "packageA" , "alpha" , "@existing" , catalog .Namespace , nil , Provides , nil , "" )),
893
+ "packageA.v1" : stripBundle (genOperator ("packageA.v1" , "" , "" , "packageA" , "alpha" , "@existing" , catalog .Namespace , nil , Provides , nil , "" )),
793
894
"packageB.v1.0.1" : genOperator ("packageB.v1.0.1" , "1.0.1" , "packageB.v1.0.0" , "packageB" , "alpha" , catalog .Name , catalog .Namespace , Provides , nil , apiSetToDependencies (Provides , nil ), "" ),
794
895
}
795
896
for k := range expected {
@@ -903,8 +1004,8 @@ func TestSolveOperators_TransferApiOwnership(t *testing.T) {
903
1004
catalog := registry.CatalogKey {Name : "community" , Namespace : namespace }
904
1005
905
1006
phases := []struct {
906
- subs []* v1alpha1.Subscription
907
- catalog * CatalogSnapshot
1007
+ subs []* v1alpha1.Subscription
1008
+ catalog * CatalogSnapshot
908
1009
expected OperatorSet
909
1010
}{
910
1011
{
@@ -1023,7 +1124,7 @@ func genOperator(name, version, replaces, pkg, channel, catalogName, catalogName
1023
1124
Properties : apiSetToProperties (providedAPIs , nil ),
1024
1125
},
1025
1126
dependencies : dependencies ,
1026
- properties : apiSetToProperties (providedAPIs , nil ),
1127
+ properties : apiSetToProperties (providedAPIs , nil ),
1027
1128
sourceInfo : & OperatorSourceInfo {
1028
1129
Catalog : registry.CatalogKey {
1029
1130
Name : catalogName ,
@@ -1041,4 +1142,4 @@ func genOperator(name, version, replaces, pkg, channel, catalogName, catalogName
1041
1142
func stripBundle (o * Operator ) * Operator {
1042
1143
o .bundle = nil
1043
1144
return o
1044
- }
1145
+ }
0 commit comments