@@ -3,9 +3,13 @@ package controllers_test
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "strings"
7
+ "time"
6
8
9
+ "github.com/go-logr/logr/funcr"
7
10
. "github.com/onsi/ginkgo/v2"
8
11
. "github.com/onsi/gomega"
12
+ catalogd "github.com/operator-framework/catalogd/pkg/apis/core/v1beta1"
9
13
"github.com/operator-framework/deppy/pkg/deppy"
10
14
"github.com/operator-framework/deppy/pkg/deppy/input"
11
15
"github.com/operator-framework/deppy/pkg/deppy/solver"
@@ -18,6 +22,7 @@ import (
18
22
ctrl "sigs.k8s.io/controller-runtime"
19
23
"sigs.k8s.io/controller-runtime/pkg/client"
20
24
"sigs.k8s.io/controller-runtime/pkg/client/fake"
25
+ "sigs.k8s.io/controller-runtime/pkg/log"
21
26
22
27
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
23
28
"github.com/operator-framework/operator-controller/internal/conditionsets"
@@ -1057,6 +1062,94 @@ var _ = Describe("Operator Controller Test", func() {
1057
1062
})
1058
1063
})
1059
1064
})
1065
+ When ("a catalog changes on cluster" , func () {
1066
+ var testLogs , opNames []string
1067
+ var cancel context.CancelFunc
1068
+ var logCount int
1069
+ BeforeEach (func () {
1070
+ l := funcr .New (func (prefix , args string ) {
1071
+ if prefix == "operator-controller" &&
1072
+ strings .Contains (args , `"controller"="operator"` ) &&
1073
+ strings .Contains (args , `"msg"="ending"` ) {
1074
+ // filter for only relevant logs
1075
+ testLogs = append (testLogs , fmt .Sprintf ("%s" , args ))
1076
+ }
1077
+ }, funcr.Options {Verbosity : 1 })
1078
+ mgr , err := ctrl .NewManager (cfg , ctrl.Options {Scheme : sch , Logger : l })
1079
+ Expect (err ).To (BeNil ())
1080
+
1081
+ err = reconciler .SetupWithManager (mgr )
1082
+ Expect (err ).To (BeNil ())
1083
+ var mgrCtx context.Context
1084
+ mgrCtx , cancel = context .WithCancel (log .IntoContext (ctx , l ))
1085
+
1086
+ go func () {
1087
+ err := mgr .Start (mgrCtx )
1088
+ Expect (err ).To (BeNil ())
1089
+ }()
1090
+
1091
+ opNames = []string {"prometheus" , "project-quay" }
1092
+ for _ , p := range opNames {
1093
+ op := & operatorsv1alpha1.Operator {ObjectMeta : metav1.ObjectMeta {Name : p }, Spec : operatorsv1alpha1.OperatorSpec {PackageName : p }}
1094
+ err := cl .Create (ctx , op )
1095
+ Expect (err ).To (BeNil ())
1096
+ }
1097
+ Eventually (func (g Gomega ) {
1098
+ By ("verifying initial reconcile logs for operator creation" )
1099
+ g .Expect (len (testLogs ) >= len (opNames )).To (BeTrue ())
1100
+ for _ , p := range opNames {
1101
+ g .Expect (testLogs [len (testLogs )- len (opNames ):]).To (ContainElement (ContainSubstring (fmt .Sprintf ("\" Operator\" ={\" name\" :\" %s\" }" , p ))))
1102
+ }
1103
+ logCount = len (testLogs )
1104
+ }).WithTimeout (2 * time .Second ).WithPolling (1 * time .Second ).WithArguments ().Should (Succeed ())
1105
+ })
1106
+
1107
+ It ("reconciles all affected operators on cluster" , func () {
1108
+ By ("creating a new catalog" )
1109
+ catalog := & catalogd.Catalog {ObjectMeta : metav1.ObjectMeta {Name : "t" }, Spec : catalogd.CatalogSpec {Source : catalogd.CatalogSource {Type : catalogd .SourceTypeImage , Image : & catalogd.ImageSource {}}}}
1110
+ err := cl .Create (ctx , catalog )
1111
+ Expect (err ).To (BeNil ())
1112
+ Eventually (func (g Gomega ) {
1113
+ By ("verifying operator reconcile logs on catalog create" )
1114
+ g .Expect (len (testLogs )).To (Equal (logCount + len (opNames )))
1115
+ for _ , p := range opNames {
1116
+ g .Expect (testLogs [len (testLogs )- len (opNames ):]).To (ContainElement (ContainSubstring (fmt .Sprintf ("\" Operator\" ={\" name\" :\" %s\" }" , p ))))
1117
+ }
1118
+ logCount = len (testLogs )
1119
+ }).WithTimeout (2 * time .Second ).WithPolling (1 * time .Second ).WithArguments ().Should (Succeed ())
1120
+
1121
+ By ("updating a catalog" )
1122
+ catalog .Spec .Source .Image .Ref = "s"
1123
+ err = cl .Update (ctx , catalog )
1124
+ Expect (err ).To (BeNil ())
1125
+ Eventually (func (g Gomega ) {
1126
+ By ("verifying operator reconcile logs on catalog update" )
1127
+ g .Expect (len (testLogs )).To (Equal (logCount + len (opNames )))
1128
+ for _ , p := range opNames {
1129
+ g .Expect (testLogs [len (testLogs )- len (opNames ):]).To (ContainElement (ContainSubstring (fmt .Sprintf ("\" Operator\" ={\" name\" :\" %s\" }" , p ))))
1130
+ }
1131
+ logCount = len (testLogs )
1132
+ }).WithTimeout (2 * time .Second ).WithPolling (1 * time .Second ).WithArguments ().Should (Succeed ())
1133
+
1134
+ By ("deleting a catalog" )
1135
+ err = cl .Delete (ctx , catalog )
1136
+ Expect (err ).To (BeNil ())
1137
+ Eventually (func (g Gomega ) {
1138
+ By ("verifying operator reconcile logs on catalog delete" )
1139
+ g .Expect (len (testLogs )).To (Equal (logCount + len (opNames )))
1140
+ for _ , p := range opNames {
1141
+ g .Expect (testLogs [len (testLogs )- len (opNames ):]).To (ContainElement (ContainSubstring (fmt .Sprintf ("\" Operator\" ={\" name\" :\" %s\" }" , p ))))
1142
+ }
1143
+ }).WithTimeout (2 * time .Second ).WithPolling (1 * time .Second ).WithArguments ().Should (Succeed ())
1144
+ })
1145
+ AfterEach (func () {
1146
+ for _ , p := range opNames {
1147
+ op := & operatorsv1alpha1.Operator {ObjectMeta : metav1.ObjectMeta {Name : p }, Spec : operatorsv1alpha1.OperatorSpec {PackageName : p }}
1148
+ Expect (cl .Delete (ctx , op )).To (BeNil ())
1149
+ }
1150
+ cancel () // stop manager
1151
+ })
1152
+ })
1060
1153
})
1061
1154
1062
1155
func verifyInvariants (ctx context.Context , c client.Client , op * operatorsv1alpha1.Operator ) {
@@ -1095,6 +1188,12 @@ var testEntitySource = input.NewCacheQuerier(map[deppy.Identifier]input.Entity{
1095
1188
"olm.package" : `{"packageName":"prometheus","version":"0.47.0"}` ,
1096
1189
"olm.gvk" : `[]` ,
1097
1190
}),
1191
+ "operatorhub/project-quay/3.8.3" : * input .NewEntity ("operatorhub/project-quay/3.8.3" , map [string ]string {
1192
+ "olm.bundle.path" : `"quay.io/openshift-community-operators/project-quay@sha256:4f5698b5fec2e5f9a4df78b5ef9609b3a697c81cdb137b98e82e79104f0eb3b5"` ,
1193
+ "olm.channel" : `{"channelName":"stable","priority":0}` ,
1194
+ "olm.package" : `{"packageName":"project-quay","version":"3.8.3"}` ,
1195
+ "olm.gvk" : `[]` ,
1196
+ }),
1098
1197
"operatorhub/badimage/0.1.0" : * input .NewEntity ("operatorhub/badimage/0.1.0" , map [string ]string {
1099
1198
"olm.bundle.path" : `{"name": "quay.io/operatorhubio/badimage:v0.1.0"}` ,
1100
1199
"olm.package" : `{"packageName":"badimage","version":"0.1.0"}` ,
0 commit comments