From 30f59c6c963104afb259173132a3cf9f1f334f18 Mon Sep 17 00:00:00 2001 From: Enxebre Date: Fri, 8 Mar 2019 09:39:49 +0100 Subject: [PATCH] Delete node on machine deletion --- pkg/controller/machine/controller.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/controller/machine/controller.go b/pkg/controller/machine/controller.go index 00b9c77f3dc9..5f3b2c8a6f40 100644 --- a/pkg/controller/machine/controller.go +++ b/pkg/controller/machine/controller.go @@ -154,6 +154,17 @@ 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 + key := client.ObjectKey{Namespace: "", Name: m.Status.NodeRef.Name} + if err := r.Client.Get(ctx, key, &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)