@@ -3,10 +3,7 @@ package controllers_test
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "strings"
7
- "time"
8
6
9
- "github.com/go-logr/logr/funcr"
10
7
. "github.com/onsi/ginkgo/v2"
11
8
. "github.com/onsi/gomega"
12
9
catalogd "github.com/operator-framework/catalogd/pkg/apis/core/v1beta1"
@@ -25,7 +22,7 @@ import (
25
22
ctrl "sigs.k8s.io/controller-runtime"
26
23
"sigs.k8s.io/controller-runtime/pkg/client"
27
24
"sigs.k8s.io/controller-runtime/pkg/client/fake"
28
- "sigs.k8s.io/controller-runtime/pkg/log "
25
+ "sigs.k8s.io/controller-runtime/pkg/reconcile "
29
26
)
30
27
31
28
var _ = Describe ("Operator Controller Test" , func () {
@@ -1023,25 +1020,24 @@ var _ = Describe("Operator Controller Test", func() {
1023
1020
})
1024
1021
})
1025
1022
When ("a catalog changes on cluster" , func () {
1026
- var testLogs , opNames []string
1023
+ var reconcileReqs , opNames []string
1027
1024
var cancel context.CancelFunc
1028
1025
var logCount int
1029
1026
BeforeEach (func () {
1030
- l := funcr .New (func (prefix , args string ) {
1031
- if prefix == "operator-controller" &&
1032
- strings .Contains (args , `"controller"="operator"` ) &&
1033
- strings .Contains (args , `"msg"="ending"` ) {
1034
- // filter for only relevant logs
1035
- testLogs = append (testLogs , fmt .Sprintf ("%s" , args ))
1036
- }
1037
- }, funcr.Options {Verbosity : 1 })
1038
- mgr , err := ctrl .NewManager (cfg , ctrl.Options {Scheme : sch , Logger : l })
1027
+ mgr , err := ctrl .NewManager (cfg , ctrl.Options {Scheme : sch })
1039
1028
Expect (err ).To (BeNil ())
1040
1029
1041
- err = reconciler .SetupWithManager (mgr )
1030
+ var fakeReconciler reconcile.Func = func (_ context.Context , request ctrl.Request ) (ctrl.Result , error ) {
1031
+ reconcileReqs = append (reconcileReqs , request .Name )
1032
+ fmt .Println ("RECONCILE" , request .Name )
1033
+ return ctrl.Result {}, nil
1034
+ }
1035
+
1036
+ err = controllers .SetupWithManager (fakeReconciler , mgr )
1042
1037
Expect (err ).To (BeNil ())
1038
+
1043
1039
var mgrCtx context.Context
1044
- mgrCtx , cancel = context .WithCancel (log . IntoContext ( ctx , l ) )
1040
+ mgrCtx , cancel = context .WithCancel (ctx )
1045
1041
1046
1042
go func () {
1047
1043
err := mgr .Start (mgrCtx )
@@ -1056,51 +1052,42 @@ var _ = Describe("Operator Controller Test", func() {
1056
1052
}
1057
1053
Eventually (func (g Gomega ) {
1058
1054
By ("verifying initial reconcile logs for operator creation" )
1059
- g .Expect (len (testLogs ) >= len (opNames )).To (BeTrue ())
1060
- for _ , p := range opNames {
1061
- g .Expect (testLogs [len (testLogs )- len (opNames ):]).To (ContainElement (ContainSubstring (fmt .Sprintf ("\" Operator\" ={\" name\" :\" %s\" }" , p ))))
1062
- }
1063
- logCount = len (testLogs )
1064
- }).WithTimeout (2 * time .Second ).WithPolling (1 * time .Second ).Should (Succeed ())
1055
+ g .Expect (len (reconcileReqs ) >= len (opNames )).To (BeTrue ())
1056
+ g .Expect (reconcileReqs ).To (ContainElements (opNames ))
1057
+ logCount = len (reconcileReqs )
1058
+ }).Should (Succeed ())
1065
1059
})
1066
-
1067
1060
It ("reconciles all affected operators on cluster" , func () {
1068
1061
By ("creating a new catalog" )
1069
1062
catalog := & catalogd.Catalog {ObjectMeta : metav1.ObjectMeta {Name : "t" }, Spec : catalogd.CatalogSpec {Source : catalogd.CatalogSource {Type : catalogd .SourceTypeImage , Image : & catalogd.ImageSource {}}}}
1070
1063
err := cl .Create (ctx , catalog )
1071
1064
Expect (err ).To (BeNil ())
1072
1065
Eventually (func (g Gomega ) {
1073
1066
By ("verifying operator reconcile logs on catalog create" )
1074
- g .Expect (testLogs ).To (HaveLen (logCount + len (opNames )))
1075
- for _ , p := range opNames {
1076
- g .Expect (testLogs [len (testLogs )- len (opNames ):]).To (ContainElement (ContainSubstring (fmt .Sprintf ("\" Operator\" ={\" name\" :\" %s\" }" , p ))))
1077
- }
1078
- logCount = len (testLogs )
1079
- }).WithTimeout (2 * time .Second ).WithPolling (1 * time .Second ).Should (Succeed ())
1067
+ g .Expect (reconcileReqs ).To (HaveLen (logCount + len (opNames )))
1068
+ g .Expect (reconcileReqs [len (reconcileReqs )- len (opNames ):]).To (ConsistOf (opNames ))
1069
+ logCount = len (reconcileReqs )
1070
+ }).Should (Succeed ())
1080
1071
1081
1072
By ("updating a catalog" )
1082
1073
catalog .Spec .Source .Image .Ref = "s"
1083
1074
err = cl .Update (ctx , catalog )
1084
1075
Expect (err ).To (BeNil ())
1085
1076
Eventually (func (g Gomega ) {
1086
1077
By ("verifying operator reconcile logs on catalog update" )
1087
- g .Expect (testLogs ).To (HaveLen (logCount + len (opNames )))
1088
- for _ , p := range opNames {
1089
- g .Expect (testLogs [len (testLogs )- len (opNames ):]).To (ContainElement (ContainSubstring (fmt .Sprintf ("\" Operator\" ={\" name\" :\" %s\" }" , p ))))
1090
- }
1091
- logCount = len (testLogs )
1092
- }).WithTimeout (2 * time .Second ).WithPolling (1 * time .Second ).Should (Succeed ())
1078
+ g .Expect (reconcileReqs ).To (HaveLen (logCount + len (opNames )))
1079
+ g .Expect (reconcileReqs [len (reconcileReqs )- len (opNames ):]).To (ConsistOf (opNames ))
1080
+ logCount = len (reconcileReqs )
1081
+ }).Should (Succeed ())
1093
1082
1094
1083
By ("deleting a catalog" )
1095
1084
err = cl .Delete (ctx , catalog )
1096
1085
Expect (err ).To (BeNil ())
1097
1086
Eventually (func (g Gomega ) {
1098
1087
By ("verifying operator reconcile logs on catalog delete" )
1099
- g .Expect (testLogs ).To (HaveLen (logCount + len (opNames )))
1100
- for _ , p := range opNames {
1101
- g .Expect (testLogs [len (testLogs )- len (opNames ):]).To (ContainElement (ContainSubstring (fmt .Sprintf ("\" Operator\" ={\" name\" :\" %s\" }" , p ))))
1102
- }
1103
- }).WithTimeout (2 * time .Second ).WithPolling (1 * time .Second ).Should (Succeed ())
1088
+ g .Expect (reconcileReqs ).To (HaveLen (logCount + len (opNames )))
1089
+ g .Expect (reconcileReqs [len (reconcileReqs )- len (opNames ):]).To (ConsistOf (opNames ))
1090
+ }).Should (Succeed ())
1104
1091
})
1105
1092
AfterEach (func () {
1106
1093
for _ , p := range opNames {
0 commit comments