Skip to content

Commit

Permalink
Allow to delete machine not linked to any node
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ingvagabund committed Feb 20, 2019
1 parent a861de9 commit c6ca736
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions pkg/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package machine

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit c6ca736

Please sign in to comment.