diff --git a/pkg/apis/machine/v1beta1/machine_types.go b/pkg/apis/machine/v1beta1/machine_types.go index 62ec393376ac..b38893541774 100644 --- a/pkg/apis/machine/v1beta1/machine_types.go +++ b/pkg/apis/machine/v1beta1/machine_types.go @@ -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 + // machine-controller and will cause machine-controller to requeue. + PreserveInstanceAnnotation = "machine.openshift.io/preserve-instance" ) // +genclient diff --git a/pkg/controller/machine/controller.go b/pkg/controller/machine/controller.go index f2f1711997e3..f36fcf0f70b5 100644 --- a/pkg/controller/machine/controller.go +++ b/pkg/controller/machine/controller.go @@ -313,6 +313,11 @@ func (r *ReconcileMachine) getCluster(ctx context.Context, machine *machinev1.Ma } func (r *ReconcileMachine) isDeleteAllowed(machine *machinev1.Machine) bool { + _, exists := machine.ObjectMeta.Annotations[machinev1.PreserveInstanceAnnotation] + if exists { + return false + } + if r.nodeName == "" || machine.Status.NodeRef == nil { return true }