Skip to content

Commit

Permalink
Delete node on machine deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre committed Mar 8, 2019
1 parent 9d16c16 commit 7bb8f6f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/controller/machine/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7bb8f6f

Please sign in to comment.