From 1e70e4d8166e024575a2803c1a0cd3c72c006a4f Mon Sep 17 00:00:00 2001 From: Malte Starostik Date: Fri, 13 Aug 2021 00:59:04 +0200 Subject: [PATCH] Fix URL pruning when joining an etcd member * Fix URL pruning when joining an etcd member Problem: Existing member clientURLs were checked if they contain the joining node's IP. In some edge cases this would prune valid URLs when the joining IP is a substring match of the only existing member's IP. Because of this, it was impossible to e.g. join 10.0.0.2 to an existing node that has an IP of 10.0.0.2X or 10.0.0.2XX: level=fatal msg="starting kubernetes: preparing server: start managed database: joining etcd cluster: etcdclient: no available endpoints" Solution: Fixed by properly parsing the URLs and comparing the IPs for equality instead of substring match. Signed-off-by: Malte Starostik (cherry picked from commit b23955e8353399951685a2716c7c2aa4b8718013) Signed-off-by: Brad Davidson --- pkg/etcd/etcd.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/etcd/etcd.go b/pkg/etcd/etcd.go index 1b05856a5cab..7d31d7eacf8d 100644 --- a/pkg/etcd/etcd.go +++ b/pkg/etcd/etcd.go @@ -746,8 +746,12 @@ members: if member.IsLearner { continue } - for _, url := range member.ClientURLs { - if strings.Contains(url, ip) { + for _, clientURL := range member.ClientURLs { + u, err := url.Parse(clientURL) + if err != nil { + continue + } + if u.Hostname() == ip { continue members } }