@@ -19,7 +19,6 @@ 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"
23
22
"github.com/operator-framework/operator-registry/alpha/declcfg"
24
23
"github.com/operator-framework/operator-registry/alpha/property"
25
24
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
@@ -34,7 +33,7 @@ import (
34
33
35
34
// Describe: ClusterExtension Controller Test
36
35
func TestClusterExtensionDoesNotExist (t * testing.T ) {
37
- _ , reconciler := newClientAndReconciler (t )
36
+ _ , reconciler := newClientAndReconciler (t , nil )
38
37
39
38
t .Log ("When the cluster extension does not exist" )
40
39
t .Log ("It returns no error" )
@@ -44,7 +43,7 @@ func TestClusterExtensionDoesNotExist(t *testing.T) {
44
43
}
45
44
46
45
func TestClusterExtensionNonExistentPackage (t * testing.T ) {
47
- cl , reconciler := newClientAndReconciler (t )
46
+ cl , reconciler := newClientAndReconciler (t , nil )
48
47
ctx := context .Background ()
49
48
extKey := types.NamespacedName {Name : fmt .Sprintf ("cluster-extension-test-%s" , rand .String (8 ))}
50
49
@@ -85,7 +84,7 @@ func TestClusterExtensionNonExistentPackage(t *testing.T) {
85
84
}
86
85
87
86
func TestClusterExtensionNonExistentVersion (t * testing.T ) {
88
- cl , reconciler := newClientAndReconciler (t )
87
+ cl , reconciler := newClientAndReconciler (t , nil )
89
88
ctx := context .Background ()
90
89
extKey := types.NamespacedName {Name : fmt .Sprintf ("cluster-extension-test-%s" , rand .String (8 ))}
91
90
@@ -130,7 +129,7 @@ func TestClusterExtensionNonExistentVersion(t *testing.T) {
130
129
}
131
130
132
131
func TestClusterExtensionChannelVersionExists (t * testing.T ) {
133
- cl , reconciler := newClientAndReconciler (t )
132
+ cl , reconciler := newClientAndReconciler (t , nil )
134
133
mockUnpacker := unpacker .(* MockUnpacker )
135
134
// Set up the Unpack method to return a result with StateUnpacked
136
135
mockUnpacker .On ("Unpack" , mock .Anything , mock .AnythingOfType ("*v1alpha2.BundleDeployment" )).Return (& source.Result {
@@ -189,7 +188,7 @@ func TestClusterExtensionChannelVersionExists(t *testing.T) {
189
188
}
190
189
191
190
func TestClusterExtensionChannelExistsNoVersion (t * testing.T ) {
192
- cl , reconciler := newClientAndReconciler (t )
191
+ cl , reconciler := newClientAndReconciler (t , nil )
193
192
mockUnpacker := unpacker .(* MockUnpacker )
194
193
// Set up the Unpack method to return a result with StateUnpacked
195
194
mockUnpacker .On ("Unpack" , mock .Anything , mock .AnythingOfType ("*v1alpha2.BundleDeployment" )).Return (& source.Result {
@@ -248,7 +247,7 @@ func TestClusterExtensionChannelExistsNoVersion(t *testing.T) {
248
247
}
249
248
250
249
func TestClusterExtensionVersionNoChannel (t * testing.T ) {
251
- cl , reconciler := newClientAndReconciler (t )
250
+ cl , reconciler := newClientAndReconciler (t , nil )
252
251
ctx := context .Background ()
253
252
extKey := types.NamespacedName {Name : fmt .Sprintf ("cluster-extension-test-%s" , rand .String (8 ))}
254
253
@@ -298,7 +297,7 @@ func TestClusterExtensionVersionNoChannel(t *testing.T) {
298
297
}
299
298
300
299
func TestClusterExtensionNoChannel (t * testing.T ) {
301
- cl , reconciler := newClientAndReconciler (t )
300
+ cl , reconciler := newClientAndReconciler (t , nil )
302
301
ctx := context .Background ()
303
302
extKey := types.NamespacedName {Name : fmt .Sprintf ("cluster-extension-test-%s" , rand .String (8 ))}
304
303
@@ -345,7 +344,7 @@ func TestClusterExtensionNoChannel(t *testing.T) {
345
344
}
346
345
347
346
func TestClusterExtensionNoVersion (t * testing.T ) {
348
- cl , reconciler := newClientAndReconciler (t )
347
+ cl , reconciler := newClientAndReconciler (t , nil )
349
348
ctx := context .Background ()
350
349
extKey := types.NamespacedName {Name : fmt .Sprintf ("cluster-extension-test-%s" , rand .String (8 ))}
351
350
@@ -416,18 +415,28 @@ func verifyConditionsInvariants(t *testing.T, ext *ocv1alpha1.ClusterExtension)
416
415
}
417
416
418
417
func TestClusterExtensionUpgrade (t * testing.T ) {
419
- cl , reconciler := newClientAndReconciler (t )
418
+ bundle := & catalogmetadata.Bundle {
419
+ Bundle : declcfg.Bundle {
420
+ Name : "operatorhub/prometheus/beta/1.0.0" ,
421
+ Package : "prometheus" ,
422
+ Image :
"quay.io/operatorhubio/[email protected] " ,
423
+ Properties : []property.Property {
424
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.0"}` )},
425
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
426
+ },
427
+ },
428
+ CatalogName : "fake-catalog" ,
429
+ InChannels : []* catalogmetadata.Channel {& prometheusBetaChannel },
430
+ }
431
+
432
+ cl , reconciler := newClientAndReconciler (t , bundle )
433
+
420
434
mockUnpacker := unpacker .(* MockUnpacker )
421
435
// Set up the Unpack method to return a result with StateUnpackPending
422
436
mockUnpacker .On ("Unpack" , mock .Anything , mock .AnythingOfType ("*v1alpha2.BundleDeployment" )).Return (& source.Result {
423
437
State : source .StatePending ,
424
438
}, nil )
425
439
ctx := context .Background ()
426
- defer func () {
427
- controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
428
- return nil , nil
429
- }
430
- }()
431
440
432
441
t .Run ("semver upgrade constraints enforcement of upgrades within major version" , func (t * testing.T ) {
433
442
defer featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .ForceSemverUpgradeConstraints , true )()
@@ -477,22 +486,21 @@ func TestClusterExtensionUpgrade(t *testing.T) {
477
486
err = cl .Update (ctx , clusterExtension )
478
487
require .NoError (t , err )
479
488
480
- controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
481
- return & catalogmetadata.Bundle {
482
- Bundle : declcfg.Bundle {
483
- Name : "operatorhub/prometheus/beta/1.0.0" ,
484
- Package : "prometheus" ,
485
- Image :
"quay.io/operatorhubio/[email protected] " ,
486
- Properties : []property.Property {
487
- {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.0"}` )},
488
- {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
489
- },
489
+ bundle := & catalogmetadata.Bundle {
490
+ Bundle : declcfg.Bundle {
491
+ Name : "operatorhub/prometheus/beta/1.0.0" ,
492
+ Package : "prometheus" ,
493
+ Image :
"quay.io/operatorhubio/[email protected] " ,
494
+ Properties : []property.Property {
495
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.0"}` )},
496
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
490
497
},
491
- CatalogName : "fake-catalog" ,
492
- InChannels : [] * catalogmetadata. Channel { & prometheusBetaChannel } ,
493
- }, nil
498
+ } ,
499
+ CatalogName : "fake-catalog" ,
500
+ InChannels : [] * catalogmetadata. Channel { & prometheusBetaChannel },
494
501
}
495
502
503
+ cl , reconciler := newClientAndReconciler (t , bundle )
496
504
// Run reconcile again
497
505
res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
498
506
require .Error (t , err )
@@ -586,22 +594,22 @@ func TestClusterExtensionUpgrade(t *testing.T) {
586
594
err = cl .Update (ctx , clusterExtension )
587
595
require .NoError (t , err )
588
596
589
- controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
590
- return & catalogmetadata.Bundle {
591
- Bundle : declcfg.Bundle {
592
- Name : "operatorhub/prometheus/beta/1.0.0" ,
593
- Package : "prometheus" ,
594
- Image :
"quay.io/operatorhubio/[email protected] " ,
595
- Properties : []property.Property {
596
- {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.0"}` )},
597
- {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
598
- },
597
+ bundle := & catalogmetadata.Bundle {
598
+ Bundle : declcfg.Bundle {
599
+ Name : "operatorhub/prometheus/beta/1.0.0" ,
600
+ Package : "prometheus" ,
601
+ Image :
"quay.io/operatorhubio/[email protected] " ,
602
+ Properties : []property.Property {
603
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.0"}` )},
604
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
599
605
},
600
- CatalogName : "fake-catalog" ,
601
- InChannels : [] * catalogmetadata. Channel { & prometheusBetaChannel } ,
602
- }, nil
606
+ } ,
607
+ CatalogName : "fake-catalog" ,
608
+ InChannels : [] * catalogmetadata. Channel { & prometheusBetaChannel },
603
609
}
604
610
611
+ cl , reconciler := newClientAndReconciler (t , bundle )
612
+
605
613
// Run reconcile again
606
614
res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
607
615
require .Error (t , err )
@@ -709,22 +717,22 @@ func TestClusterExtensionUpgrade(t *testing.T) {
709
717
err = cl .Update (ctx , clusterExtension )
710
718
require .NoError (t , err )
711
719
712
- controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
713
- return & catalogmetadata.Bundle {
714
- Bundle : declcfg.Bundle {
715
- Name : "operatorhub/prometheus/beta/1.0.0" ,
716
- Package : "prometheus" ,
717
- Image :
"quay.io/operatorhubio/[email protected] " ,
718
- Properties : []property.Property {
719
- {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.0"}` )},
720
- {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
721
- },
720
+ bundle := & catalogmetadata.Bundle {
721
+ Bundle : declcfg.Bundle {
722
+ Name : "operatorhub/prometheus/beta/1.0.0" ,
723
+ Package : "prometheus" ,
724
+ Image :
"quay.io/operatorhubio/[email protected] " ,
725
+ Properties : []property.Property {
726
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.0"}` )},
727
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
722
728
},
723
- CatalogName : "fake-catalog" ,
724
- InChannels : [] * catalogmetadata. Channel { & prometheusBetaChannel } ,
725
- }, nil
729
+ } ,
730
+ CatalogName : "fake-catalog" ,
731
+ InChannels : [] * catalogmetadata. Channel { & prometheusBetaChannel },
726
732
}
727
733
734
+ cl , reconciler := newClientAndReconciler (t , bundle )
735
+
728
736
// Run reconcile again
729
737
res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
730
738
require .NoError (t , err )
@@ -749,18 +757,13 @@ func TestClusterExtensionUpgrade(t *testing.T) {
749
757
}
750
758
751
759
func TestClusterExtensionDowngrade (t * testing.T ) {
752
- cl , reconciler := newClientAndReconciler (t )
760
+ cl , reconciler := newClientAndReconciler (t , nil )
753
761
mockUnpacker := unpacker .(* MockUnpacker )
754
762
// Set up the Unpack method to return a result with StateUnpacked
755
763
mockUnpacker .On ("Unpack" , mock .Anything , mock .AnythingOfType ("*v1alpha2.BundleDeployment" )).Return (& source.Result {
756
764
State : source .StatePending ,
757
765
}, nil )
758
766
ctx := context .Background ()
759
- defer func () {
760
- controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
761
- return nil , nil
762
- }
763
- }()
764
767
765
768
t .Run ("enforce upgrade constraints" , func (t * testing.T ) {
766
769
for _ , tt := range []struct {
@@ -821,22 +824,22 @@ func TestClusterExtensionDowngrade(t *testing.T) {
821
824
err = cl .Update (ctx , clusterExtension )
822
825
require .NoError (t , err )
823
826
824
- controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
825
- return & catalogmetadata.Bundle {
826
- Bundle : declcfg.Bundle {
827
- Name : "operatorhub/prometheus/beta/1.0.1" ,
828
- Package : "prometheus" ,
829
- Image :
"quay.io/operatorhubio/[email protected] " ,
830
- Properties : []property.Property {
831
- {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.1"}` )},
832
- {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
833
- },
827
+ bundle := & catalogmetadata.Bundle {
828
+ Bundle : declcfg.Bundle {
829
+ Name : "operatorhub/prometheus/beta/1.0.1" ,
830
+ Package : "prometheus" ,
831
+ Image :
"quay.io/operatorhubio/[email protected] " ,
832
+ Properties : []property.Property {
833
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"1.0.1"}` )},
834
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
834
835
},
835
- CatalogName : "fake-catalog" ,
836
- InChannels : [] * catalogmetadata. Channel { & prometheusBetaChannel } ,
837
- }, nil
836
+ } ,
837
+ CatalogName : "fake-catalog" ,
838
+ InChannels : [] * catalogmetadata. Channel { & prometheusBetaChannel },
838
839
}
839
840
841
+ cl , reconciler := newClientAndReconciler (t , bundle )
842
+
840
843
// Run reconcile again
841
844
res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
842
845
require .Error (t , err )
@@ -920,22 +923,22 @@ func TestClusterExtensionDowngrade(t *testing.T) {
920
923
err = cl .Update (ctx , clusterExtension )
921
924
require .NoError (t , err )
922
925
923
- controllers .GetInstalledbundle = func (ctx context.Context , acg helmclient.ActionClientGetter , allBundles []* catalogmetadata.Bundle , ext * ocv1alpha1.ClusterExtension ) (* catalogmetadata.Bundle , error ) {
924
- return & catalogmetadata.Bundle {
925
- Bundle : declcfg.Bundle {
926
- Name : "operatorhub/prometheus/beta/2.0.0" ,
927
- Package : "prometheus" ,
928
- Image :
"quay.io/operatorhubio/[email protected] " ,
929
- Properties : []property.Property {
930
- {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"2.0.0"}` )},
931
- {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
932
- },
926
+ bundle := & catalogmetadata.Bundle {
927
+ Bundle : declcfg.Bundle {
928
+ Name : "operatorhub/prometheus/beta/2.0.0" ,
929
+ Package : "prometheus" ,
930
+ Image :
"quay.io/operatorhubio/[email protected] " ,
931
+ Properties : []property.Property {
932
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"2.0.0"}` )},
933
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
933
934
},
934
- CatalogName : "fake-catalog" ,
935
- InChannels : [] * catalogmetadata. Channel { & prometheusBetaChannel } ,
936
- }, nil
935
+ } ,
936
+ CatalogName : "fake-catalog" ,
937
+ InChannels : [] * catalogmetadata. Channel { & prometheusBetaChannel },
937
938
}
938
939
940
+ cl , reconciler := newClientAndReconciler (t , bundle )
941
+
939
942
// Run reconcile again
940
943
res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
941
944
require .NoError (t , err )
0 commit comments