Skip to content

Commit

Permalink
Fix URL pruning when joining an etcd member
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
(cherry picked from commit b23955e)
Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
mstarostik authored and brandond committed Aug 12, 2021
1 parent 18bc38d commit 1e70e4d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 1e70e4d

Please sign in to comment.