From a8cc297997324939ed7a5b89143b5e2da7519abf Mon Sep 17 00:00:00 2001 From: Leela Venkaiah G Date: Fri, 4 Oct 2024 05:29:46 +0000 Subject: [PATCH] do not always error out while checking for existence of resources controllers also get reconciles for deletion events and it may happen that resource at api server be deleted first before it being purged from cache and during that time if we error out the reconciliation will never be successful in standard conditions. Signed-off-by: Leela Venkaiah G --- internal/controller/clientprofile_controller.go | 5 +++++ internal/controller/driver_controller.go | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/controller/clientprofile_controller.go b/internal/controller/clientprofile_controller.go index e47c3950..230c7ca8 100644 --- a/internal/controller/clientprofile_controller.go +++ b/internal/controller/clientprofile_controller.go @@ -25,6 +25,7 @@ import ( "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" + k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" @@ -130,6 +131,10 @@ func (r *ClientProfileReconciler) Reconcile(ctx context.Context, req ctrl.Reques func (r *ClientProfileReconcile) reconcile() error { if err := r.loadAndValidate(); err != nil { + if k8serrors.IsNotFound(err) { + r.log.Info("Client profile resource does not exists anymore, skipping reconcile") + return nil + } return err } diff --git a/internal/controller/driver_controller.go b/internal/controller/driver_controller.go index ba0616a9..7dbf99bd 100644 --- a/internal/controller/driver_controller.go +++ b/internal/controller/driver_controller.go @@ -226,6 +226,10 @@ func (r *DriverReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr func (r *driverReconcile) reconcile() error { // Load the driver desired state based on driver resource, operator config resource and default values. if err := r.LoadAndValidateDesiredState(); err != nil { + if k8serrors.IsNotFound(err) { + r.log.Info("Driver resource does not exist anymore, skipping reconcile") + return nil + } return err } @@ -255,7 +259,7 @@ func (r *driverReconcile) LoadAndValidateDesiredState() error { // (Can happen if a driver with an identical name was created in a different namespace) csiDriver := storagev1.CSIDriver{} csiDriver.Name = r.driver.Name - if err := r.Get(r.ctx, client.ObjectKeyFromObject(&csiDriver), &csiDriver); client.IgnoreNotFound(err) != nil { + if err := r.Get(r.ctx, client.ObjectKeyFromObject(&csiDriver), &csiDriver); err != nil { r.log.Error(err, "Failed to query the existence of a CSI Driver") return err }