@@ -19,6 +19,7 @@ import (
19
19
ctrl "sigs.k8s.io/controller-runtime"
20
20
"sigs.k8s.io/controller-runtime/pkg/client"
21
21
22
+ helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
22
23
"github.com/operator-framework/operator-registry/alpha/declcfg"
23
24
"github.com/operator-framework/operator-registry/alpha/property"
24
25
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
@@ -416,11 +417,16 @@ func verifyConditionsInvariants(t *testing.T, ext *ocv1alpha1.ClusterExtension)
416
417
func TestClusterExtensionUpgrade (t * testing.T ) {
417
418
cl , reconciler := newClientAndReconciler (t )
418
419
mockUnpacker := unpacker .(* MockUnpacker )
419
- // Set up the Unpack method to return a result with StateUnpacked
420
+ // Set up the Unpack method to return a result with StateUnpackPending
420
421
mockUnpacker .On ("Unpack" , mock .Anything , mock .AnythingOfType ("*v1alpha2.BundleDeployment" )).Return (& source.Result {
421
422
State : source .StatePending ,
422
423
}, nil )
423
424
ctx := context .Background ()
425
+ defer func () {
426
+ controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
427
+ return nil , nil
428
+ }
429
+ }()
424
430
425
431
t .Run ("semver upgrade constraints enforcement of upgrades within major version" , func (t * testing.T ) {
426
432
defer featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .ForceSemverUpgradeConstraints , true )()
@@ -470,6 +476,22 @@ func TestClusterExtensionUpgrade(t *testing.T) {
470
476
err = cl .Update (ctx , clusterExtension )
471
477
require .NoError (t , err )
472
478
479
+ controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
480
+ return & catalogmetadata.Bundle {
481
+ Bundle : declcfg.Bundle {
482
+ Name : "operatorhub/prometheus/beta/1.0.0" ,
483
+ Package : "prometheus" ,
484
+ Image :
"quay.io/operatorhubio/[email protected] " ,
485
+ Properties : []property.Property {
486
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.0"}` )},
487
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
488
+ },
489
+ },
490
+ CatalogName : "fake-catalog" ,
491
+ InChannels : []* catalogmetadata.Channel {& prometheusBetaChannel },
492
+ }, nil
493
+ }
494
+
473
495
// Run reconcile again
474
496
res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
475
497
require .Error (t , err )
@@ -488,7 +510,7 @@ func TestClusterExtensionUpgrade(t *testing.T) {
488
510
require .NotNil (t , cond )
489
511
assert .Equal (t , metav1 .ConditionFalse , cond .Status )
490
512
assert .Equal (t , ocv1alpha1 .ReasonResolutionFailed , cond .Reason )
491
- assert .Equal (t , "error upgrading from currently installed version \" 1.0.0\" : no package \" prometheus\" matching version \" 2.0.0\" found in channel \" beta\" " , cond .Message )
513
+ assert .Equal (t , "error upgrading from currently installed version \" 1.0.0\" : no package \" prometheus\" matching version \" 2.0.0\" in channel \" beta\" found " , cond .Message )
492
514
493
515
// Valid update skipping one version
494
516
clusterExtension .Spec .Version = "1.2.0"
@@ -563,6 +585,22 @@ func TestClusterExtensionUpgrade(t *testing.T) {
563
585
err = cl .Update (ctx , clusterExtension )
564
586
require .NoError (t , err )
565
587
588
+ controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
589
+ return & catalogmetadata.Bundle {
590
+ Bundle : declcfg.Bundle {
591
+ Name : "operatorhub/prometheus/beta/1.0.0" ,
592
+ Package : "prometheus" ,
593
+ Image :
"quay.io/operatorhubio/[email protected] " ,
594
+ Properties : []property.Property {
595
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.0"}` )},
596
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
597
+ },
598
+ },
599
+ CatalogName : "fake-catalog" ,
600
+ InChannels : []* catalogmetadata.Channel {& prometheusBetaChannel },
601
+ }, nil
602
+ }
603
+
566
604
// Run reconcile again
567
605
res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
568
606
require .Error (t , err )
@@ -581,7 +619,7 @@ func TestClusterExtensionUpgrade(t *testing.T) {
581
619
require .NotNil (t , cond )
582
620
assert .Equal (t , metav1 .ConditionFalse , cond .Status )
583
621
assert .Equal (t , ocv1alpha1 .ReasonResolutionFailed , cond .Reason )
584
- assert .Equal (t , "error upgrading from currently installed version \" 1.0.0\" : no package \" prometheus\" matching version \" 1.2.0\" found in channel \" beta\" " , cond .Message )
622
+ assert .Equal (t , "error upgrading from currently installed version \" 1.0.0\" : no package \" prometheus\" matching version \" 1.2.0\" in channel \" beta\" found " , cond .Message )
585
623
586
624
// Valid update skipping one version
587
625
clusterExtension .Spec .Version = "1.0.1"
@@ -670,6 +708,22 @@ func TestClusterExtensionUpgrade(t *testing.T) {
670
708
err = cl .Update (ctx , clusterExtension )
671
709
require .NoError (t , err )
672
710
711
+ controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
712
+ return & catalogmetadata.Bundle {
713
+ Bundle : declcfg.Bundle {
714
+ Name : "operatorhub/prometheus/beta/1.0.0" ,
715
+ Package : "prometheus" ,
716
+ Image :
"quay.io/operatorhubio/[email protected] " ,
717
+ Properties : []property.Property {
718
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.0"}` )},
719
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
720
+ },
721
+ },
722
+ CatalogName : "fake-catalog" ,
723
+ InChannels : []* catalogmetadata.Channel {& prometheusBetaChannel },
724
+ }, nil
725
+ }
726
+
673
727
// Run reconcile again
674
728
res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
675
729
require .NoError (t , err )
@@ -701,6 +755,11 @@ func TestClusterExtensionDowngrade(t *testing.T) {
701
755
State : source .StatePending ,
702
756
}, nil )
703
757
ctx := context .Background ()
758
+ defer func () {
759
+ controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
760
+ return nil , nil
761
+ }
762
+ }()
704
763
705
764
t .Run ("enforce upgrade constraints" , func (t * testing.T ) {
706
765
for _ , tt := range []struct {
@@ -761,6 +820,22 @@ func TestClusterExtensionDowngrade(t *testing.T) {
761
820
err = cl .Update (ctx , clusterExtension )
762
821
require .NoError (t , err )
763
822
823
+ controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
824
+ return & catalogmetadata.Bundle {
825
+ Bundle : declcfg.Bundle {
826
+ Name : "operatorhub/prometheus/beta/1.0.1" ,
827
+ Package : "prometheus" ,
828
+ Image :
"quay.io/operatorhubio/[email protected] " ,
829
+ Properties : []property.Property {
830
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.1"}` )},
831
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
832
+ },
833
+ },
834
+ CatalogName : "fake-catalog" ,
835
+ InChannels : []* catalogmetadata.Channel {& prometheusBetaChannel },
836
+ }, nil
837
+ }
838
+
764
839
// Run reconcile again
765
840
res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
766
841
require .Error (t , err )
@@ -779,7 +854,7 @@ func TestClusterExtensionDowngrade(t *testing.T) {
779
854
require .NotNil (t , cond )
780
855
assert .Equal (t , metav1 .ConditionFalse , cond .Status )
781
856
assert .Equal (t , ocv1alpha1 .ReasonResolutionFailed , cond .Reason )
782
- assert .Equal (t , "error upgrading from currently installed version \" 1.0.1\" : no package \" prometheus\" matching version \" 1.0.0\" found in channel \" beta\" " , cond .Message )
857
+ assert .Equal (t , "error upgrading from currently installed version \" 1.0.1\" : no package \" prometheus\" matching version \" 1.0.0\" in channel \" beta\" found " , cond .Message )
783
858
})
784
859
}
785
860
})
@@ -844,6 +919,22 @@ func TestClusterExtensionDowngrade(t *testing.T) {
844
919
err = cl .Update (ctx , clusterExtension )
845
920
require .NoError (t , err )
846
921
922
+ controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
923
+ return & catalogmetadata.Bundle {
924
+ Bundle : declcfg.Bundle {
925
+ Name : "operatorhub/prometheus/beta/2.0.0" ,
926
+ Package : "prometheus" ,
927
+ Image :
"quay.io/operatorhubio/[email protected] " ,
928
+ Properties : []property.Property {
929
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"2.0.0"}` )},
930
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
931
+ },
932
+ },
933
+ CatalogName : "fake-catalog" ,
934
+ InChannels : []* catalogmetadata.Channel {& prometheusBetaChannel },
935
+ }, nil
936
+ }
937
+
847
938
// Run reconcile again
848
939
res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
849
940
require .NoError (t , err )
0 commit comments