@@ -19,6 +19,7 @@ import (
1919 ctrl "sigs.k8s.io/controller-runtime"
2020 "sigs.k8s.io/controller-runtime/pkg/client"
2121
22+ helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
2223 "github.com/operator-framework/operator-registry/alpha/declcfg"
2324 "github.com/operator-framework/operator-registry/alpha/property"
2425 rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
@@ -416,11 +417,16 @@ func verifyConditionsInvariants(t *testing.T, ext *ocv1alpha1.ClusterExtension)
416417func TestClusterExtensionUpgrade (t * testing.T ) {
417418 cl , reconciler := newClientAndReconciler (t )
418419 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
420421 mockUnpacker .On ("Unpack" , mock .Anything , mock .AnythingOfType ("*v1alpha2.BundleDeployment" )).Return (& source.Result {
421422 State : source .StatePending ,
422423 }, nil )
423424 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+ }()
424430
425431 t .Run ("semver upgrade constraints enforcement of upgrades within major version" , func (t * testing.T ) {
426432 defer featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .ForceSemverUpgradeConstraints , true )()
@@ -470,6 +476,22 @@ func TestClusterExtensionUpgrade(t *testing.T) {
470476 err = cl .Update (ctx , clusterExtension )
471477 require .NoError (t , err )
472478
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+
473495 // Run reconcile again
474496 res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
475497 require .Error (t , err )
@@ -488,7 +510,7 @@ func TestClusterExtensionUpgrade(t *testing.T) {
488510 require .NotNil (t , cond )
489511 assert .Equal (t , metav1 .ConditionFalse , cond .Status )
490512 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 )
492514
493515 // Valid update skipping one version
494516 clusterExtension .Spec .Version = "1.2.0"
@@ -563,6 +585,22 @@ func TestClusterExtensionUpgrade(t *testing.T) {
563585 err = cl .Update (ctx , clusterExtension )
564586 require .NoError (t , err )
565587
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+
566604 // Run reconcile again
567605 res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
568606 require .Error (t , err )
@@ -581,7 +619,7 @@ func TestClusterExtensionUpgrade(t *testing.T) {
581619 require .NotNil (t , cond )
582620 assert .Equal (t , metav1 .ConditionFalse , cond .Status )
583621 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 )
585623
586624 // Valid update skipping one version
587625 clusterExtension .Spec .Version = "1.0.1"
@@ -670,6 +708,22 @@ func TestClusterExtensionUpgrade(t *testing.T) {
670708 err = cl .Update (ctx , clusterExtension )
671709 require .NoError (t , err )
672710
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+
673727 // Run reconcile again
674728 res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
675729 require .NoError (t , err )
@@ -701,6 +755,11 @@ func TestClusterExtensionDowngrade(t *testing.T) {
701755 State : source .StatePending ,
702756 }, nil )
703757 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+ }()
704763
705764 t .Run ("enforce upgrade constraints" , func (t * testing.T ) {
706765 for _ , tt := range []struct {
@@ -761,6 +820,22 @@ func TestClusterExtensionDowngrade(t *testing.T) {
761820 err = cl .Update (ctx , clusterExtension )
762821 require .NoError (t , err )
763822
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+
764839 // Run reconcile again
765840 res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
766841 require .Error (t , err )
@@ -779,7 +854,7 @@ func TestClusterExtensionDowngrade(t *testing.T) {
779854 require .NotNil (t , cond )
780855 assert .Equal (t , metav1 .ConditionFalse , cond .Status )
781856 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 )
783858 })
784859 }
785860 })
@@ -844,6 +919,22 @@ func TestClusterExtensionDowngrade(t *testing.T) {
844919 err = cl .Update (ctx , clusterExtension )
845920 require .NoError (t , err )
846921
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+
847938 // Run reconcile again
848939 res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
849940 require .NoError (t , err )
0 commit comments