Skip to content

Commit ab1718f

Browse files
committed
expand on the wireproto override
1 parent 83d91a0 commit ab1718f

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

api/v1/search/mongodbsearch_types.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,17 @@ func (s *MongoDBSearch) GetLogLevel() mdb.LogLevel {
249249
return s.Spec.LogLevel
250250
}
251251

252-
func (s *MongoDBSearch) IsWireprotoForced() bool {
252+
// mongot configuration defaults to the gRPC server. on rare occasions we might advise users to enable the legacy
253+
// wireproto server. Once the deprecated wireproto server is removed, this function, annotation, and all code guarded
254+
// by this check should be removed.
255+
func (s *MongoDBSearch) IsWireprotoEnabled() bool {
253256
val, ok := s.Annotations[ForceWireprotoTransportAnnotation]
254257
return ok && val == "true"
255258
}
259+
260+
func (s *MongoDBSearch) GetEffectiveMongotPort() int32 {
261+
if s.IsWireprotoEnabled() {
262+
return s.GetMongotWireprotoPort()
263+
}
264+
return s.GetMongotGrpcPort()
265+
}

controllers/operator/mongodbsearch_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (r *MongoDBSearchReconciler) Reconcile(ctx context.Context, request reconci
5757
return reconcile.Result{RequeueAfter: time.Second * util.RetryTimeSec}, err
5858
}
5959

60-
if mdbSearch.IsWireprotoForced() {
60+
if mdbSearch.IsWireprotoEnabled() {
6161
log.Info("Enabling the mongot wireproto server as required by annotation")
6262
// the keyfile secret is necessary for wireproto authentication
6363
r.watch.AddWatchedResourceIfNotAdded(searchSource.KeyfileSecretName(), mdbSearch.Namespace, watch.Secret, mdbSearch.NamespacedName())

controllers/operator/mongodbsearch_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.Mong
103103
}
104104

105105
var wireprotoServer *mongot.ConfigWireproto
106-
if search.IsWireprotoForced() {
106+
if search.IsWireprotoEnabled() {
107107
wireprotoServer = &mongot.ConfigWireproto{
108108
Address: fmt.Sprintf("0.0.0.0:%d", search.GetMongotWireprotoPort()),
109109
Authentication: &mongot.ConfigAuthentication{

controllers/searchcontroller/mongodbsearch_reconcile_helper.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (r *MongoDBSearchReconcileHelper) reconcile(ctx context.Context, log *zap.S
9898
}
9999

100100
keyfileStsModification := statefulset.NOOP()
101-
if r.mdbSearch.IsWireprotoForced() {
101+
if r.mdbSearch.IsWireprotoEnabled() {
102102
var err error
103103
keyfileStsModification, err = r.ensureSourceKeyfile(ctx, log)
104104
if apierrors.IsNotFound(err) {
@@ -317,7 +317,7 @@ func buildSearchHeadlessService(search *searchv1.MongoDBSearch) corev1.Service {
317317
SetPublishNotReadyAddresses(true).
318318
SetOwnerReferences(search.GetOwnerReferences())
319319

320-
if search.IsWireprotoForced() {
320+
if search.IsWireprotoEnabled() {
321321
serviceBuilder.AddPort(&corev1.ServicePort{
322322
Name: "mongot-wireproto",
323323
Protocol: corev1.ProtocolTCP,
@@ -375,7 +375,7 @@ func createMongotConfig(search *searchv1.MongoDBSearch, db SearchSourceDBResourc
375375
},
376376
},
377377
}
378-
if search.IsWireprotoForced() {
378+
if search.IsWireprotoEnabled() {
379379
config.Server.Wireproto = &mongot.ConfigWireproto{
380380
Address: fmt.Sprintf("0.0.0.0:%d", search.GetMongotWireprotoPort()),
381381
Authentication: &mongot.ConfigAuthentication{
@@ -413,17 +413,14 @@ func GetMongodConfigParameters(search *searchv1.MongoDBSearch, clusterDomain str
413413
"searchIndexManagementHostAndPort": mongotHostAndPort(search, clusterDomain),
414414
"skipAuthenticationToSearchIndexManagementServer": false,
415415
"searchTLSMode": string(searchTLSMode),
416-
"useGrpcForSearch": !search.IsWireprotoForced(),
416+
"useGrpcForSearch": !search.IsWireprotoEnabled(),
417417
},
418418
}
419419
}
420420

421421
func mongotHostAndPort(search *searchv1.MongoDBSearch, clusterDomain string) string {
422422
svcName := search.SearchServiceNamespacedName()
423-
port := search.GetMongotGrpcPort()
424-
if search.IsWireprotoForced() {
425-
port = search.GetMongotWireprotoPort()
426-
}
423+
port := search.GetEffectiveMongotPort()
427424
return fmt.Sprintf("%s.%s.svc.%s:%d", svcName.Name, svcName.Namespace, clusterDomain, port)
428425
}
429426

0 commit comments

Comments
 (0)