Skip to content

Commit 236eee1

Browse files
authored
Merge pull request kubernetes#87505 from neolit123/1.18-handle-etcd-members-without-names
kubeadm: improvements to the concurrent etcd member join support
2 parents 5441a99 + a027c37 commit 236eee1

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

cmd/kubeadm/app/util/etcd/etcd.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const etcdTimeout = 2 * time.Second
4242

4343
// Exponential backoff for etcd operations
4444
var etcdBackoff = wait.Backoff{
45-
Steps: 9,
45+
Steps: 11,
4646
Duration: 50 * time.Millisecond,
4747
Factor: 2.0,
4848
Jitter: 0.1,
@@ -128,9 +128,9 @@ func NewFromCluster(client clientset.Interface, certificatesDir string) (*Client
128128
}
129129

130130
// dialTimeout is the timeout for failing to establish a connection.
131-
// It is set to 20 seconds as times shorter than that will cause TLS connections to fail
131+
// It is set to >20 seconds as times shorter than that will cause TLS connections to fail
132132
// on heavily loaded arm64 CPUs (issue #64649)
133-
const dialTimeout = 20 * time.Second
133+
const dialTimeout = 40 * time.Second
134134

135135
// Sync synchronizes client's endpoints with the known endpoints from the etcd membership.
136136
func (c *Client) Sync() error {
@@ -303,12 +303,20 @@ func (c *Client) AddMember(name string, peerAddrs string) ([]Member, error) {
303303
// Returns the updated list of etcd members
304304
ret := []Member{}
305305
for _, m := range resp.Members {
306-
// fixes the entry for the joining member (that doesn't have a name set in the initialCluster returned by etcd)
307-
if m.Name == "" {
308-
ret = append(ret, Member{Name: name, PeerURL: m.PeerURLs[0]})
309-
} else {
310-
ret = append(ret, Member{Name: m.Name, PeerURL: m.PeerURLs[0]})
306+
// If the peer address matches, this is the member we are adding.
307+
// Use the name we passed to the function.
308+
if peerAddrs == m.PeerURLs[0] {
309+
ret = append(ret, Member{Name: name, PeerURL: peerAddrs})
310+
continue
311+
}
312+
// Otherwise, we are processing other existing etcd members returned by AddMembers.
313+
memberName := m.Name
314+
// In some cases during concurrent join, some members can end up without a name.
315+
// Use the member ID as name for those.
316+
if len(memberName) == 0 {
317+
memberName = strconv.FormatUint(m.ID, 16)
311318
}
319+
ret = append(ret, Member{Name: memberName, PeerURL: m.PeerURLs[0]})
312320
}
313321

314322
// Add the new member client address to the list of endpoints

0 commit comments

Comments
 (0)