@@ -419,6 +419,122 @@ func TestSolveOperators_WithGVKDependencies(t *testing.T) {
419
419
}
420
420
}
421
421
422
+ func TestSolveOperators_WithLabelDependencies (t * testing.T ) {
423
+ APISet := APISet {opregistry.APIKey {"g" , "v" , "k" , "ks" }: struct {}{}}
424
+ Provides := APISet
425
+
426
+ namespace := "olm"
427
+ catalog := registry.CatalogKey {"community" , namespace }
428
+
429
+ newSub := newSub (namespace , "packageA" , "alpha" , catalog )
430
+ subs := []* v1alpha1.Subscription {newSub }
431
+
432
+ deps := []* api.Dependency {
433
+ {
434
+ Type : "olm.gvk" ,
435
+ Value : `{"group":"g","kind":"k","version":"v"}` ,
436
+ },
437
+ {
438
+ Type : "olm.label" ,
439
+ Value : `{"label":"lts"}` ,
440
+ },
441
+ }
442
+
443
+ props := []* api.Property {
444
+ {
445
+ Type : "olm.label" ,
446
+ Value : `{"label":"lts"}` ,
447
+ },
448
+ }
449
+
450
+ operatorBv1 := genOperator ("packageB.v1" , "1.0.0" , "" , "packageB" , "beta" , "community" , "olm" , nil , Provides , nil , "" )
451
+ for _ , p := range props {
452
+ operatorBv1 .properties = append (operatorBv1 .properties , p )
453
+ }
454
+
455
+ fakeNamespacedOperatorCache := NamespacedOperatorCache {
456
+ snapshots : map [registry.CatalogKey ]* CatalogSnapshot {
457
+ registry.CatalogKey {
458
+ Namespace : "olm" ,
459
+ Name : "community" ,
460
+ }: {
461
+ key : registry.CatalogKey {
462
+ Namespace : "olm" ,
463
+ Name : "community" ,
464
+ },
465
+ operators : []* Operator {
466
+ genOperator ("packageA" , "0.0.1" , "" , "packageA" , "alpha" , "community" , "olm" , nil , nil , deps , "" ),
467
+ operatorBv1 ,
468
+ genOperator ("packageB.v2" , "2.0.0" , "" , "packageB" , "alpha" , "community" , "olm" , nil , Provides , nil , "" ),
469
+ },
470
+ },
471
+ },
472
+ }
473
+ satResolver := SatResolver {
474
+ cache : getFakeOperatorCache (fakeNamespacedOperatorCache ),
475
+ }
476
+
477
+ operators , err := satResolver .SolveOperators ([]string {"olm" }, nil , subs )
478
+ assert .NoError (t , err )
479
+ assert .Equal (t , 2 , len (operators ))
480
+
481
+ expected := OperatorSet {
482
+ "packageA" : genOperator ("packageA" , "0.0.1" , "" , "packageA" , "alpha" , "community" , "olm" , nil , nil , deps , "" ),
483
+ "packageB.v1" : operatorBv1 ,
484
+ }
485
+ for k := range expected {
486
+ require .NotNil (t , operators [k ])
487
+ assert .EqualValues (t , k , operators [k ].Identifier ())
488
+ }
489
+ }
490
+
491
+ func TestSolveOperators_WithUnsatisfiableLabelDependencies (t * testing.T ) {
492
+ APISet := APISet {opregistry.APIKey {"g" , "v" , "k" , "ks" }: struct {}{}}
493
+ Provides := APISet
494
+
495
+ namespace := "olm"
496
+ catalog := registry.CatalogKey {"community" , namespace }
497
+
498
+ newSub := newSub (namespace , "packageA" , "alpha" , catalog )
499
+ subs := []* v1alpha1.Subscription {newSub }
500
+
501
+ deps := []* api.Dependency {
502
+ {
503
+ Type : "olm.gvk" ,
504
+ Value : `{"group":"g","kind":"k","version":"v"}` ,
505
+ },
506
+ {
507
+ Type : "olm.label" ,
508
+ Value : `{"label":"lts"}` ,
509
+ },
510
+ }
511
+
512
+ fakeNamespacedOperatorCache := NamespacedOperatorCache {
513
+ snapshots : map [registry.CatalogKey ]* CatalogSnapshot {
514
+ registry.CatalogKey {
515
+ Namespace : "olm" ,
516
+ Name : "community" ,
517
+ }: {
518
+ key : registry.CatalogKey {
519
+ Namespace : "olm" ,
520
+ Name : "community" ,
521
+ },
522
+ operators : []* Operator {
523
+ genOperator ("packageA" , "0.0.1" , "" , "packageA" , "alpha" , "community" , "olm" , nil , nil , deps , "" ),
524
+ genOperator ("packageB.v1" , "1.0.0" , "" , "packageB" , "alpha" , "community" , "olm" , nil , Provides , nil , "" ),
525
+ },
526
+ },
527
+ },
528
+ }
529
+ satResolver := SatResolver {
530
+ cache : getFakeOperatorCache (fakeNamespacedOperatorCache ),
531
+ }
532
+
533
+ operators , err := satResolver .SolveOperators ([]string {"olm" }, nil , subs )
534
+ assert .Error (t , err )
535
+ assert .Equal (t , 0 , len (operators ))
536
+ }
537
+
422
538
func TestSolveOperators_WithNestedGVKDependencies (t * testing.T ) {
423
539
APISet := APISet {opregistry.APIKey {"g" , "v" , "k" , "ks" }: struct {}{}}
424
540
Provides := APISet
@@ -596,7 +712,7 @@ func TestSolveOperators_PreferCatalogInSameNamespace(t *testing.T) {
596
712
597
713
csv := existingOperator (namespace , "packageA.v1" , "packageA" , "alpha" , "" , Provides , nil , nil , nil )
598
714
csvs := []* v1alpha1.ClusterServiceVersion {csv }
599
- sub := existingSub (namespace ,"packageA.v1" , "packageA" , "alpha" , catalog )
715
+ sub := existingSub (namespace , "packageA.v1" , "packageA" , "alpha" , catalog )
600
716
subs := []* v1alpha1.Subscription {sub }
601
717
602
718
fakeNamespacedOperatorCache := NamespacedOperatorCache {
@@ -789,7 +905,7 @@ func TestSolveOperators_SubscriptionlessOperatorsSatisfyDependencies(t *testing.
789
905
assert .NoError (t , err )
790
906
assert .Equal (t , 2 , len (operators ))
791
907
expected := OperatorSet {
792
- "packageA.v1" : stripBundle (genOperator ("packageA.v1" , "" , "" , "packageA" , "alpha" , "@existing" , catalog .Namespace , nil , Provides , nil , "" )),
908
+ "packageA.v1" : stripBundle (genOperator ("packageA.v1" , "" , "" , "packageA" , "alpha" , "@existing" , catalog .Namespace , nil , Provides , nil , "" )),
793
909
"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
910
}
795
911
for k := range expected {
@@ -903,8 +1019,8 @@ func TestSolveOperators_TransferApiOwnership(t *testing.T) {
903
1019
catalog := registry.CatalogKey {Name : "community" , Namespace : namespace }
904
1020
905
1021
phases := []struct {
906
- subs []* v1alpha1.Subscription
907
- catalog * CatalogSnapshot
1022
+ subs []* v1alpha1.Subscription
1023
+ catalog * CatalogSnapshot
908
1024
expected OperatorSet
909
1025
}{
910
1026
{
@@ -1023,7 +1139,7 @@ func genOperator(name, version, replaces, pkg, channel, catalogName, catalogName
1023
1139
Properties : apiSetToProperties (providedAPIs , nil ),
1024
1140
},
1025
1141
dependencies : dependencies ,
1026
- properties : apiSetToProperties (providedAPIs , nil ),
1142
+ properties : apiSetToProperties (providedAPIs , nil ),
1027
1143
sourceInfo : & OperatorSourceInfo {
1028
1144
Catalog : registry.CatalogKey {
1029
1145
Name : catalogName ,
@@ -1041,4 +1157,4 @@ func genOperator(name, version, replaces, pkg, channel, catalogName, catalogName
1041
1157
func stripBundle (o * Operator ) * Operator {
1042
1158
o .bundle = nil
1043
1159
return o
1044
- }
1160
+ }
0 commit comments