Fix premature etcd shutdown when joining an existing cluster

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/4024/head
Brad Davidson 2021-09-14 22:13:31 -07:00 committed by Brad Davidson
parent 60cd86bc42
commit 086ca8ba6a
1 changed files with 14 additions and 14 deletions

View File

@ -297,18 +297,7 @@ func (e *ETCD) Start(ctx context.Context, clientAccessInfo *clientaccess.Info) e
// join attempts to add a member to an existing cluster // join attempts to add a member to an existing cluster
func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) error { func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) error {
clientURLs, memberList, err := ClientURLs(ctx, clientAccessInfo, e.config.PrivateIP) clientCtx, cancel := context.WithTimeout(ctx, 20*time.Second)
if err != nil {
return err
}
client, err := GetClient(ctx, e.runtime, clientURLs...)
if err != nil {
return err
}
defer client.Close()
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel() defer cancel()
var ( var (
@ -316,7 +305,18 @@ func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) er
add = true add = true
) )
members, err := client.MemberList(ctx) clientURLs, memberList, err := ClientURLs(clientCtx, clientAccessInfo, e.config.PrivateIP)
if err != nil {
return err
}
client, err := GetClient(clientCtx, e.runtime, clientURLs...)
if err != nil {
return err
}
defer client.Close()
members, err := client.MemberList(clientCtx)
if err != nil { if err != nil {
logrus.Errorf("Failed to get member list from etcd cluster. Will assume this member is already added") logrus.Errorf("Failed to get member list from etcd cluster. Will assume this member is already added")
members = &clientv3.MemberListResponse{ members = &clientv3.MemberListResponse{
@ -349,7 +349,7 @@ func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) er
if add { if add {
logrus.Infof("Adding %s to etcd cluster %v", e.peerURL(), cluster) logrus.Infof("Adding %s to etcd cluster %v", e.peerURL(), cluster)
if _, err = client.MemberAddAsLearner(ctx, []string{e.peerURL()}); err != nil { if _, err = client.MemberAddAsLearner(clientCtx, []string{e.peerURL()}); err != nil {
return err return err
} }
cluster = append(cluster, fmt.Sprintf("%s=%s", e.name, e.peerURL())) cluster = append(cluster, fmt.Sprintf("%s=%s", e.name, e.peerURL()))