Skip to content

Commit 5e0c077

Browse files
committed
kubeadm: handle multiple members without names during concurrent join
For the etcd client, amend AddMember() to handle a very rare bug when multiple members can end up with the same name. Match the member peer address and assign it the name of the member we are adding. For the rest of the members with missing names use their member IDs as name. The etcd node is not disrupted by the unknown names. The important aspects are: - The number of members of the initial cluster must match the members in the cluster. - The member we are current adding is present in the initial cluster.
1 parent c9b4cf3 commit 5e0c077

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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)