Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5a475fe
(fix): Use CLUSTER_DOMAIN environment variable instead of the fixed v…
edimarlnx Sep 26, 2025
7b14af5
(fix): Replace CLUSTER_DOMAIN logic with configurable `ClusterDomain`…
edimarlnx Sep 30, 2025
d9af10a
(fix): Pass `ClusterDomain` to `GetMongodConfigParameters` and relate…
edimarlnx Sep 30, 2025
b1d59ae
Merge branch 'master' into fix/cluster-domain
edimarlnx Oct 1, 2025
fc943fc
Update the changelog for new changes
edimarlnx Oct 2, 2025
1d14361
Update changelog/20250925_fix_use_cluster_domain_environment_variable…
edimarlnx Oct 6, 2025
480cc80
Merge branch 'mongodb:master' into fix/cluster-domain
edimarlnx Oct 6, 2025
f426bd1
Update changelog/20250925_fix_use_cluster_domain_environment_variable…
edimarlnx Oct 6, 2025
e9a5452
feat(crd): add `ClusterDomain` field to MongoDBCommunity CRD
edimarlnx Oct 6, 2025
06bb497
fix(changelog): correct filename for `ClusterDomain` changelog entry
edimarlnx Oct 7, 2025
667f936
Merge branch 'master' into fix/cluster-domain
edimarlnx Oct 7, 2025
5693eef
fix(tests): remove redundant arguments from URI methods
edimarlnx Oct 8, 2025
ca23e1f
Merge branch 'master' into fix/cluster-domain
edimarlnx Oct 8, 2025
d6ae737
feat(changelog): update details for configurable `ClusterDomain` impl…
edimarlnx Oct 8, 2025
eb1f75e
feat(changelog): simplify details for `ClusterDomain` implementation
edimarlnx Oct 8, 2025
553987c
feat(tests): fix broken tests
edimarlnx Oct 9, 2025
47adda1
Merge branch 'master' into fix/cluster-domain
edimarlnx Oct 9, 2025
3dad796
Fix linter issues
edimarlnx Oct 10, 2025
abcfb28
Merge branch 'master' into fix/cluster-domain
edimarlnx Oct 10, 2025
9827dd2
Update changelog/20250925_feature_use_cluster_domain_environment_vari…
MaciejKaras Oct 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
kind: feature
date: 2025-09-25
---

