From c6ca73688c9dd48d25eb56dc50a04968bf4edc32 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Thu, 21 Feb 2019 00:37:07 +0100 Subject: [PATCH] Allow to delete machine not linked to any node If a machine is not linked to a node, just delete the machine. Since a node can be unlinked from a machine when the node goes NotReady and is removed by cloud controller manager. In that case some machines would never get deleted without a manual intervention. --- pkg/actuators/machine/actuator.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/actuators/machine/actuator.go b/pkg/actuators/machine/actuator.go index d73d3b2ca1..40325467b5 100644 --- a/pkg/actuators/machine/actuator.go +++ b/pkg/actuators/machine/actuator.go @@ -18,7 +18,6 @@ package machine import ( "context" - "errors" "fmt" "time" @@ -257,13 +256,11 @@ func (gl *glogLogger) Logf(format string, v ...interface{}) { // DeleteMachine deletes an AWS instance func (a *Actuator) DeleteMachine(cluster *machinev1.Cluster, machine *machinev1.Machine) error { // Drain node before deleting - if _, exists := machine.ObjectMeta.Annotations[ExcludeNodeDrainingAnnotation]; !exists { - if machine.Status.NodeRef == nil { - // Draining a node of a machine without a node needs to be explicitely inspected - err := errors.New("draining node without a node reference during machine deletion operation is forbidden") - glog.Error(err) - return err - } + // If a machine is not linked to a node, just delete the machine. Since a node + // can be unlinked from a machine when the node goes NotReady and is removed + // by cloud controller manager. In that case some machines would never get + // deleted without a manual intervention. + if _, exists := machine.ObjectMeta.Annotations[ExcludeNodeDrainingAnnotation]; !exists && machine.Status.NodeRef != nil { glog.Infof("Draining node before delete") if a.config == nil { err := fmt.Errorf("missing client config, unable to build kube client")