Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Forward etcd leadership from machine that is being deleted #2525

Merged
merged 1 commit into from
Mar 17, 2020
Merged

✨Forward etcd leadership from machine that is being deleted #2525

merged 1 commit into from
Mar 17, 2020

Conversation

alexander-demicev
Copy link
Contributor

@alexander-demicev alexander-demicev commented Mar 4, 2020

During the scaledown process, we need to be sure that the control plane machine that is about to be deleted is not etcd leader. This PR always moves the leadership to the first follower. It also introduces a few minor changes to etcd client, it missed the ability to get the leader ID

Closes #2398

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 4, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @alexander-demichev. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 4, 2020
@k8s-ci-robot k8s-ci-robot requested review from chuckha and vincepri March 4, 2020 15:08
Copy link
Contributor

@chuckha chuckha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few points to address, but i like this approach!

controlplane/kubeadm/internal/etcd/etcd.go Outdated Show resolved Hide resolved
controlplane/kubeadm/internal/workload_cluster.go Outdated Show resolved Hide resolved
controlplane/kubeadm/internal/workload_cluster.go Outdated Show resolved Hide resolved
controlplane/kubeadm/internal/workload_cluster.go Outdated Show resolved Hide resolved
@chuckha
Copy link
Contributor

chuckha commented Mar 4, 2020

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 4, 2020
@chuckha
Copy link
Contributor

chuckha commented Mar 4, 2020

/assign

@chuckha
Copy link
Contributor

chuckha commented Mar 4, 2020

/milestone v0.3.0

@k8s-ci-robot k8s-ci-robot added this to the v0.3.0 milestone Mar 4, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 4, 2020
@alexander-demicev alexander-demicev changed the title ✨[WIP] Forward etcd leadship from machine that is being deleted ✨Forward etcd leadship from machine that is being deleted Mar 5, 2020
@alexander-demicev alexander-demicev changed the title ✨Forward etcd leadship from machine that is being deleted ✨Forward etcd leadership from machine that is being deleted Mar 5, 2020
@@ -755,6 +761,12 @@ func (r *KubeadmControlPlaneReconciler) reconcileDelete(ctx context.Context, clu
for i := range machinesToDelete {
m := machinesToDelete[i]
logger := logger.WithValues("machine", m)
// If etcd leadership is on machine that is about to be deleted, move it to first follower
if err := workloadCluster.ForwardEtcdLeadership(ctx, m); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me the advantages of doing this.

We appear to be removing a cluster with this operation. All the other machines are gone. We get to this section, we're deleting the remaining control plane machines. Since we cordon and drain before a machine is deleted, it appears that we'll just assign etcd into a circle: 1->2->3->1 by the time this for loop completes. It's also not clear why we need to do this at all, since the cluster is going away.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! The original intention was to do this for control plane scale down operations rather than control plane deletion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@detiber that makes a lot more sense. I thought it was something like that, but the linked issue was not very specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 5, 2020
@vincepri
Copy link
Member

vincepri commented Mar 9, 2020

Moving this out of v0.3.0 given that it looks like an improvement that can go in later

/milestone v0.3.x

@k8s-ci-robot k8s-ci-robot modified the milestones: v0.3.0, v0.3.x Mar 9, 2020
@vincepri
Copy link
Member

@alexander-demichev are you still interested in working on this change?

@vincepri
Copy link
Member

per @michaelgugino comment, we need to make sure to focus the change only to target upgrades, rather than doing this when we're deleting the whole cluster. Ideally, it'd be great to move etcd leadership to the first newly-created machine during an upgrade process, this will probably ensure that the leader is stable during the upgrade process and minimize possible disruptions.

@alexander-demicev
Copy link
Contributor Author

@vincepri Yes, I'm still interested in this :)

@k8s-ci-robot k8s-ci-robot removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 13, 2020
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 13, 2020
Copy link
Contributor

@chuckha chuckha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep private identifiers private unless they need to become public

@alexander-demicev
Copy link
Contributor Author

@chuckha fixed

@chuckha
Copy link
Contributor

chuckha commented Mar 13, 2020

I think some basic unit tests in the workload_cluster_test.go file would be really good to add. We won't need to add anything to the reconciler as that logic doesn't need testing there. It might be nice to add an e2e test for scale down, but that, i think, is outside the scope of this PR and can be done in parallel to this work.

/approve
/assign @vincepri

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexander-demichev, chuckha

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 13, 2020
Comment on lines +518 to +519
if member.ID != currentMember.ID {
err := etcdClient.MoveLeader(ctx, member.ID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should make sure that the new member isn't a machine that's going to be deleted, a (potential) simple solution would be to always pick the last created machine/etcd member

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexander-demichev do you have time to tackle the above? or we can do it in a follow-up PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are fine with this PR then feel free to merge. A follow-up sounds good, if that's not urgent I can try to make something during the week.

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 17, 2020
@vincepri
Copy link
Member

/milestone v0.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KCP: ensure machine that is being deleted during upgrades or scale down isn't the etcd leader
6 participants