From 3c95be0b1f04de40baf6d8235cb9cb7bb6586af0 Mon Sep 17 00:00:00 2001 From: Emilio Garcia Date: Mon, 17 Aug 2020 12:49:51 -0400 Subject: [PATCH] allow users to manually delete machines stuck in crash loop --- .../pkg/controller/machine/controller.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/vendor/github.com/openshift/machine-api-operator/pkg/controller/machine/controller.go b/vendor/github.com/openshift/machine-api-operator/pkg/controller/machine/controller.go index 22b4768685..2c438c31c4 100644 --- a/vendor/github.com/openshift/machine-api-operator/pkg/controller/machine/controller.go +++ b/vendor/github.com/openshift/machine-api-operator/pkg/controller/machine/controller.go @@ -228,6 +228,19 @@ func (r *ReconcileMachine) Reconcile(request reconcile.Request) (reconcile.Resul } if err := r.actuator.Delete(ctx, m); err != nil { + // If you try to delete the instance and get a 404 response, it is common that the reconciler gets + // stuck in a delete loop. In order to break it, the user will need to manually delete the machine + // and whatever resource it is stuck looping on. + if errors.Is(err, errors.New("Resource not found")) { + // Remove finalizer so user can manually delete the machine + m.ObjectMeta.Finalizers = util.Filter(m.ObjectMeta.Finalizers, machinev1.MachineFinalizer) + if err := r.Client.Update(context.Background(), m); err != nil { + klog.Errorf("%v: failed to remove finalizer from machine: %v", machineName, err) + return reconcile.Result{}, err + } + klog.V(3).Infof("instance %v could not be deleted. The finalizer has been removed, please manually delete the machine and node", machineName) + return reconcile.Result{}, err + } // isInvalidMachineConfiguration will take care of the case where the // configuration is invalid from the beginning. len(m.Status.Addresses) > 0 // will handle the case when a machine configuration was invalidated