Skip to content

Commit

Permalink
fix: mongodb cluster member addr (#5588)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuriwuyun authored Oct 23, 2023
1 parent 4311028 commit a150515
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lorry/component/postgres/officalpostgres/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestGetMemberAddrs(t *testing.T) {
ctx := context.TODO()
manager, mock, _ := MockDatabase(t)
defer mock.Close()
cluster := &dcs.Cluster{}
cluster := &dcs.Cluster{Namespace: "default"}

t.Run("get empty addrs", func(t *testing.T) {
addrs := manager.GetMemberAddrs(ctx, cluster)
Expand All @@ -182,7 +182,7 @@ func TestGetMemberAddrs(t *testing.T) {
addrs := manager.GetMemberAddrs(ctx, cluster)

assert.Equal(t, 1, len(addrs))
assert.Equal(t, "test.pg-headless:5432", addrs[0])
assert.Equal(t, "test.pg-headless.default.svc.cluster.local:5432", addrs[0])
})
}

Expand Down
6 changes: 5 additions & 1 deletion lorry/dcs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ package dcs

import (
"fmt"

"github.com/apecloud/kubeblocks/pkg/constant"
viper "github.com/apecloud/kubeblocks/pkg/viperx"
)

type Cluster struct {
Expand Down Expand Up @@ -91,7 +94,8 @@ func (c *Cluster) GetMemberAddrWithPort(member Member) string {
}

func (c *Cluster) GetMemberAddr(member Member) string {
return fmt.Sprintf("%s.%s-headless", member.Name, c.ClusterCompName)
clusterDomain := viper.GetString(constant.KubernetesClusterDomainEnv)
return fmt.Sprintf("%s.%s-headless.%s.svc.%s", member.Name, c.ClusterCompName, c.Namespace, clusterDomain)
}

func (c *Cluster) GetMemberAddrWithName(name string) string {
Expand Down

0 comments on commit a150515

Please sign in to comment.