Skip to content

Commit

Permalink
Fix MemberList error handling and incorrect etcd-arg passthrough
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
brandond committed Apr 29, 2023
1 parent 91afb38 commit e61fde9
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions pkg/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -620,23 +608,24 @@ 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)
defer cancel()

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,
PeerURLs: []string{e.peerURL()},
ClientURLs: []string{e.clientURL()},
},
},
})
return
}
}

rw.Header().Set("Content-Type", "application/json")
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e61fde9

Please sign in to comment.