diff --git a/pkg/controller/machine/controller.go b/pkg/controller/machine/controller.go index 00b9c77f3dc9..d94ab0604adc 100644 --- a/pkg/controller/machine/controller.go +++ b/pkg/controller/machine/controller.go @@ -154,6 +154,16 @@ func (r *ReconcileMachine) Reconcile(request reconcile.Request) (reconcile.Resul return reconcile.Result{}, err } + if m.Status.NodeRef != nil { + klog.Infof("Deleting node %q", m.Status.NodeRef.Name) + var node corev1.Node + if err := r.Client.Get(ctx, client.ObjectKey{Name: m.Status.NodeRef.Name}, &node); err != nil { + klog.Warningf("Failed to get node %q for machine %q: %v", m.Status.NodeRef.Name, m.Name, err) + } else if err := r.Client.Delete(ctx, &node); err != nil { + klog.Warningf("Failed to delete node %q for machine %q: %v", m.Status.NodeRef.Name, m.Name, err) + } + } + // Remove finalizer on successful deletion. klog.Infof("machine object %v deletion successful, removing finalizer.", name) m.ObjectMeta.Finalizers = util.Filter(m.ObjectMeta.Finalizers, clusterv1.MachineFinalizer)