@@ -100,6 +100,19 @@ func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.Mong
100100 if search .Spec .LogLevel != "" {
101101 logLevel = string (search .Spec .LogLevel )
102102 }
103+
104+ var wireprotoServer * mongot.ConfigWireproto
105+ if search .IsWireprotoForced () {
106+ wireprotoServer = & mongot.ConfigWireproto {
107+ Address : fmt .Sprintf ("0.0.0.0:%d" , search .GetMongotWireprotoPort ()),
108+ Authentication : & mongot.ConfigAuthentication {
109+ Mode : "keyfile" ,
110+ KeyFile : searchcontroller .TempKeyfilePath ,
111+ },
112+ TLS : & mongot.ConfigWireprotoTLS {Mode : mongot .ConfigTLSModeDisabled },
113+ }
114+ }
115+
103116 return mongot.Config {
104117 SyncSource : mongot.ConfigSyncSource {
105118 ReplicaSet : mongot.ConfigReplicaSet {
@@ -119,6 +132,7 @@ func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.Mong
119132 Address : fmt .Sprintf ("0.0.0.0:%d" , search .GetMongotGrpcPort ()),
120133 TLS : & mongot.ConfigGrpcTLS {Mode : mongot .ConfigTLSModeDisabled },
121134 },
135+ Wireproto : wireprotoServer ,
122136 },
123137 Metrics : mongot.ConfigMetrics {
124138 Enabled : true ,
@@ -164,35 +178,69 @@ func TestMongoDBSearchReconcile_MissingSource(t *testing.T) {
164178
165179func TestMongoDBSearchReconcile_Success (t * testing.T ) {
166180 ctx := context .Background ()
167- search := newMongoDBSearch ("search" , mock .TestNamespace , "mdb" )
168- search .Spec .LogLevel = "WARN"
169-
170- mdbc := newMongoDBCommunity ("mdb" , mock .TestNamespace )
171- reconciler , c := newSearchReconciler (mdbc , search )
172181
173- res , err := reconciler .Reconcile (
174- ctx ,
175- reconcile.Request {NamespacedName : types.NamespacedName {Name : search .Name , Namespace : search .Namespace }},
176- )
177- expected , _ := workflow .OK ().ReconcileResult ()
178- assert .NoError (t , err )
179- assert .Equal (t , expected , res )
180-
181- svc := & corev1.Service {}
182- err = c .Get (ctx , search .SearchServiceNamespacedName (), svc )
183- assert .NoError (t , err )
182+ tests := []struct {
183+ name string
184+ withWireproto bool
185+ }{
186+ {
187+ name : "grpc only (default)" ,
188+ withWireproto : false ,
189+ },
190+ {
191+ name : "grpc + wireproto via annotation" ,
192+ withWireproto : true ,
193+ },
194+ }
184195
185- cm := & corev1.ConfigMap {}
186- err = c .Get (ctx , search .MongotConfigConfigMapNamespacedName (), cm )
187- assert .NoError (t , err )
188- expectedConfig := buildExpectedMongotConfig (search , mdbc )
189- configYaml , err := yaml .Marshal (expectedConfig )
190- assert .NoError (t , err )
191- assert .Equal (t , string (configYaml ), cm .Data [searchcontroller .MongotConfigFilename ])
196+ for _ , tc := range tests {
197+ t .Run (tc .name , func (t * testing.T ) {
198+ search := newMongoDBSearch ("search" , mock .TestNamespace , "mdb" )
199+ search .Spec .LogLevel = "WARN"
200+ if tc .withWireproto {
201+ if search .Annotations == nil {
202+ search .Annotations = map [string ]string {}
203+ }
204+ search .Annotations [searchv1 .ForceWireprotoTransportAnnotation ] = "true"
205+ }
192206
193- sts := & appsv1.StatefulSet {}
194- err = c .Get (ctx , search .StatefulSetNamespacedName (), sts )
195- assert .NoError (t , err )
207+ mdbc := newMongoDBCommunity ("mdb" , mock .TestNamespace )
208+ reconciler , c := newSearchReconciler (mdbc , search )
209+
210+ res , err := reconciler .Reconcile (
211+ ctx ,
212+ reconcile.Request {NamespacedName : types.NamespacedName {Name : search .Name , Namespace : search .Namespace }},
213+ )
214+ expected , _ := workflow .OK ().ReconcileResult ()
215+ assert .NoError (t , err )
216+ assert .Equal (t , expected , res )
217+
218+ svc := & corev1.Service {}
219+ err = c .Get (ctx , search .SearchServiceNamespacedName (), svc )
220+ assert .NoError (t , err )
221+ servicePortNames := []string {}
222+ for _ , port := range svc .Spec .Ports {
223+ servicePortNames = append (servicePortNames , port .Name )
224+ }
225+ expectedPortNames := []string {"mongot-grpc" , "metrics" , "healthcheck" }
226+ if tc .withWireproto {
227+ expectedPortNames = append (expectedPortNames , "mongot-wireproto" )
228+ }
229+ assert .ElementsMatch (t , expectedPortNames , servicePortNames )
230+
231+ cm := & corev1.ConfigMap {}
232+ err = c .Get (ctx , search .MongotConfigConfigMapNamespacedName (), cm )
233+ assert .NoError (t , err )
234+ expectedConfig := buildExpectedMongotConfig (search , mdbc )
235+ configYaml , err := yaml .Marshal (expectedConfig )
236+ assert .NoError (t , err )
237+ assert .Equal (t , string (configYaml ), cm .Data [searchcontroller .MongotConfigFilename ])
238+
239+ sts := & appsv1.StatefulSet {}
240+ err = c .Get (ctx , search .StatefulSetNamespacedName (), sts )
241+ assert .NoError (t , err )
242+ })
243+ }
196244}
197245
198246func checkSearchReconcileFailed (
0 commit comments