Skip to content

Commit 9ed720d

Browse files
authored
Reverted replicaSetName in favor of putting more hosts in connection string (#273)
# Summary This reverts handling replicaSetName from mongot config and adds passing all mongod hosts in the connection string. It is not necessary now to set it, as mongot is connecting in a replicaset mode when there is more than one host passed on connection string. <!-- Enter your issue summary here.--> ## Proof of Work <!-- Enter your proof that it works here.--> <!-- start git-machete generated --> ## Based on PR #229 ## Chain of upstream PRs as of 2025-07-17 * PR #229: `master` ← `search/public-preview` * **PR #273 (THIS ONE)**: `search/public-preview` ← `lsierant/search-multiple-hosts` <!-- end git-machete generated -->
1 parent 167e26b commit 9ed720d

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

controllers/operator/mongodbsearch_controller_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,18 @@ func newSearchReconciler(
7474
}
7575

7676
func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.MongoDBCommunity) mongot.Config {
77+
var hostAndPorts []string
78+
for i := range mdbc.Spec.Members {
79+
hostAndPorts = append(hostAndPorts, fmt.Sprintf("%s-%d.%s.%s.svc.cluster.local:%d", mdbc.Name, i, mdbc.Name+"-svc", search.Namespace, 27017))
80+
}
7781
return mongot.Config{
7882
SyncSource: mongot.ConfigSyncSource{
7983
ReplicaSet: mongot.ConfigReplicaSet{
80-
HostAndPort: fmt.Sprintf("%s.%s.svc.cluster.local:%d", mdbc.Name+"-svc", search.Namespace, 27017),
84+
HostAndPort: hostAndPorts,
8185
Username: "mongot-user",
8286
PasswordFile: "/tmp/sourceUserPassword",
8387
TLS: ptr.To(false),
8488
ReadPreference: ptr.To("secondaryPreferred"),
85-
ReplicaSetName: "mdb",
8689
},
8790
},
8891
Storage: mongot.ConfigStorage{

controllers/search_controller/mongodbsearch_reconcile_helper.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,19 @@ func buildSearchHeadlessService(search *searchv1.MongoDBSearch) corev1.Service {
208208
}
209209

210210
func createMongotConfig(search *searchv1.MongoDBSearch, db SearchSourceDBResource) mongot.Config {
211+
var hostAndPorts []string
212+
for i := range db.Members() {
213+
hostAndPorts = append(hostAndPorts, fmt.Sprintf("%s-%d.%s.%s.svc.cluster.local:%d", db.Name(), i, db.DatabaseServiceName(), db.GetNamespace(), db.DatabasePort()))
214+
}
215+
211216
return mongot.Config{
212217
SyncSource: mongot.ConfigSyncSource{
213218
ReplicaSet: mongot.ConfigReplicaSet{
214-
HostAndPort: fmt.Sprintf("%s.%s.svc.cluster.local:%d", db.DatabaseServiceName(), db.GetNamespace(), db.DatabasePort()),
219+
HostAndPort: hostAndPorts,
215220
Username: search.SourceUsername(),
216221
PasswordFile: "/tmp/sourceUserPassword",
217222
TLS: ptr.To(false),
218223
ReadPreference: ptr.To("secondaryPreferred"),
219-
ReplicaSetName: db.Name(),
220224
},
221225
},
222226
Storage: mongot.ConfigStorage{

controllers/search_controller/search_construction.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type SearchSourceDBResource interface {
3838
DatabasePort() int
3939
GetMongoDBVersion() string
4040
IsSecurityTLSConfigEnabled() bool
41+
Members() int
4142
}
4243

4344
func NewSearchSourceDBResourceFromMongoDBCommunity(mdbc *mdbcv1.MongoDBCommunity) SearchSourceDBResource {
@@ -48,6 +49,10 @@ type mdbcSearchResource struct {
4849
db *mdbcv1.MongoDBCommunity
4950
}
5051

52+
func (r *mdbcSearchResource) Members() int {
53+
return r.db.Spec.Members
54+
}
55+
5156
func (r *mdbcSearchResource) Name() string {
5257
return r.db.Name
5358
}

helm_chart/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,4 @@ search:
229229
repo: 268558157000.dkr.ecr.eu-west-1.amazonaws.com
230230
name: mongot/community
231231
# default MongoDB Search version used; can be overridden by setting MongoDBSearch.spec.version field.
232-
version: b9b80915f5571bfa5fc2aa70acb20d784e68d79b
232+
version: d6884ae132aab30497af55dbaff05e8274e9775f

mongodb-community-operator/pkg/mongot/mongot_config.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ type ConfigSyncSource struct {
1414
}
1515

1616
type ConfigReplicaSet struct {
17-
HostAndPort string `json:"hostAndPort"`
18-
Username string `json:"username"`
19-
PasswordFile string `json:"passwordFile"`
20-
ReplicaSetName string `json:"replicaSetName"`
21-
TLS *bool `json:"tls,omitempty"`
22-
ReadPreference *string `json:"readPreference,omitempty"`
17+
HostAndPort []string `json:"hostAndPort"`
18+
Username string `json:"username"`
19+
PasswordFile string `json:"passwordFile"`
20+
TLS *bool `json:"tls,omitempty"`
21+
ReadPreference *string `json:"readPreference,omitempty"`
2322
}
2423

2524
type ConfigStorage struct {

scripts/dev/contexts/e2e_mdb_community

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export OM_EXTERNALLY_CONFIGURED="true"
1313

1414
# Temporary development images built from mongot master
1515
#export MDB_SEARCH_COMMUNITY_VERSION="776d43523d185b6b234289e17c191712a3e6569b" # master
16-
#export MDB_SEARCH_COMMUNITY_VERSION="d6884ae132aab30497af55dbaff05e8274e9775f" # Local->Admin
16+
export MDB_SEARCH_COMMUNITY_VERSION="d6884ae132aab30497af55dbaff05e8274e9775f" # Local->Admin
1717
#export MDB_SEARCH_COMMUNITY_VERSION="ad8acf5c3a045d6e0306ad67d61fcb5be40f57ae" # hardcoded mdbc-rs replicaset name
18-
export MDB_SEARCH_COMMUNITY_VERSION="b9b80915f5571bfa5fc2aa70acb20d784e68d79b" # hardcoded Local->Admin, handled replicaSetName in config
18+
#export MDB_SEARCH_COMMUNITY_VERSION="b9b80915f5571bfa5fc2aa70acb20d784e68d79b" # hardcoded Local->Admin, handled replicaSetName in config
1919
export MDB_SEARCH_COMMUNITY_NAME="mongot/community"
2020
export MDB_SEARCH_COMMUNITY_REPO_URL="268558157000.dkr.ecr.eu-west-1.amazonaws.com"

0 commit comments

Comments
 (0)