* **MongoDBCommunity**: Add support for custom cluster domains via `CLUSTER_DOMAIN` environment variable and `ClusterDomain` spec field
* Replace hardcoded `cluster.local` value with configurable cluster domain
* Add optional `ClusterDomain` field to `MongoDBCommunitySpec` with hostname format validation
* Implement `GetClusterDomain()` method with fallback hierarchy: spec field → environment variable → default `cluster.local`
* Update MongoDB connection URI generation (standard and SRV) to use configurable domain
* Fix host seed generation in `CommunitySearchSource` and `EnterpriseResourceSearchSource` to use configurable domain
* Update mongod configuration parameters for MongoDB Search with correct cluster domain
* Remove `clusterDomain` parameter from public methods (`MongoURI()`, `MongoSRVURI()`, `MongoAuthUserURI()`, `MongoAuthUserSRVURI()`) - now retrieve domain directly from spec
* Update all unit tests to reflect new structure
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ spec:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
clusterDomain:
format: hostname
type: string
featureCompatibilityVersion:
description: |-
FeatureCompatibilityVersion configures the feature compatibility version that will
Expand Down
2 changes: 1 addition & 1 deletion controllers/operator/mongodbreplicaset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ func (r *ReconcileMongoDbReplicaSet) applySearchOverrides(ctx context.Context, r
if rs.Spec.AdditionalMongodConfig == nil {
rs.Spec.AdditionalMongodConfig = mdbv1.NewEmptyAdditionalMongodConfig()
}
searchMongodConfig := searchcontroller.GetMongodConfigParameters(search)
searchMongodConfig := searchcontroller.GetMongodConfigParameters(search, rs.Spec.GetClusterDomain())
rs.Spec.AdditionalMongodConfig.AddOption("setParameter", searchMongodConfig["setParameter"])

if searchcontroller.NeedsSearchCoordinatorRolePolyfill(rs.Spec.GetMongoDBVersion()) {
Expand Down
3 changes: 2 additions & 1 deletion controllers/searchcontroller/community_search_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type CommunitySearchSource struct {

func (r *CommunitySearchSource) HostSeeds() []string {
seeds := make([]string, r.Spec.Members)
clusterDomain := r.Spec.GetClusterDomain()
for i := range seeds {
seeds[i] = fmt.Sprintf("%s-%d.%s.%s.svc.cluster.local:%d", r.Name, i, r.ServiceName(), r.Namespace, r.GetMongodConfiguration().GetDBPort())
seeds[i] = fmt.Sprintf("%s-%d.%s.%s.svc.%s:%d", r.Name, i, r.ServiceName(), r.Namespace, clusterDomain, r.GetMongodConfiguration().GetDBPort())
}
return seeds
}
Expand Down
3 changes: 2 additions & 1 deletion controllers/searchcontroller/enterprise_search_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ func NewEnterpriseResourceSearchSource(mdb *mdbv1.MongoDB) SearchSourceDBResourc

func (r EnterpriseResourceSearchSource) HostSeeds() []string {
seeds := make([]string, r.Spec.Members)
clusterDomain := r.Spec.GetClusterDomain()
for i := range seeds {
seeds[i] = fmt.Sprintf("%s-%d.%s.%s.svc.cluster.local:%d", r.Name, i, r.ServiceName(), r.Namespace, r.Spec.GetAdditionalMongodConfig().GetPortOrDefault())
seeds[i] = fmt.Sprintf("%s-%d.%s.%s.svc.%s:%d", r.Name, i, r.ServiceName(), r.Namespace, clusterDomain, r.Spec.GetAdditionalMongodConfig().GetPortOrDefault())
}
return seeds
}
Expand Down
10 changes: 5 additions & 5 deletions controllers/searchcontroller/mongodbsearch_reconcile_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,24 +388,24 @@ func createMongotConfig(search *searchv1.MongoDBSearch, db SearchSourceDBResourc
}
}

func GetMongodConfigParameters(search *searchv1.MongoDBSearch) map[string]any {
func GetMongodConfigParameters(search *searchv1.MongoDBSearch, clusterDomain string) map[string]any {
searchTLSMode := automationconfig.TLSModeDisabled
if search.Spec.Security.TLS != nil {
searchTLSMode = automationconfig.TLSModeRequired
}
return map[string]any{
"setParameter": map[string]any{
"mongotHost": mongotHostAndPort(search),
"searchIndexManagementHostAndPort": mongotHostAndPort(search),
"mongotHost": mongotHostAndPort(search, clusterDomain),
"searchIndexManagementHostAndPort": mongotHostAndPort(search, clusterDomain),
"skipAuthenticationToSearchIndexManagementServer": false,
"searchTLSMode": string(searchTLSMode),
},
}
}

func mongotHostAndPort(search *searchv1.MongoDBSearch) string {
func mongotHostAndPort(search *searchv1.MongoDBSearch, clusterDomain string) string {
svcName := search.SearchServiceNamespacedName()
return fmt.Sprintf("%s.%s.svc.cluster.local:%d", svcName.Name, svcName.Namespace, search.GetMongotPort())
return fmt.Sprintf("%s.%s.svc.%s:%d", svcName.Name, svcName.Namespace, clusterDomain, search.GetMongotPort())
}

func (r *MongoDBSearchReconcileHelper) ValidateSingleMongoDBSearchForSearchSource(ctx context.Context) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ spec:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
clusterDomain:
format: hostname
type: string
featureCompatibilityVersion:
description: |-
FeatureCompatibilityVersion configures the feature compatibility version that will
Expand Down
42 changes: 19 additions & 23 deletions mongodb-community-operator/api/v1/mongodbcommunity_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"regexp"
"strings"

"github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/util/envvar"
"github.com/stretchr/objx"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -71,7 +72,8 @@ type MongoDBCommunitySpec struct {
Type Type `json:"type"`
// Version defines which version of MongoDB will be used
Version string `json:"version,omitempty"`

// +kubebuilder:validation:Format="hostname"
ClusterDomain string `json:"clusterDomain,omitempty"`
// Arbiters is the number of arbiters to add to the Replica Set.
// It is not recommended to have more than one arbiter per Replica Set.
// More info: https://www.mongodb.com/docs/manual/tutorial/add-replica-set-arbiter/
Expand Down Expand Up @@ -922,30 +924,26 @@ func (m *MongoDBCommunity) GetUserOptionsString(user authtypes.User) string {
}

// MongoURI returns a mongo uri which can be used to connect to this deployment
func (m *MongoDBCommunity) MongoURI(clusterDomain string) string {
func (m *MongoDBCommunity) MongoURI() string {
optionsString := m.GetOptionsString()

return fmt.Sprintf("mongodb://%s/?replicaSet=%s%s", strings.Join(m.Hosts(clusterDomain), ","), m.Name, optionsString)
return fmt.Sprintf("mongodb://%s/?replicaSet=%s%s", strings.Join(m.Hosts(), ","), m.Name, optionsString)
}

// MongoSRVURI returns a mongo srv uri which can be used to connect to this deployment
func (m *MongoDBCommunity) MongoSRVURI(clusterDomain string) string {
if clusterDomain == "" {
clusterDomain = defaultClusterDomain
}

func (m *MongoDBCommunity) MongoSRVURI() string {
optionsString := m.GetOptionsString()

return fmt.Sprintf("mongodb+srv://%s.%s.svc.%s/?replicaSet=%s%s", m.ServiceName(), m.Namespace, clusterDomain, m.Name, optionsString)
return fmt.Sprintf("mongodb+srv://%s.%s.svc.%s/?replicaSet=%s%s", m.ServiceName(), m.Namespace, m.Spec.GetClusterDomain(), m.Name, optionsString)
}

// MongoAuthUserURI returns a mongo uri which can be used to connect to this deployment
// and includes the authentication data for the user
func (m *MongoDBCommunity) MongoAuthUserURI(user authtypes.User, password string, clusterDomain string) string {
func (m *MongoDBCommunity) MongoAuthUserURI(user authtypes.User, password string) string {
optionsString := m.GetUserOptionsString(user)
return fmt.Sprintf("mongodb://%s%s/%s?replicaSet=%s&ssl=%t%s",
user.GetLoginString(password),
strings.Join(m.Hosts(clusterDomain), ","),
strings.Join(m.Hosts(), ","),
user.Database,
m.Name,
m.Spec.Security.TLS.Enabled,
Expand All @@ -954,36 +952,28 @@ func (m *MongoDBCommunity) MongoAuthUserURI(user authtypes.User, password string

// MongoAuthUserSRVURI returns a mongo srv uri which can be used to connect to this deployment
// and includes the authentication data for the user
func (m *MongoDBCommunity) MongoAuthUserSRVURI(user authtypes.User, password string, clusterDomain string) string {
if clusterDomain == "" {
clusterDomain = defaultClusterDomain
}

func (m *MongoDBCommunity) MongoAuthUserSRVURI(user authtypes.User, password string) string {
optionsString := m.GetUserOptionsString(user)
return fmt.Sprintf("mongodb+srv://%s%s.%s.svc.%s/%s?replicaSet=%s&ssl=%t%s",
user.GetLoginString(password),
m.ServiceName(),
m.Namespace,
clusterDomain,
m.Spec.GetClusterDomain(),
user.Database,
m.Name,
m.Spec.Security.TLS.Enabled,
optionsString)
}

func (m *MongoDBCommunity) Hosts(clusterDomain string) []string {
func (m *MongoDBCommunity) Hosts() []string {
hosts := make([]string, m.Spec.Members)

if clusterDomain == "" {
clusterDomain = defaultClusterDomain
}

for i := 0; i < m.Spec.Members; i++ {
hosts[i] = fmt.Sprintf("%s-%d.%s.%s.svc.%s:%d",
m.Name, i,
m.ServiceName(),
m.Namespace,
clusterDomain,
m.Spec.GetClusterDomain(),
m.GetMongodConfiguration().GetDBPort())
}
return hosts
Expand Down Expand Up @@ -1156,6 +1146,12 @@ func (m MongoDBCommunity) GetAgentLogFile() string {
func (m MongoDBCommunity) GetAgentMaxLogFileDurationHours() int {
return m.Spec.AgentConfiguration.MaxLogFileDurationHours
}
func (m MongoDBCommunitySpec) GetClusterDomain() string {
if m.ClusterDomain != "" {
return m.ClusterDomain
}
return envvar.GetEnvOrDefault(constants.ClusterDomainEnv, defaultClusterDomain)
}

type automationConfigReplicasScaler struct {
current, desired int
Expand Down
29 changes: 17 additions & 12 deletions mongodb-community-operator/api/v1/mongodbcommunity_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func TestMongoDB_MongoURI(t *testing.T) {
for _, params := range tests {
mdb := newReplicaSet(params.members, params.name, params.namespace)
mdb.Spec.AdditionalMongodConfig.Object = params.additionalMongodConfig
assert.Equal(t, mdb.MongoURI(params.clusterDomain), params.connectionString)
mdb.Spec.ClusterDomain = params.clusterDomain
assert.Equal(t, mdb.MongoURI(), params.connectionString)
}
}

Expand Down Expand Up @@ -152,30 +153,34 @@ func TestMongoDB_MongoURI_With_Options(t *testing.T) {
mdb := newReplicaSet(params.members, params.name, params.namespace)
mdb.Spec.AdditionalMongodConfig.Object = params.additionalMongodConfig
mdb.Spec.AdditionalConnectionStringConfig.Object = params.additionalConnectionStringConfig
assert.Equal(t, mdb.MongoURI(params.clusterDomain), params.connectionString)
mdb.Spec.ClusterDomain = params.clusterDomain
assert.Equal(t, mdb.MongoURI(), params.connectionString)
}
}

func TestMongoDB_MongoSRVURI(t *testing.T) {
mdb := newReplicaSet(2, "my-rs", "my-namespace")
assert.Equal(t, mdb.MongoSRVURI(""), "mongodb+srv://my-rs-svc.my-namespace.svc.cluster.local/?replicaSet=my-rs")
assert.Equal(t, mdb.MongoSRVURI("my.cluster"), "mongodb+srv://my-rs-svc.my-namespace.svc.my.cluster/?replicaSet=my-rs")
assert.Equal(t, mdb.MongoSRVURI(), "mongodb+srv://my-rs-svc.my-namespace.svc.cluster.local/?replicaSet=my-rs")
mdb.Spec.ClusterDomain = "my.cluster"
assert.Equal(t, mdb.MongoSRVURI(), "mongodb+srv://my-rs-svc.my-namespace.svc.my.cluster/?replicaSet=my-rs")
}

func TestMongoDB_MongoSRVURI_With_Options(t *testing.T) {
mdb := newReplicaSet(2, "my-rs", "my-namespace")
mdb.Spec.AdditionalConnectionStringConfig.Object = map[string]interface{}{
"readPreference": "primary",
}
assert.Equal(t, mdb.MongoSRVURI(""), "mongodb+srv://my-rs-svc.my-namespace.svc.cluster.local/?replicaSet=my-rs&readPreference=primary")
assert.Equal(t, mdb.MongoSRVURI("my.cluster"), "mongodb+srv://my-rs-svc.my-namespace.svc.my.cluster/?replicaSet=my-rs&readPreference=primary")
assert.Equal(t, mdb.MongoSRVURI(), "mongodb+srv://my-rs-svc.my-namespace.svc.cluster.local/?replicaSet=my-rs&readPreference=primary")
mdb.Spec.ClusterDomain = "my.cluster"
assert.Equal(t, mdb.MongoSRVURI(), "mongodb+srv://my-rs-svc.my-namespace.svc.my.cluster/?replicaSet=my-rs&readPreference=primary")

mdb = newReplicaSet(2, "my-rs", "my-namespace")
mdb.Spec.AdditionalConnectionStringConfig.Object = map[string]interface{}{
"readPreference": "primary", "replicaSet": "differentName", "tls": true, "ssl": true,
}
assert.Equal(t, mdb.MongoSRVURI(""), "mongodb+srv://my-rs-svc.my-namespace.svc.cluster.local/?replicaSet=my-rs&readPreference=primary")
assert.Equal(t, mdb.MongoSRVURI("my.cluster"), "mongodb+srv://my-rs-svc.my-namespace.svc.my.cluster/?replicaSet=my-rs&readPreference=primary")
assert.Equal(t, mdb.MongoSRVURI(), "mongodb+srv://my-rs-svc.my-namespace.svc.cluster.local/?replicaSet=my-rs&readPreference=primary")
mdb.Spec.ClusterDomain = "my.cluster"
assert.Equal(t, mdb.MongoSRVURI(), "mongodb+srv://my-rs-svc.my-namespace.svc.my.cluster/?replicaSet=my-rs&readPreference=primary")
}

func TestMongodConfiguration(t *testing.T) {
Expand Down Expand Up @@ -399,7 +404,7 @@ func TestMongoDBCommunity_MongoAuthUserURI(t *testing.T) {
for _, params := range tests {
mdb.Spec.AdditionalConnectionStringConfig.Object = params.additionalConnectionStringConfig
testuser.ConnectionStringOptions = params.userConnectionStringConfig
assert.Equal(t, mdb.MongoAuthUserURI(testuser, "password", ""), params.connectionString)
assert.Equal(t, mdb.MongoAuthUserURI(testuser, "password"), params.connectionString)
}

testuser = authtypes.User{
Expand All @@ -408,7 +413,7 @@ func TestMongoDBCommunity_MongoAuthUserURI(t *testing.T) {
}
mdb = newReplicaSet(2, "my-rs", "my-namespace")

assert.Equal(t, mdb.MongoAuthUserURI(testuser, "", ""), "mongodb://my-rs-0.my-rs-svc.my-namespace.svc.cluster.local:27017,my-rs-1.my-rs-svc.my-namespace.svc.cluster.local:27017/$external?replicaSet=my-rs&ssl=false")
assert.Equal(t, mdb.MongoAuthUserURI(testuser, ""), "mongodb://my-rs-0.my-rs-svc.my-namespace.svc.cluster.local:27017,my-rs-1.my-rs-svc.my-namespace.svc.cluster.local:27017/$external?replicaSet=my-rs&ssl=false")
}

func TestMongoDBCommunity_MongoAuthUserSRVURI(t *testing.T) {
Expand Down Expand Up @@ -460,7 +465,7 @@ func TestMongoDBCommunity_MongoAuthUserSRVURI(t *testing.T) {
for _, params := range tests {
mdb.Spec.AdditionalConnectionStringConfig.Object = params.additionalConnectionStringConfig
testuser.ConnectionStringOptions = params.userConnectionStringConfig
assert.Equal(t, mdb.MongoAuthUserSRVURI(testuser, "password", ""), params.connectionString)
assert.Equal(t, mdb.MongoAuthUserSRVURI(testuser, "password"), params.connectionString)
}

testuser = authtypes.User{
Expand All @@ -469,7 +474,7 @@ func TestMongoDBCommunity_MongoAuthUserSRVURI(t *testing.T) {
}
mdb = newReplicaSet(2, "my-rs", "my-namespace")

assert.Equal(t, mdb.MongoAuthUserSRVURI(testuser, "", ""), "mongodb+srv://my-rs-svc.my-namespace.svc.cluster.local/$external?replicaSet=my-rs&ssl=false")
assert.Equal(t, mdb.MongoAuthUserSRVURI(testuser, ""), "mongodb+srv://my-rs-svc.my-namespace.svc.cluster.local/$external?replicaSet=my-rs&ssl=false")
}

func TestConvertAuthModeToAuthMechanism(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions mongodb-community-operator/controllers/mongodb_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (r ReplicaSetReconciler) ensureUserResources(ctx context.Context, mdb mdbv1

// updateConnectionStringSecrets updates secrets where user specific connection strings are stored.
// The client applications can mount these secrets and connect to the mongodb cluster
func (r ReplicaSetReconciler) updateConnectionStringSecrets(ctx context.Context, mdb mdbv1.MongoDBCommunity, clusterDomain string) error {
func (r ReplicaSetReconciler) updateConnectionStringSecrets(ctx context.Context, mdb mdbv1.MongoDBCommunity) error {
for _, user := range mdb.GetAuthUsers() {
secretName := user.ConnectionStringSecretName

Expand Down Expand Up @@ -75,8 +75,8 @@ func (r ReplicaSetReconciler) updateConnectionStringSecrets(ctx context.Context,
SetName(secretName).
SetNamespace(secretNamespace).
SetAnnotations(user.ConnectionStringSecretAnnotations).
SetField("connectionString.standard", mdb.MongoAuthUserURI(user, pwd, clusterDomain)).
SetField("connectionString.standardSrv", mdb.MongoAuthUserSRVURI(user, pwd, clusterDomain)).
SetField("connectionString.standard", mdb.MongoAuthUserURI(user, pwd)).
SetField("connectionString.standardSrv", mdb.MongoAuthUserSRVURI(user, pwd)).
SetField("username", user.Username).
SetField("password", pwd).
SetOwnerReferences(mdb.GetOwnerReferences()).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ import (
)

const (
clusterDomain = "CLUSTER_DOMAIN"

lastSuccessfulConfiguration = "mongodb.com/v1.lastSuccessfulConfiguration"
lastAppliedMongoDBVersion = "mongodb.com/v1.lastAppliedMongoDBVersion"
)
Expand Down Expand Up @@ -236,7 +234,7 @@ func (r ReplicaSetReconciler) Reconcile(ctx context.Context, request reconcile.R
}

res, err := status.Update(ctx, r.client.Status(), &mdb, statusOptions().
withMongoURI(mdb.MongoURI(os.Getenv(clusterDomain))). // nolint:forbidigo
withMongoURI(mdb.MongoURI()). // nolint:forbidigo
withMongoDBMembers(mdb.AutomationConfigMembersThisReconciliation()).
withStatefulSetReplicas(mdb.StatefulSetReplicasThisReconciliation()).
withStatefulSetArbiters(mdb.StatefulSetArbitersThisReconciliation()).
Expand All @@ -249,7 +247,7 @@ func (r ReplicaSetReconciler) Reconcile(ctx context.Context, request reconcile.R
return res, err
}

if err := r.updateConnectionStringSecrets(ctx, mdb, os.Getenv(clusterDomain)); err != nil { // nolint:forbidigo
if err := r.updateConnectionStringSecrets(ctx, mdb); err != nil { // nolint:forbidigo
r.log.Errorf("Could not update connection string secrets: %s", err)
}

Expand Down Expand Up @@ -532,8 +530,8 @@ func (r ReplicaSetReconciler) ensureAutomationConfig(mdb mdbv1.MongoDBCommunity,
}

func buildAutomationConfig(mdb mdbv1.MongoDBCommunity, isEnterprise bool, auth automationconfig.Auth, currentAc automationconfig.AutomationConfig, modifications ...automationconfig.Modification) (automationconfig.AutomationConfig, error) {
domain := getDomain(mdb.ServiceName(), mdb.Namespace, os.Getenv(clusterDomain)) // nolint:forbidigo
arbiterDomain := getDomain(mdb.ServiceName(), mdb.Namespace, os.Getenv(clusterDomain)) // nolint:forbidigo
domain := getDomain(mdb.ServiceName(), mdb.Namespace, mdb.Spec.GetClusterDomain()) // nolint:forbidigo
arbiterDomain := getDomain(mdb.ServiceName(), mdb.Namespace, mdb.Spec.GetClusterDomain()) // nolint:forbidigo

zap.S().Debugw("AutomationConfigMembersThisReconciliation", "mdb.AutomationConfigMembersThisReconciliation()", mdb.AutomationConfigMembersThisReconciliation())

Expand Down Expand Up @@ -730,7 +728,7 @@ func (r ReplicaSetReconciler) buildAutomationConfig(ctx context.Context, mdb mdb
customRolesModification,
prometheusModification,
processPortManager.GetPortsModification(),
getMongodConfigSearchModification(search),
getMongodConfigSearchModification(search, mdb.Spec.GetClusterDomain()),
searchCoordinatorCustomRoleModification(search, mdb.GetMongoDBVersion()),
)
if err != nil {
Expand Down Expand Up @@ -836,13 +834,13 @@ func getMongodConfigModification(mdb mdbv1.MongoDBCommunity) automationconfig.Mo

// getMongodConfigModification will merge the additional configuration in the CRD
// into the configuration set up by the operator.
func getMongodConfigSearchModification(search *searchv1.MongoDBSearch) automationconfig.Modification {
func getMongodConfigSearchModification(search *searchv1.MongoDBSearch, clusterDomain string) automationconfig.Modification {
// Condition for skipping add parameter if it is external mongod
if search == nil || search.IsExternalMongoDBSource() {
return automationconfig.NOOP()
}

searchConfigParameters := searchcontroller.GetMongodConfigParameters(search)
searchConfigParameters := searchcontroller.GetMongodConfigParameters(search, clusterDomain)
return func(ac *automationconfig.AutomationConfig) {
for i := range ac.Processes {
err := mergo.Merge(&ac.Processes[i].Args26, objx.New(searchConfigParameters), mergo.WithOverride)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ const (
AgentKeyfileKey = "keyfile"
AgentPemFile = "agent-certs-pem"
AutomationAgentWindowsKeyFilePath = "%SystemDrive%\\MMSAutomation\\versions\\keyfile"
ClusterDomainEnv = "CLUSTER_DOMAIN"
)