feat: run the member leave sequence before clearing the EtcdMember finalizer #500
func removeEtcdNode(s *reconcileState, member *ecv1alpha1.EtcdMember) error {
References to removeEtcdNode need to be updated for the typo fix
We can reuse findEtcdNodeForEtcdMember
We can wrap the error
nit: this can be an if-else block
Also, we can directly call c.Delete() instead of c.Get() before it, since we are only concerned about deleting
Should we call cleanupMemberResources before removing the finalizers of the member resources?
Good catch.
Thanks, good suggestion.
directly call c.Delete() instead of c.Get() before it
It seems better.
Good question. The doc says "Removing a member's finalizer unblocks Kubernetes' own garbage collector, which then deletes that member's owned Pod, PVC, and TLS certificate Secret (§4.10) — no controller code needed for that part. ". So I think we do not need to cleanupMemberResources.
OK, so we can expose more info.
we should return an error.
When it's nil, we don't know whether the etcd node has been removed or not. So we need to requeue the request and retry later.
Let's break down this into two functions,
deleteMemberPod(ctx context.Context, member ecv1alpha1.EtcdMember, pods []corev1.Pod) (bool, error)- The first return parameter is true if the POD exist and now deleted; false otherwise
- The second return parameter returns an error if any and not "NotFound" error
deleteMemberPVC(ctx context.Context, member *ecv1alpha1.EtcdMember) (bool, error)- The return parameters are similar to
deleteMemberPodIf the deleteMemberPod returns true, requeue the request so that we delete the PVC in next reconcile loop.
Currently when cluster.DeletionTimestamp != nil is true, the controller calls finalizeCluster and always returns directly. We should continue to execute the reconcile workflow if any etcdmember needs to be terminated.
This can be resolved in a separate PR.
We don't bypass the graceful per-member leave sequence. We still need to cleanup all resources before we remove the EtcdCluster. Please keep the comment as it's for now, and resolve it in a separate PR.
Should we ensure s.memberListResp not nil in refreshClusterState()?
If I understand correctly, s.memberListResp should contain at least one member when etcd cluster is healthy. However, under following conditions the MemberList may return nil response:
1. network partition between etcd-operator and etcd pod.
2. etcd cluster has no leader when the MemberList is called.
For any case above, should we do a retry of MemberList by requeuing the request after refreshClusterState() is returned.
So, my suggestion is to remove the if s.memberListResp == nil gate, and retry MemberList around refreshClusterState() if s.memberListResp got nil. Does this sound good to you?
OK. But this is against the design: https://github.com/etcd-io/etcd-operator/blob/main/docs/design/etcd-member-lifecycle-and-self-healing-v0.3.0.md#413-finalizing-an-etcdcluster-cluster-deletion
Should we update the doc and diagram first?
Should we ensures.memberListRespnot nil inrefreshClusterState()?
No, when the cluster isn't healthy, or even temporaray network jitter, it may be nil. In such case, we just assume the cluster isn't healthy for now.
and retryMemberListaroundrefreshClusterState()ifs.memberListRespgot nil. Does this sound good to you?
It's one option; just assuming the cluster isn't healthy, and let next loop to try it automatically is a simpler option.
The terminating etcdcluster case just doesn't need to follow the one-at-a-time per-member restriction. We can concurrently terminate all etcdmembers. But it depends on whether it may complicate the implementation. Let's discuss this in a separate PR.
do a retry ofMemberListby requeuing the request afterrefreshClusterState()is returned
I know an error returned in removeEtcdNode could trigger requeuing the request.
What I mean is to requeue the request earlier, before the workflow entering dispatch(), if s.memberListResp is nil for whatever reason. So we don't need to check if s.memberListResp == nil everywhere in reconcileEtcdMember.
What I mean is to requeue the request earlier, before the workflow entering dispatch()
We need to let the dispatch to fix any unhealthy member. Otherwise, we will enter into a deadlock if the cluster is unhealthy
Pls ping me back when all review comments are resolved.
Member repairing (Recreating, Replacing and lost-quorum recovery) is after cleaning up Terminating members in dispatch. If we requeue the request here due to an error, which is only recoverable by repairing, e.g. quorum loss, then we enter a deadlock here.
To move this forward, do you mind that I check s.memberListResp == nil in the beginning of reconcileEtcdMember. That is almost same to checking in removeEtcdNode .
There are only two cases which may trigger an EtcdMember termatning:
So in most cases, the cluster is healthy when the controller is handling an etcdMember's terminating case. If the cluster is somehow not healthy, then it might be temporary environment issue, it's unlikely that we can fix it.
Just added an open question in https://github.com/etcd-io/etcd-operator/pull/501. Let's resolve it separately.
pls don't get me wrong. I am not saying we don't resolve it. I am just saying fixing it in a followup PR as it will complicate the implementation.
Do you mind that I check s.memberListResp == nil in the beginning of reconcileEtcdMember? or should I check in removeEtcdNode ?
Do you mind that I checks.memberListResp == nilin the beginning ofreconcileEtcdMember? or should I check inremoveEtcdNode?
It isn't a big problem. Check inside removeEtcdNode seems a little cleaner, and we just return error when s.memberListResp == nil is true for now.
I updated the Terminating workflow in reconcile_member_v0.3.0.png, I think we also need to cleanup alarm for the member if any; otherwise it's weird that we removed a member, but we still have alarm on a non-exist member.
This can be resolved separately.
I updated the Terminating workflow in reconcile_member_v0.3.0.png
Updated. This change breaks e2e TestManualScaleInWithoutEndpoints, I have to skip it.
Fixes in follow-up PR:
LGTM & thx
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: <a href="https://github.com/etcd-io/etcd-operator/pull/500#pullrequestreview-5134191593" title="Approved">ahrtr</a>, <a href="https://github.com/etcd-io/etcd-operator/pull/500#" title="Author self-approved">silentred</a>
The full list of commands accepted by this bot can be found here.
The pull request process is described here
<details >
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
</details>
<!-- META={"approvers":[]} -->
ahrtr
silentred
Resolve https://github.com/etcd-io/etcd-operator/issues/471
/cc @ahrtr