From d9b055f962598d4b0e99cddb2e2e5fb49e8aa219 Mon Sep 17 00:00:00 2001 From: Carlos Salas Date: Sun, 10 Nov 2024 09:49:49 +0100 Subject: [PATCH] fix: wrap error when nodepool update/delete fails Signed-off-by: Carlos Salas --- cloud/services/container/nodepools/reconcile.go | 2 +- exp/controllers/gcpmanagedmachinepool_controller.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cloud/services/container/nodepools/reconcile.go b/cloud/services/container/nodepools/reconcile.go index 1f91c2f5c..a643ac0ec 100644 --- a/cloud/services/container/nodepools/reconcile.go +++ b/cloud/services/container/nodepools/reconcile.go @@ -149,7 +149,7 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) { log.Info("Node pool config update required", "request", nodePoolUpdateConfigRequest) err = s.updateNodePoolConfig(ctx, nodePoolUpdateConfigRequest) if err != nil { - return ctrl.Result{}, fmt.Errorf("node pool config update (either version/labels/taints/locations/image type/network tag/linux node config or all) failed: %s", err) + return ctrl.Result{}, fmt.Errorf("node pool config update (either version/labels/taints/locations/image type/network tag/linux node config or all) failed: %w", err) } log.Info("Node pool config updating in progress") s.scope.GCPManagedMachinePool.Status.Ready = true diff --git a/exp/controllers/gcpmanagedmachinepool_controller.go b/exp/controllers/gcpmanagedmachinepool_controller.go index 9d11b0d62..92042ccab 100644 --- a/exp/controllers/gcpmanagedmachinepool_controller.go +++ b/exp/controllers/gcpmanagedmachinepool_controller.go @@ -336,11 +336,12 @@ func (r *GCPManagedMachinePoolReconciler) reconcile(ctx context.Context, managed var e *apierror.APIError if ok := errors.As(err, &e); ok { if e.GRPCStatus().Code() == codes.FailedPrecondition { - log.Info("Cannot perform update when there's other operation, retry later", "reconciler", name) + log.Info("Cannot perform update while another operation is running, requeuing", "reconciler", name) return ctrl.Result{RequeueAfter: reconciler.DefaultRetryTime}, nil } } log.Error(err, "Reconcile error", "reconciler", name) + record.Warnf(managedMachinePoolScope.GCPManagedMachinePool, "GCPManagedMachinePoolReconcile", "Reconcile error - %v", err) return ctrl.Result{}, err } @@ -369,6 +370,13 @@ func (r *GCPManagedMachinePoolReconciler) reconcileDelete(ctx context.Context, m log.V(4).Info("Calling reconciler delete", "reconciler", name) res, err := r.Delete(ctx) if err != nil { + var e *apierror.APIError + if ok := errors.As(err, &e); ok { + if e.GRPCStatus().Code() == codes.FailedPrecondition { + log.Info("Cannot perform delete while another operation is running, requeuing", "reconciler", name) + return ctrl.Result{RequeueAfter: reconciler.DefaultRetryTime}, nil + } + } log.Error(err, "Reconcile error", "reconciler", name) record.Warnf(managedMachinePoolScope.GCPManagedMachinePool, "GCPManagedMachinePoolReconcile", "Reconcile error - %v", err) return ctrl.Result{}, err