@@ -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 {
@@ -385,11 +389,10 @@ func TestSyncSubscriptions(t *testing.T) {
385
389
},
386
390
Conditions : []v1alpha1.BundleLookupCondition {
387
391
{
388
- Type : v1alpha1 .BundleLookupPending ,
389
- Status : corev1 .ConditionTrue ,
390
- Reason : "JobIncomplete" ,
391
- Message : "unpack job not completed" ,
392
- LastTransitionTime : & now ,
392
+ Type : v1alpha1 .BundleLookupPending ,
393
+ Status : corev1 .ConditionTrue ,
394
+ Reason : "JobIncomplete" ,
395
+ Message : "unpack job not completed" ,
393
396
},
394
397
},
395
398
},
@@ -430,56 +433,203 @@ func TestSyncSubscriptions(t *testing.T) {
430
433
CatalogSourceNamespace : testNamespace ,
431
434
},
432
435
Status : v1alpha1.SubscriptionStatus {
433
- CurrentCSV : "" ,
434
- State : v1alpha1 .SubscriptionStateUpgradePending ,
435
- Install : & v1alpha1.InstallPlanReference {
436
- Kind : v1alpha1 .InstallPlanKind ,
437
- APIVersion : v1alpha1 .InstallPlanAPIVersion ,
436
+ CurrentCSV : "" ,
437
+ State : "" ,
438
+ LastUpdated : now ,
439
+ Conditions : []v1alpha1.SubscriptionCondition {
440
+ {
441
+ Type : v1alpha1 .SubscriptionBundleUnpacking ,
442
+ Status : corev1 .ConditionTrue ,
443
+ Reason : "UnpackingInProgress" ,
444
+ },
438
445
},
439
- InstallPlanRef : & corev1.ObjectReference {
440
- Namespace : testNamespace ,
441
- Kind : v1alpha1 .InstallPlanKind ,
442
- APIVersion : v1alpha1 .InstallPlanAPIVersion ,
446
+ },
447
+ },
448
+ },
449
+ },
450
+ {
451
+ name : "NoStatus/NoCurrentCSV/BundleUnpackFailed" ,
452
+ fields : fields {
453
+ clientOptions : []clientfake.Option {clientfake .WithSelfLinks (t )},
454
+ existingOLMObjs : []runtime.Object {
455
+ & v1alpha1.Subscription {
456
+ TypeMeta : metav1.TypeMeta {
457
+ Kind : v1alpha1 .SubscriptionKind ,
458
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
459
+ },
460
+ ObjectMeta : metav1.ObjectMeta {
461
+ Name : "sub" ,
462
+ Namespace : testNamespace ,
463
+ },
464
+ Spec : & v1alpha1.SubscriptionSpec {
465
+ CatalogSource : "src" ,
466
+ CatalogSourceNamespace : testNamespace ,
467
+ },
468
+ Status : v1alpha1.SubscriptionStatus {
469
+ CurrentCSV : "" ,
470
+ State : "" ,
471
+ },
472
+ },
473
+ },
474
+ resolveSubs : []* v1alpha1.Subscription {
475
+ {
476
+ TypeMeta : metav1.TypeMeta {
477
+ Kind : v1alpha1 .SubscriptionKind ,
478
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
479
+ },
480
+ ObjectMeta : metav1.ObjectMeta {
481
+ Name : "sub" ,
482
+ Namespace : testNamespace ,
483
+ },
484
+ Spec : & v1alpha1.SubscriptionSpec {
485
+ CatalogSource : "src" ,
486
+ CatalogSourceNamespace : testNamespace ,
487
+ },
488
+ Status : v1alpha1.SubscriptionStatus {
489
+ CurrentCSV : "" ,
490
+ State : v1alpha1 .SubscriptionStateUpgradePending ,
491
+ },
492
+ },
493
+ },
494
+ resolveBundleLookups : []v1alpha1.BundleLookup {
495
+ {
496
+ Path : "bundle-path-a" ,
497
+ Identifier : "bundle-a" ,
498
+ CatalogSourceRef : & corev1.ObjectReference {
499
+ Namespace : testNamespace ,
500
+ Name : "src" ,
501
+ },
502
+ Conditions : []v1alpha1.BundleLookupCondition {
503
+ {
504
+ Type : v1alpha1 .BundleLookupFailed ,
505
+ Status : corev1 .ConditionTrue ,
506
+ Reason : "JobFailed" ,
507
+ Message : "unpack job failed" ,
508
+ LastTransitionTime : & now ,
509
+ },
443
510
},
444
- InstallPlanGeneration : 1 ,
445
- LastUpdated : now ,
446
511
},
447
512
},
448
513
},
449
- wantInstallPlans : []v1alpha1.InstallPlan {
514
+ args : args {
515
+ obj : & v1alpha1.Subscription {
516
+ TypeMeta : metav1.TypeMeta {
517
+ Kind : v1alpha1 .SubscriptionKind ,
518
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
519
+ },
520
+ ObjectMeta : metav1.ObjectMeta {
521
+ Name : "sub" ,
522
+ Namespace : testNamespace ,
523
+ },
524
+ Spec : & v1alpha1.SubscriptionSpec {
525
+ CatalogSource : "src" ,
526
+ CatalogSourceNamespace : testNamespace ,
527
+ },
528
+ Status : v1alpha1.SubscriptionStatus {
529
+ CurrentCSV : "" ,
530
+ State : "" ,
531
+ },
532
+ },
533
+ },
534
+ wantSubscriptions : []* v1alpha1.Subscription {
450
535
{
451
- Spec : v1alpha1.InstallPlanSpec {
452
- ClusterServiceVersionNames : []string {"bundle-a" },
453
- Approval : v1alpha1 .ApprovalAutomatic ,
454
- Approved : true ,
455
- Generation : 1 ,
536
+ TypeMeta : metav1.TypeMeta {
537
+ Kind : v1alpha1 .SubscriptionKind ,
538
+ APIVersion : v1alpha1 .SubscriptionCRDAPIVersion ,
456
539
},
457
- Status : v1alpha1.InstallPlanStatus {
458
- Phase : v1alpha1 .InstallPlanPhaseInstalling ,
459
- CatalogSources : []string {},
460
- BundleLookups : []v1alpha1.BundleLookup {
540
+ ObjectMeta : metav1.ObjectMeta {
541
+ Name : "sub" ,
542
+ Namespace : testNamespace ,
543
+ },
544
+ Spec : & v1alpha1.SubscriptionSpec {
545
+ CatalogSource : "src" ,
546
+ CatalogSourceNamespace : testNamespace ,
547
+ },
548
+ Status : v1alpha1.SubscriptionStatus {
549
+ CurrentCSV : "" ,
550
+ State : "" ,
551
+ LastUpdated : now ,
552
+ Conditions : []v1alpha1.SubscriptionCondition {
461
553
{
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
- },
554
+ Type : v1alpha1 .SubscriptionBundleUnpackFailed ,
555
+ Reason : "BundleUnpackFailed" ,
556
+ Message : "bundle unpacking failed. Reason: JobFailed, and Message: unpack job failed" ,
557
+ Status : corev1 .ConditionTrue ,
477
558
},
478
559
},
479
560
},
480
561
},
481
562
},
482
563
},
564
+ {
565
+ name : "NoStatus/NoCurrentCSV/BundleLookupError" ,
566
+ fields : fields {
567
+ clientOptions : []clientfake.Option {clientfake .WithSelfLinks (t )},
568
+ existingOLMObjs : []runtime.Object {
569
+ & v1alpha1.Subscription {
570
+ TypeMeta : metav1.TypeMeta {
571
+ Kind : v1alpha1 .SubscriptionKind ,
572
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
573
+ },
574
+ ObjectMeta : metav1.ObjectMeta {
575
+ Name : "sub" ,
576
+ Namespace : testNamespace ,
577
+ },
578
+ Spec : & v1alpha1.SubscriptionSpec {
579
+ CatalogSource : "src" ,
580
+ CatalogSourceNamespace : testNamespace ,
581
+ },
582
+ Status : v1alpha1.SubscriptionStatus {
583
+ CurrentCSV : "" ,
584
+ State : "" ,
585
+ },
586
+ },
587
+ },
588
+ resolveBundleLookups : []v1alpha1.BundleLookup {{}},
589
+ unpackBundleErr : errors .New ("fake unpack error" ),
590
+ },
591
+ args : args {
592
+ obj : & v1alpha1.Subscription {
593
+ TypeMeta : metav1.TypeMeta {
594
+ Kind : v1alpha1 .SubscriptionKind ,
595
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
596
+ },
597
+ ObjectMeta : metav1.ObjectMeta {
598
+ Name : "sub" ,
599
+ Namespace : testNamespace ,
600
+ },
601
+ Spec : & v1alpha1.SubscriptionSpec {
602
+ CatalogSource : "src" ,
603
+ CatalogSourceNamespace : testNamespace ,
604
+ },
605
+ Status : v1alpha1.SubscriptionStatus {
606
+ CurrentCSV : "" ,
607
+ State : "" ,
608
+ },
609
+ },
610
+ },
611
+ wantSubscriptions : []* v1alpha1.Subscription {
612
+ {
613
+ TypeMeta : metav1.TypeMeta {
614
+ Kind : v1alpha1 .SubscriptionKind ,
615
+ APIVersion : v1alpha1 .SubscriptionCRDAPIVersion ,
616
+ },
617
+ ObjectMeta : metav1.ObjectMeta {
618
+ Name : "sub" ,
619
+ Namespace : testNamespace ,
620
+ },
621
+ Spec : & v1alpha1.SubscriptionSpec {
622
+ CatalogSource : "src" ,
623
+ CatalogSourceNamespace : testNamespace ,
624
+ },
625
+ Status : v1alpha1.SubscriptionStatus {
626
+ CurrentCSV : "" ,
627
+ State : "" ,
628
+ },
629
+ },
630
+ },
631
+ wantErr : errors .New ("bundle unpacking failed with an error: fake unpack error" ),
632
+ },
483
633
{
484
634
name : "Status/HaveCurrentCSV/UpdateFoundInCatalog" ,
485
635
fields : fields {
@@ -1013,7 +1163,12 @@ func TestSyncSubscriptions(t *testing.T) {
1013
1163
ctx , cancel := context .WithCancel (context .TODO ())
1014
1164
defer cancel ()
1015
1165
1016
- o , err := NewFakeOperator (ctx , testNamespace , []string {testNamespace }, withClock (clockFake ), withClientObjs (tt .fields .existingOLMObjs ... ), withFakeClientOptions (tt .fields .clientOptions ... ))
1166
+ fakeBundleUnpacker := & bundlefakes.FakeUnpacker {
1167
+ UnpackBundleStub : func (lookup * v1alpha1.BundleLookup , timeout time.Duration ) (* bundle.BundleUnpackResult , error ) {
1168
+ return & bundle.BundleUnpackResult {BundleLookup : lookup .DeepCopy ()}, tt .fields .unpackBundleErr
1169
+ },
1170
+ }
1171
+ o , err := NewFakeOperator (ctx , testNamespace , []string {testNamespace }, withClock (clockFake ), withClientObjs (tt .fields .existingOLMObjs ... ), withFakeClientOptions (tt .fields .clientOptions ... ), withBundleUnpacker (fakeBundleUnpacker ))
1017
1172
require .NoError (t , err )
1018
1173
1019
1174
o .reconciler = & fakes.FakeRegistryReconcilerFactory {
0 commit comments