rancher: [BUG] rancher machines are not removed from the cluster after actual worker nodes removed
Rancher Server Setup
- Rancher version: 2.7.9, 2.8.0
- Installation option (Docker install/Helm Chart): helm
- If Helm Chart, Kubernetes Cluster and version (RKE1, RKE2, k3s, EKS, etc):
- Proxy/Cert Details: none
Information about the Cluster
- Kubernetes version: 1.27.8
- Cluster Type (Local/Downstream): downstream custom rke2 on hosted on aws
- If downstream, what type of cluster? (Custom/Imported or specify provider for Hosted/Infrastructure Provider):
User Information
- What is the role of the user logged in? (Admin/Cluster Owner/Cluster Member/Project Owner/Project Member/Custom)
- If custom, define the set of permissions:
Describe the bug
After upgrade from 2.7.5 to 2.7.9 I’ve noticed that terminated worker nodes are still displayed on rancher UI with Nodenotfound status.
capi-controller-manager: is full of errors like:
E1204 17:41:44.435523 1 controller.go:329] "Reconciler error" err="no matching Node for Machine \"custom-fbdc7789f02e\" in namespace \"fleet-default\": cannot find node with matching ProviderID" controller="machine" controllerGroup="cluster.x-k8s.io" controllerKind="Machine" Machine="fleet-default/custom-fbdc7789f02e" namespace="fleet-default" name="custom-fbdc7789f02e" reconcileID=330124c5-1ffb-4f7d-a618-94a976c62106
E1204 17:41:44.585423 1 controller.go:329] "Reconciler error" err="no matching Node for Machine \"custom-be9d831e6358\" in namespace \"fleet-default\": cannot find node with matching ProviderID" controller="machine" controllerGroup="cluster.x-k8s.io" controllerKind="Machine" Machine="fleet-default/custom-be9d831e6358" namespace="fleet-default" name="custom-be9d831e6358" reconcileID=63186033-4f57-4524-85af-2123a88f3a04
machine resource mentioned in the error still exists:
k -n fleet-default get machine | grep custom-be9d831e6358
custom-be9d831e6358 rancher-euc1-te-test01 ip-172-29-196-238.eu-central-1.compute.internal aws:///eu-central-1a/i-0a82b430f14175488 Running 5h6m
but nodes.management.cattle.io resources for old workers are gone
Also in downstream rke2 cluster k get nodes doesn’t show these old nodes, so it is only affecting rancher.
To Reproduce
- Terminate active running node
Result
After node is terminated it is removed from the cluster but it is not removed from rancher and node still displayed on UI in Nodenotfound status.
Expected Result After node is terminated it is removed from the cluster and it is also removed from rancher.
Screenshots
Additional context In slack other ppl mentioned that they have same issue starting from version 2.7.6 https://rancher-users.slack.com/archives/C3ASABBD1/p1701711546706849\
SURE-8277
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 43 (11 by maintainers)
@snasovich I’m going to go ahead and re-open this issue.
While the original intention of removing this behavior was to better align with other providers upstream, I do believe there is merit for the various use-cases stated here (primarily auto scaling) that would benefit from a workflow that allows v1.Node objects to be deleted and have their corresponding CAPI machines cleaned up.
I believe we can re-add this behavior, but make it opt-in. Once enabled, the custom node controller in the CAPR infrastructure provider would reconcile/delete the corresponding CAPI machine objects if it sees a removal of the custom node. To those commenting on this issue that are affected by the change in behavior – would that work?
@snasovich I’m not following how this is by design? This basically means any use of autoscaling (cluster autoscaler, karpenter, manual scaling of underlying cloud resources) will leave lingering nodes within the cluster with no means for reconciliation, except for the temporary solutions posted above.
We have also noticed that upgrading cluster version, or applying any projects, roles, and mappings fail to go through since the cluster is not in an
Activestate when there is aNodeNotFoundmachine present.What’s the appropriate method to trigger
deleted through trigger/removal of the CAPI Machine object@jdbaudean yeah, that is why I put that script into a cron job which is running every 15minutes to make sure that machine with state
NodeNotFoundis removed as soon as it gets in to that state. In your case you might need to adjust interval.Oh, I just realised that
rke.cattle.io/delete-missing-custom-machines-after: '5s'annotation for thecluster.provisioning.cattle.ionot for individual machine! Works as expected now with that annotation on a cluster. 🎉Ticket #43686 - Test Results - ✅
Verified on Rancher
v2.9-1c2b815c8dd66e141b21630904127adc8e03c3de-head:Scenario 1 - ✅
v2.9-headactive, take a snapshotCluster Explorer > Nodesand delete a worker node, then delete the associated instance on the cloud provider sideNodeNotFoundstatus is seen on the machine of the terminated node viaCluster Management > Machines; as expectedScenario 2 - ✅
v2.9-headactive, take a snapshotCluster Explorer > Nodesand delete a worker node, then delete the associated instance on the cloud provider sideNodeNotFoundstatus is seen on the machine of the terminated node viaCluster Management > Machines; as expectedScenario 3 - ✅
Edit YAML, and apply the following annotation:activeand accurately reflects 1:1 ratio of nodes to machines; as expectedScenario 4 - ✅
Edit YAML, and apply the following annotation:activeand accurately reflects 1:1 ratio of nodes to machines; as expectedScenario 5 - ✅
v2.9-headactive, take a snapshotNodeNotFoundstatusEdit YAMLand apply annotation, then upgrade k8s version to 1.30Scenario 6 - ✅
v2.9-headactive, take a snapshotNodeNotFoundstatusEdit YAMLand apply annotation, then upgrade k8s version to 1.30@jdbaudean , my bad - missed that part - thank you for pointing me to it.
@snasovich We have noticed that leaving these abandoned machines in
NodeNotFoundstatus on large clusters with dynamic leads to the state where there are hundreds of abandoned machines and even rancher UI is struggling with loading cluster management view. This brakes custom node pools support.@snasovich So far this happens when I delete a node from the cluster via the Rancher UI, delete a node using
kubectl delete node <node-name>, and when the cluster-autoscaler removes nodes. That is by design?As I also mentioned, if I try to go into cluster management and clean up the
Nodenotfoundnodes myself, Rancher will remove any node with the same Node name.@okgolove That is exactly what I did, and put that into a CronJob but still looking forward for proper fix 😕
To clarify, when using provisioningv2,
cluster-apiis the component responsible for performing the drain and cordon of your node. It’s definitely not ideal that you’re ending up in a situation where you have multiple machines that reference the same node – ideallycluster-apiwould refer to the node using theuidof thev1/Nodeobject which would prevent that situation; however, it does not seem that it does that based on the behavior you’ve described. I’ll need to do some digging into determining a workaround for that specific situation.I’m seeing this exact same behavior in 2.7.9. This happens every time the cluster-autoscaler removes a node, I assumed it was an issue with the cluster-autoscaler or my aws-cloud-provider config.
Unfortunately the slack link referenced above is older than 90 days, so historical context within that thread is lost.
I can confirm that this is still a problem with v2.8.2 of rancher on a clean install, which is using v1.4.4 of the cluster-api controller. After a bit of investigation the problem why this is happening is because the
.metadata.deletionTimestampfield is never set on the machine resource, this is preventing the cluster-api controller from reconciling the deletion of machine resources.Relevant code can be seen here: https://github.com/kubernetes-sigs/cluster-api/blob/00dbf7b9f6322d7ebd06ae2efa703b23354dd37d/internal/controllers/machine/machine_controller.go#L209-L219
I have checked the historic and future code of the cluster-api controller and this logic hasn’t changed on their side. Perhaps @Oats87 you might have some insight as to where this was previously happening within the rancher code base, and or where we should be hoping to introduce the necessary changes to correctly set the deletion timestamp.
This can easily be reproduced, by simply watching the
cattle-provisioning-capi-systempod logs then deleting a machine resource that had previously failed to reconcile.@okgolove I was trying to upgrade from 2.7.5 to 2.8.0 but I think this regression was introduced in 2.7.6