From acf9036b63f833dbea5b8dee2836082d4639dddf Mon Sep 17 00:00:00 2001 From: Chris Kim <30601846+Oats87@users.noreply.github.com> Date: Wed, 15 Sep 2021 05:41:30 -1000 Subject: [PATCH] No-op when etcd member was already removed and use existing name for etcd controller (#4014) Signed-off-by: Chris Kim --- pkg/etcd/member_controller.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/etcd/member_controller.go b/pkg/etcd/member_controller.go index 86e4f32a5e..c355897ad0 100644 --- a/pkg/etcd/member_controller.go +++ b/pkg/etcd/member_controller.go @@ -17,8 +17,8 @@ func RegisterMemberHandlers(ctx context.Context, etcd *ETCD, nodes controllerv1. nodeController: nodes, ctx: ctx, } - nodes.OnChange(ctx, "managed-etcd-member-controller", e.sync) - nodes.OnRemove(ctx, "managed-etcd-member-controller", e.onRemove) + nodes.OnChange(ctx, "managed-etcd-controller", e.sync) + nodes.OnRemove(ctx, "managed-etcd-controller", e.onRemove) } var ( @@ -99,7 +99,19 @@ func (e *etcdMemberHandler) onRemove(key string, node *v1.Node) (*v1.Node, error logrus.Debugf("Node %s was not labeled etcd node, skipping etcd member removal", key) return node, nil } - + logrus.Infof("Removing etcd member %s from cluster", key) + if removalRequested, ok := node.Annotations[removalAnnotation]; ok { + if strings.ToLower(removalRequested) == "true" { + if removedNodeName, ok := node.Annotations[removedNodeNameAnnotation]; ok { + if len(removedNodeName) > 0 { + // If we received a node to delete that has already been removed via annotation, it will be missing + // the corresponding node name and address annotations. + logrus.Infof("etcd member %s was already removed as member name %s via annotation from the cluster", key, removedNodeName) + return node, nil + } + } + } + } name, ok := node.Annotations[NodeNameAnnotation] if !ok { return node, fmt.Errorf("node name annotation for node %s not found", key) @@ -108,6 +120,5 @@ func (e *etcdMemberHandler) onRemove(key string, node *v1.Node) (*v1.Node, error if !ok { return node, fmt.Errorf("node address annotation for node %s not found", key) } - return node, e.etcd.RemovePeer(e.ctx, name, address, true) }