From e61fde93c1359a13d2aa05b5c75a1e12e8140dbd Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Thu, 27 Apr 2023 21:13:39 +0000 Subject: [PATCH] Fix MemberList error handling and incorrect etcd-arg passthrough Signed-off-by: Brad Davidson --- pkg/etcd/etcd.go | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/pkg/etcd/etcd.go b/pkg/etcd/etcd.go index 5e88bb6f10f6..ae84ca3b8e67 100644 --- a/pkg/etcd/etcd.go +++ b/pkg/etcd/etcd.go @@ -424,8 +424,8 @@ func (e *ETCD) Start(ctx context.Context, clientAccessInfo *clientaccess.Info) e if err := wait.PollImmediateUntilWithContext(ctx, time.Second, func(ctx context.Context) (bool, error) { if err := e.join(ctx, clientAccessInfo); err != nil { // Retry the join if waiting for another member to be promoted, or waiting for peers to connect after promotion - if errors.Is(err, rpctypes.ErrTooManyLearners) || errors.Is(err, rpctypes.ErrGRPCUnhealthy) { - logrus.Infof("Waiting for other members to finish joining etcd cluster") + if errors.Is(err, rpctypes.ErrTooManyLearners) || errors.Is(err, rpctypes.ErrUnhealthy) { + logrus.Infof("Waiting for other members to finish joining etcd cluster: %v", err) return false, nil } return false, err @@ -465,19 +465,7 @@ func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) er } defer client.Close() - members, err := client.MemberList(clientCtx) - if err != nil { - logrus.Errorf("Failed to get member list from etcd cluster. Will assume this member is already added") - members = &clientv3.MemberListResponse{ - Members: append(memberList.Members, &etcdserverpb.Member{ - Name: e.name, - PeerURLs: []string{e.peerURL()}, - }), - } - add = false - } - - for _, member := range members.Members { + for _, member := range memberList.Members { for _, peer := range member.PeerURLs { u, err := url.Parse(peer) if err != nil { @@ -620,6 +608,7 @@ func (e *ETCD) handler(next http.Handler) http.Handler { } // infoHandler returns etcd cluster information. This is used by new members when joining the cluster. +// If we can't retrieve an actual MemberList from etcd, we return a canned response with only the local node listed. func (e *ETCD) infoHandler() http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { ctx, cancel := context.WithTimeout(req.Context(), 2*time.Second) @@ -627,7 +616,8 @@ func (e *ETCD) infoHandler() http.Handler { members, err := e.client.MemberList(ctx) if err != nil { - json.NewEncoder(rw).Encode(&Members{ + logrus.Warnf("Failed to get etcd MemberList for %s: %v", req.RemoteAddr, err) + members = &clientv3.MemberListResponse{ Members: []*etcdserverpb.Member{ { Name: e.name, @@ -635,8 +625,7 @@ func (e *ETCD) infoHandler() http.Handler { ClientURLs: []string{e.clientURL()}, }, }, - }) - return + } } rw.Header().Set("Content-Type", "application/json") @@ -921,7 +910,7 @@ func (e *ETCD) StartEmbeddedTemporary(ctx context.Context) error { Name: e.name, LogOutputs: []string{"stderr"}, ExperimentalInitialCorruptCheck: true, - }, append(e.config.ExtraAPIArgs, "--max-snapshots=0", "--max-wals=0")) + }, append(e.config.ExtraEtcdArgs, "--max-snapshots=0", "--max-wals=0")) } func addPort(address string, offset int) (string, error) {