Skip to content

Commit

Permalink
do not always error out while checking for existence of resources
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
leelavg committed Oct 15, 2024
1 parent 9ad05e2 commit 92ee7aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions internal/controller/clientprofile_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.clientProfile.UID == "" {
r.log.Info("Client profile resource does not exists anymore, skipping reconcile")
return nil
}
return err
}

Expand Down
6 changes: 5 additions & 1 deletion internal/controller/driver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.driver.UID == "" {
r.log.Info("Driver resource does not exist anymore, skipping reconcile")
return nil
}
return err
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 92ee7aa

Please sign in to comment.