From 4f51cc1d9a6d31ae5622fe50c90f03962a7ee3a4 Mon Sep 17 00:00:00 2001 From: ahrtr Date: Sat, 19 Feb 2022 05:34:23 +0800 Subject: [PATCH] trim the suffix dot from the srv.Target for etcd-client DNS lookup --- client/pkg/srv/srv.go | 3 ++- client/pkg/srv/srv_test.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/client/pkg/srv/srv.go b/client/pkg/srv/srv.go index 948c6834909..21c377e352b 100644 --- a/client/pkg/srv/srv.go +++ b/client/pkg/srv/srv.go @@ -106,9 +106,10 @@ func GetClient(service, domain string, serviceName string) (*SRVClients, error) return err } for _, srv := range addrs { + shortHost := strings.TrimSuffix(srv.Target, ".") urls = append(urls, &url.URL{ Scheme: scheme, - Host: net.JoinHostPort(srv.Target, fmt.Sprintf("%d", srv.Port)), + Host: net.JoinHostPort(shortHost, fmt.Sprintf("%d", srv.Port)), }) } srvs = append(srvs, addrs...) diff --git a/client/pkg/srv/srv_test.go b/client/pkg/srv/srv_test.go index c2ccf9485d9..f5c84421b9d 100644 --- a/client/pkg/srv/srv_test.go +++ b/client/pkg/srv/srv_test.go @@ -226,8 +226,8 @@ func TestSRVDiscover(t *testing.T) { }, { []*net.SRV{ - {Target: "a.example.com", Port: 2480}, - {Target: "b.example.com", Port: 2480}, + {Target: "a.example.com.", Port: 2480}, + {Target: "b.example.com.", Port: 2480}, {Target: "c.example.com", Port: 2480}, }, []*net.SRV{},