@@ -2,6 +2,7 @@ package catalog
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"fmt"
6
7
"testing"
7
8
"time"
@@ -13,6 +14,8 @@ import (
13
14
utilclocktesting "k8s.io/utils/clock/testing"
14
15
15
16
"github.com/operator-framework/api/pkg/operators/v1alpha1"
17
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/bundle"
18
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/bundle/bundlefakes"
16
19
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/reconciler"
17
20
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
18
21
"github.com/operator-framework/operator-lifecycle-manager/pkg/fakes"
@@ -29,6 +32,7 @@ func TestSyncSubscriptions(t *testing.T) {
29
32
resolveSteps []* v1alpha1.Step
30
33
resolveSubs []* v1alpha1.Subscription
31
34
resolveBundleLookups []v1alpha1.BundleLookup
35
+ unpackBundleErr error
32
36
existingOLMObjs []runtime.Object
33
37
}
34
38
type args struct {
@@ -431,55 +435,194 @@ func TestSyncSubscriptions(t *testing.T) {
431
435
},
432
436
Status : v1alpha1.SubscriptionStatus {
433
437
CurrentCSV : "" ,
434
- State : v1alpha1 .SubscriptionStateUpgradePending ,
435
- Install : & v1alpha1.InstallPlanReference {
436
- Kind : v1alpha1 .InstallPlanKind ,
437
- APIVersion : v1alpha1 .InstallPlanAPIVersion ,
438
+ State : "" ,
439
+ },
440
+ },
441
+ },
442
+ },
443
+ {
444
+ name : "NoStatus/NoCurrentCSV/BundleLookupFailed" ,
445
+ fields : fields {
446
+ clientOptions : []clientfake.Option {clientfake .WithSelfLinks (t )},
447
+ existingOLMObjs : []runtime.Object {
448
+ & v1alpha1.Subscription {
449
+ TypeMeta : metav1.TypeMeta {
450
+ Kind : v1alpha1 .SubscriptionKind ,
451
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
438
452
},
439
- InstallPlanRef : & corev1.ObjectReference {
440
- Namespace : testNamespace ,
441
- Kind : v1alpha1 .InstallPlanKind ,
442
- APIVersion : v1alpha1 .InstallPlanAPIVersion ,
453
+ ObjectMeta : metav1.ObjectMeta {
454
+ Name : "sub" ,
455
+ Namespace : testNamespace ,
456
+ },
457
+ Spec : & v1alpha1.SubscriptionSpec {
458
+ CatalogSource : "src" ,
459
+ CatalogSourceNamespace : testNamespace ,
460
+ },
461
+ Status : v1alpha1.SubscriptionStatus {
462
+ CurrentCSV : "" ,
463
+ State : "" ,
464
+ },
465
+ },
466
+ },
467
+ resolveSubs : []* v1alpha1.Subscription {
468
+ {
469
+ TypeMeta : metav1.TypeMeta {
470
+ Kind : v1alpha1 .SubscriptionKind ,
471
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
472
+ },
473
+ ObjectMeta : metav1.ObjectMeta {
474
+ Name : "sub" ,
475
+ Namespace : testNamespace ,
476
+ },
477
+ Spec : & v1alpha1.SubscriptionSpec {
478
+ CatalogSource : "src" ,
479
+ CatalogSourceNamespace : testNamespace ,
480
+ },
481
+ Status : v1alpha1.SubscriptionStatus {
482
+ CurrentCSV : "" ,
483
+ State : v1alpha1 .SubscriptionStateUpgradePending ,
484
+ },
485
+ },
486
+ },
487
+ resolveBundleLookups : []v1alpha1.BundleLookup {
488
+ {
489
+ Path : "bundle-path-a" ,
490
+ Identifier : "bundle-a" ,
491
+ CatalogSourceRef : & corev1.ObjectReference {
492
+ Namespace : testNamespace ,
493
+ Name : "src" ,
494
+ },
495
+ Conditions : []v1alpha1.BundleLookupCondition {
496
+ {
497
+ Type : bundle .BundleLookupFailed ,
498
+ Status : corev1 .ConditionTrue ,
499
+ Reason : "JobFailed" ,
500
+ Message : "unpack job failed" ,
501
+ LastTransitionTime : & now ,
502
+ },
443
503
},
444
- InstallPlanGeneration : 1 ,
445
- LastUpdated : now ,
446
504
},
447
505
},
448
506
},
449
- wantInstallPlans : []v1alpha1.InstallPlan {
507
+ args : args {
508
+ obj : & v1alpha1.Subscription {
509
+ TypeMeta : metav1.TypeMeta {
510
+ Kind : v1alpha1 .SubscriptionKind ,
511
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
512
+ },
513
+ ObjectMeta : metav1.ObjectMeta {
514
+ Name : "sub" ,
515
+ Namespace : testNamespace ,
516
+ },
517
+ Spec : & v1alpha1.SubscriptionSpec {
518
+ CatalogSource : "src" ,
519
+ CatalogSourceNamespace : testNamespace ,
520
+ },
521
+ Status : v1alpha1.SubscriptionStatus {
522
+ CurrentCSV : "" ,
523
+ State : "" ,
524
+ },
525
+ },
526
+ },
527
+ wantSubscriptions : []* v1alpha1.Subscription {
450
528
{
451
- Spec : v1alpha1.InstallPlanSpec {
452
- ClusterServiceVersionNames : []string {"bundle-a" },
453
- Approval : v1alpha1 .ApprovalAutomatic ,
454
- Approved : true ,
455
- Generation : 1 ,
529
+ TypeMeta : metav1.TypeMeta {
530
+ Kind : v1alpha1 .SubscriptionKind ,
531
+ APIVersion : v1alpha1 .SubscriptionCRDAPIVersion ,
456
532
},
457
- Status : v1alpha1.InstallPlanStatus {
458
- Phase : v1alpha1 .InstallPlanPhaseInstalling ,
459
- CatalogSources : []string {},
460
- BundleLookups : []v1alpha1.BundleLookup {
533
+ ObjectMeta : metav1.ObjectMeta {
534
+ Name : "sub" ,
535
+ Namespace : testNamespace ,
536
+ },
537
+ Spec : & v1alpha1.SubscriptionSpec {
538
+ CatalogSource : "src" ,
539
+ CatalogSourceNamespace : testNamespace ,
540
+ },
541
+ Status : v1alpha1.SubscriptionStatus {
542
+ CurrentCSV : "" ,
543
+ State : "" ,
544
+ LastUpdated : now ,
545
+ Conditions : []v1alpha1.SubscriptionCondition {
461
546
{
462
- Path : "bundle-path-a" ,
463
- Identifier : "bundle-a" ,
464
- CatalogSourceRef : & corev1.ObjectReference {
465
- Namespace : testNamespace ,
466
- Name : "src" ,
467
- },
468
- Conditions : []v1alpha1.BundleLookupCondition {
469
- {
470
- Type : v1alpha1 .BundleLookupPending ,
471
- Status : corev1 .ConditionTrue ,
472
- Reason : "JobIncomplete" ,
473
- Message : "unpack job not completed" ,
474
- LastTransitionTime : & now ,
475
- },
476
- },
547
+ Type : v1alpha1 .SubscriptionResolutionFailed ,
548
+ Reason : "BundleUnpackFailurePreventedResolution" ,
549
+ Message : "bundle unpacking failed. Reason: JobFailed, and Message: unpack job failed" ,
550
+ Status : corev1 .ConditionTrue ,
477
551
},
478
552
},
479
553
},
480
554
},
481
555
},
482
556
},
557
+ {
558
+ name : "NoStatus/NoCurrentCSV/BundleLookupError" ,
559
+ fields : fields {
560
+ clientOptions : []clientfake.Option {clientfake .WithSelfLinks (t )},
561
+ existingOLMObjs : []runtime.Object {
562
+ & v1alpha1.Subscription {
563
+ TypeMeta : metav1.TypeMeta {
564
+ Kind : v1alpha1 .SubscriptionKind ,
565
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
566
+ },
567
+ ObjectMeta : metav1.ObjectMeta {
568
+ Name : "sub" ,
569
+ Namespace : testNamespace ,
570
+ },
571
+ Spec : & v1alpha1.SubscriptionSpec {
572
+ CatalogSource : "src" ,
573
+ CatalogSourceNamespace : testNamespace ,
574
+ },
575
+ Status : v1alpha1.SubscriptionStatus {
576
+ CurrentCSV : "" ,
577
+ State : "" ,
578
+ },
579
+ },
580
+ },
581
+ resolveBundleLookups : []v1alpha1.BundleLookup {{}},
582
+ unpackBundleErr : errors .New ("fake unpack error" ),
583
+ },
584
+ args : args {
585
+ obj : & v1alpha1.Subscription {
586
+ TypeMeta : metav1.TypeMeta {
587
+ Kind : v1alpha1 .SubscriptionKind ,
588
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
589
+ },
590
+ ObjectMeta : metav1.ObjectMeta {
591
+ Name : "sub" ,
592
+ Namespace : testNamespace ,
593
+ },
594
+ Spec : & v1alpha1.SubscriptionSpec {
595
+ CatalogSource : "src" ,
596
+ CatalogSourceNamespace : testNamespace ,
597
+ },
598
+ Status : v1alpha1.SubscriptionStatus {
599
+ CurrentCSV : "" ,
600
+ State : "" ,
601
+ },
602
+ },
603
+ },
604
+ wantSubscriptions : []* v1alpha1.Subscription {
605
+ {
606
+ TypeMeta : metav1.TypeMeta {
607
+ Kind : v1alpha1 .SubscriptionKind ,
608
+ APIVersion : v1alpha1 .SubscriptionCRDAPIVersion ,
609
+ },
610
+ ObjectMeta : metav1.ObjectMeta {
611
+ Name : "sub" ,
612
+ Namespace : testNamespace ,
613
+ },
614
+ Spec : & v1alpha1.SubscriptionSpec {
615
+ CatalogSource : "src" ,
616
+ CatalogSourceNamespace : testNamespace ,
617
+ },
618
+ Status : v1alpha1.SubscriptionStatus {
619
+ CurrentCSV : "" ,
620
+ State : "" ,
621
+ },
622
+ },
623
+ },
624
+ wantErr : errors .New ("bundle unpacking failed with an error: fake unpack error" ),
625
+ },
483
626
{
484
627
name : "Status/HaveCurrentCSV/UpdateFoundInCatalog" ,
485
628
fields : fields {
@@ -1013,7 +1156,12 @@ func TestSyncSubscriptions(t *testing.T) {
1013
1156
ctx , cancel := context .WithCancel (context .TODO ())
1014
1157
defer cancel ()
1015
1158
1016
- o , err := NewFakeOperator (ctx , testNamespace , []string {testNamespace }, withClock (clockFake ), withClientObjs (tt .fields .existingOLMObjs ... ), withFakeClientOptions (tt .fields .clientOptions ... ))
1159
+ fakeBundleUnpacker := & bundlefakes.FakeUnpacker {
1160
+ UnpackBundleStub : func (lookup * v1alpha1.BundleLookup , timeout time.Duration ) (* bundle.BundleUnpackResult , error ) {
1161
+ return & bundle.BundleUnpackResult {BundleLookup : lookup .DeepCopy ()}, tt .fields .unpackBundleErr
1162
+ },
1163
+ }
1164
+ o , err := NewFakeOperator (ctx , testNamespace , []string {testNamespace }, withClock (clockFake ), withClientObjs (tt .fields .existingOLMObjs ... ), withFakeClientOptions (tt .fields .clientOptions ... ), withBundleUnpacker (fakeBundleUnpacker ))
1017
1165
require .NoError (t , err )
1018
1166
1019
1167
o .reconciler = & fakes.FakeRegistryReconcilerFactory {
0 commit comments