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 4, 2024
1 parent 9ad05e2 commit d589960
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/controller/clientprofile_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (r *ClientProfileReconciler) Reconcile(ctx context.Context, req ctrl.Reques

func (r *ClientProfileReconcile) reconcile() error {
if err := r.loadAndValidate(); err != nil {
if client.IgnoreNotFound(err) == nil {
r.log.Info("Resources for reconciling clientprofile is not found. Object(s) might have been deleted.")
return nil
}
return err
}

Expand Down
8 changes: 6 additions & 2 deletions 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 client.IgnoreNotFound(err) == nil {
r.log.Info("Resources for reconciling driver is not found. Object(s) might have been deleted.")
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 Expand Up @@ -296,7 +300,7 @@ func (r *driverReconcile) LoadAndValidateDesiredState() error {
opConfig := csiv1a1.OperatorConfig{}
opConfig.Name = operatorConfigName
opConfig.Namespace = operatorNamespace
if err := r.Get(r.ctx, client.ObjectKeyFromObject(&opConfig), &opConfig); client.IgnoreNotFound(err) != nil {
if err := r.Get(r.ctx, client.ObjectKeyFromObject(&opConfig), &opConfig); err != nil {
r.log.Error(err, "Unable to load operatorconfig.csi.ceph.io", "name", client.ObjectKeyFromObject(&opConfig))
return err
}
Expand Down

0 comments on commit d589960

Please sign in to comment.