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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fix node deletion under managed control planes #3673

Merged
merged 1 commit into from Sep 30, 2020

Conversation

dthorsen
Copy link
Contributor

What this PR does / why we need it:
This PR allows the Machine controller to drain and delete Nodes when running under managed control planes.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #3631

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 22, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @dthorsen!

It looks like this is your first PR to kubernetes-sigs/cluster-api 馃帀. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 馃槂

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 22, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @dthorsen. 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/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 22, 2020
@dthorsen
Copy link
Contributor Author

@vincepri As far as I know node objects for control plane are only used under a kubeadm control plane. EKS and GKE don't list control plane nodes.

@dthorsen dthorsen changed the title 馃悰 Always delete nodes except under kubeadm control plane 馃悰 Always delete nodes except under kubeadm control plane Sep 22, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 25, 2020
@dthorsen dthorsen changed the title 馃悰 Always delete nodes except under kubeadm control plane 馃悰 Fix node deletion under managed control planes Sep 25, 2020
@dthorsen dthorsen force-pushed the issue-3631 branch 2 times, most recently from 8dd9af0 to 64eda6d Compare September 25, 2020 20:43
@dthorsen dthorsen marked this pull request as ready for review September 25, 2020 20:45
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 25, 2020
@vincepri
Copy link
Member

/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 Sep 25, 2020
controllers/machine_controller.go Outdated Show resolved Hide resolved
controllers/machine_controller.go Outdated Show resolved Hide resolved
controllers/machine_helpers.go Outdated Show resolved Hide resolved
controllers/machine_controller.go Outdated Show resolved Hide resolved
controllers/machine_controller.go Outdated Show resolved Hide resolved
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.

/approve
/assign @ncdc

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

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 Sep 25, 2020
@dthorsen
Copy link
Contributor Author

@vincepri or @ncdc It occurred to me that maybe returning an error here:

https://github.com/kubernetes-sigs/cluster-api/pull/3673/files#diff-7ea69dfdf2e12f7bff0fb38e0c59e0b8R384

may also be a breaking change for non-externally-managed control plane clusters in the case of a 404. I think if this error is a 404 we should simply skip the call to util.IsExternalManagedControlPlane(controlPlane) and only return the error if it is any error other than a 404. This will probably avoid some edge cases where things could get stuck unable to drain correctly.

@vincepri
Copy link
Member

Good catch, we should fallback to the old logic (checking machines) if the error is NotFound

@dthorsen
Copy link
Contributor Author

@vincepri @ncdc I added the check for a NotFound error.

@dthorsen
Copy link
Contributor Author

/test pull-cluster-api-test

@vincepri
Copy link
Member

/milestone v0.3.10

@k8s-ci-robot k8s-ci-robot added this to the v0.3.10 milestone Sep 29, 2020
@vincepri
Copy link
Member

/assign @CecileRobertMichon

Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

lgtm for me, only a small thing that can be also addressed in a follow-up PR

// IsExternalManagedControlPlane returns a bool indicating whether the control plane referenced
// in the passed Unstructured resource is an externally managed control plane such as AKS, EKS, GKE, etc.
func IsExternalManagedControlPlane(controlPlane *unstructured.Unstructured) bool {
managed, found, err := unstructured.NestedBool(controlPlane.Object, "status", "externalManagedControlPlane")
Copy link
Member

Choose a reason for hiding this comment

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

Should we document somewhere that manage control plane implementation should have this field (might be in https://cluster-api.sigs.k8s.io/developer/architecture/controllers/control-plane.html#required-status-fields)

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 this isn't part of the contract currently AFAIK

cc @alexeldeib

Copy link
Member

Choose a reason for hiding this comment

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

+1 updating the documentation, just a note though the field is completely optional and there is a fallback to the current behavior during delete

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. What are thoughts on making this new field be an optional part of the contract to avoid a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an unusual case in that the field is really required for managed control planes like AKS, EKS, GKE, etc otherwise the Machine controller will suffer this pretty bad bug (instance termination without draining nodes), but not required at all for KubeadmControlPlane. No other optional status fields currently appear to modify functionality and are purely informational. If we make it a new required status field though, I think this would need to wait for a new minor version to be released. I'd like to get the bugfix released sooner rather than later if possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm 馃憤 to optional. Please update the control plane architecture doc linked above and add it to the list of optional status fields, assuming everyone else agrees.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dthorsen dthorsen force-pushed the issue-3631 branch 2 times, most recently from 11ae6a8 to 717e5e4 Compare September 29, 2020 17:19

* `failureReason` - is a string that explains why an error has occurred, if possible.
* `failureMessage` - is a string that holds the message contained by the error.
* `externalManagedControlPlane` - is a bool that should be set to true if the Node objects do not
exist in the cluster. For example, managed control plane providers for AKS, EKS, GKE, etc, should
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

(I think it should since we're using controlPlaneRef the same way)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CecileRobertMichon Yes, as long as you reference the AzureManagedControlPlane in the cluster's controlPlaneRef field you should be able to use the status in your resource as well. Since the check here in CAPI is using the unstructured API, the underlying type is not important. Whatever object is referenced by controlPlaneRef just needs to have the status field externalManagedControlPlane if there are no control plane Machine resources in the cluster.

Copy link
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

lgtm

@fabriziopandini
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 30, 2020
@k8s-ci-robot k8s-ci-robot merged commit 5754973 into kubernetes-sigs:master Sep 30, 2020
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CAPI won't delete Nodes in "managed" control planes because there are no control plane machines
6 participants