Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/apis/machine/v1beta1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const (
// MachineClusterIDLabel is the label that a machine must have to identify the
// cluster to which it belongs.
MachineClusterIDLabel = "machine.openshift.io/cluster-api-cluster"

// PreserveInstanceAnnotation prevents a VM from being deleted by the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a justification why we need this atm? If not, I'd prefer to not introduce it in this PR

// machine-controller and will cause machine-controller to requeue.
PreserveInstanceAnnotation = "machine.openshift.io/preserve-instance"
)

// +genclient
Expand Down
20 changes: 2 additions & 18 deletions pkg/controller/machine/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,24 +335,8 @@ func (r *ReconcileMachine) getCluster(ctx context.Context, machine *machinev1.Ma
}

func (r *ReconcileMachine) isDeleteAllowed(machine *machinev1.Machine) bool {
if r.nodeName == "" || machine.Status.NodeRef == nil {
return true
}

if machine.Status.NodeRef.Name != r.nodeName {
return true
}

node := &corev1.Node{}
if err := r.Client.Get(context.Background(), client.ObjectKey{Name: r.nodeName}, node); err != nil {
klog.Infof("Failed to determine if controller's node %q is associated with machine %q: %v", r.nodeName, machine.Name, err)
return true
}

// When the UID of the machine's node reference and this controller's actual node match then then the request is to
// delete the machine this machine-controller is running on. Return false to not allow machine controller to delete its
// own machine.
return node.UID != machine.Status.NodeRef.UID
_, exists := machine.ObjectMeta.Annotations[machinev1.PreserveInstanceAnnotation]
return !exists
}

func (r *ReconcileMachine) deleteNode(ctx context.Context, name string) error {
Expand Down