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 30f59c6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/controller/machine/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 30f59c6

Please sign in to comment.