From d46afba24294acd728cfabd0d7bd2afb8573a10d Mon Sep 17 00:00:00 2001 From: lubedacht <132355999+lubedacht@users.noreply.github.com> Date: Tue, 25 Jun 2024 17:33:38 +0200 Subject: [PATCH] :bug: Fix deletion patch error (#163) Co-authored-by: Jonas Riedel <138458199+jriedel-ionos@users.noreply.github.com> --- internal/controller/ionoscloudmachine_controller.go | 9 +++++++-- internal/controller/util.go | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/controller/ionoscloudmachine_controller.go b/internal/controller/ionoscloudmachine_controller.go index 75fc4e42..c3c7731f 100644 --- a/internal/controller/ionoscloudmachine_controller.go +++ b/internal/controller/ionoscloudmachine_controller.go @@ -220,7 +220,7 @@ func (r *IonosCloudMachineReconciler) reconcileDelete( if requeue { log.Info("Deletion request is still in progress") - return ctrl.Result{RequeueAfter: defaultReconcileDuration}, nil + return ctrl.Result{RequeueAfter: reducedReconcileDuration}, nil } reconcileSequence := []serviceReconcileStep[scope.Machine]{ @@ -242,7 +242,6 @@ func (r *IonosCloudMachineReconciler) reconcileDelete( return ctrl.Result{RequeueAfter: defaultReconcileDuration}, err } } - controllerutil.RemoveFinalizer(machineScope.IonosMachine, infrav1.MachineFinalizer) return ctrl.Result{}, nil } @@ -291,6 +290,12 @@ func (*IonosCloudMachineReconciler) checkRequestStates( return nil }, ) + + // We need to patch the machine during the deletion phase to make sure we do + // not have a diff in the status during the final patch when the finalizer is removed. + if !machineScope.IonosMachine.DeletionTimestamp.IsZero() { + requeue, retErr = true, machineScope.PatchObject() + } } } diff --git a/internal/controller/util.go b/internal/controller/util.go index 4c4aa5f3..2cf13300 100644 --- a/internal/controller/util.go +++ b/internal/controller/util.go @@ -36,6 +36,7 @@ import ( const ( defaultReconcileDuration = time.Second * 20 + reducedReconcileDuration = time.Second * 10 ) type serviceReconcileStep[T scope.Cluster | scope.Machine] struct {