fix: ignore 'not a leader' error on forfeit leadership

When forfeiting etcd leadership, it might be that the node still reports
leadership status while not being a leader once the actual API call is
used. We should ignore such an error as the node is not a leader.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
This commit is contained in:
Andrey Smirnov 2021-07-05 23:15:29 +03:00 committed by talos-bot
parent 22a4193678
commit aaa36f3b4f

View File

@ -6,6 +6,7 @@ package etcd
import (
"context"
"errors"
"fmt"
"log"
"net/url"
@ -259,6 +260,11 @@ func (c *Client) ForfeitLeadership(ctx context.Context) (string, error) {
_, err = c.MoveLeader(ctx, m.GetID())
if err != nil {
if errors.Is(err, rpctypes.ErrNotLeader) {
// this member is not a leader anymore, so nothing to be done for the forfeit leadership
return "", nil
}
return "", err
}