Skip to content

Commit

Permalink
Remove unnecessary requeues (#1153)
Browse files Browse the repository at this point in the history
  • Loading branch information
adejanovski authored Jan 5, 2024
1 parent b946345 commit 6e668b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG/CHANGELOG-1.12.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ When cutting a new release, update the `unreleased` heading to the tag being gen

## unreleased

- [ENHANCEMENT] [#1115](https://github.com/k8ssandra/k8ssandra-operator/issues/1115) Add a validation check for the projected pod names length
- [ENHANCEMENT] [#1115](https://github.com/k8ssandra/k8ssandra-operator/issues/1115) Add a validation check for the projected pod names length
* [CHANGE] [#1050](https://github.com/k8ssandra/k8ssandra-operator/issues/1050) Remove unnecessary requeues in the Medusa controllers
18 changes: 9 additions & 9 deletions controllers/medusa/medusabackupjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (r *MedusaBackupJobReconciler) Reconcile(ctx context.Context, req ctrl.Requ
if errors.IsNotFound(err) {
return ctrl.Result{}, nil
}
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}

backup := instance.DeepCopy()
Expand All @@ -79,18 +79,18 @@ func (r *MedusaBackupJobReconciler) Reconcile(ctx context.Context, req ctrl.Requ
err = r.Get(ctx, cassdcKey, cassdc)
if err != nil {
logger.Error(err, "failed to get cassandradatacenter", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}

// Set an owner reference on the backup job so that it can be cleaned up when the cassandra datacenter is deleted
if backup.OwnerReferences == nil {
if err = controllerutil.SetControllerReference(cassdc, backup, r.Scheme); err != nil {
logger.Error(err, "failed to set controller reference", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}
if err = r.Update(ctx, backup); err != nil {
logger.Error(err, "failed to update MedusaBackupJob with owner reference", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
} else {
logger.Info("updated MedusaBackupJob with owner reference", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, nil
Expand All @@ -100,7 +100,7 @@ func (r *MedusaBackupJobReconciler) Reconcile(ctx context.Context, req ctrl.Requ
pods, err := medusa.GetCassandraDatacenterPods(ctx, cassdc, r, logger)
if err != nil {
logger.Error(err, "Failed to get datacenter pods")
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}

// If there is anything in progress, simply requeue the request until each pod has finished or errored
Expand Down Expand Up @@ -166,11 +166,11 @@ func (r *MedusaBackupJobReconciler) Reconcile(ctx context.Context, req ctrl.Requ
backupSummary, err := r.getBackupSummary(ctx, backup, pods, logger)
if err != nil {
logger.Error(err, "Failed to get backup summary")
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}
if err := r.createMedusaBackup(ctx, backup, backupSummary, logger); err != nil {
logger.Error(err, "Failed to create MedusaBackup")
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}

// Set the finish time
Expand All @@ -180,7 +180,7 @@ func (r *MedusaBackupJobReconciler) Reconcile(ctx context.Context, req ctrl.Requ
backup.Status.FinishTime = metav1.Now()
if err := r.Status().Patch(ctx, backup, patch); err != nil {
logger.Error(err, "failed to patch status with finish time")
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}

return ctrl.Result{Requeue: false}, nil
Expand All @@ -192,7 +192,7 @@ func (r *MedusaBackupJobReconciler) Reconcile(ctx context.Context, req ctrl.Requ
if !shared.IsMedusaDeployed(pods) {
// TODO generate event and/or update status to indicate error condition
logger.Error(medusa.BackupSidecarNotFound, "medusa is not deployed", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.LongDelay}, medusa.BackupSidecarNotFound
return ctrl.Result{}, medusa.BackupSidecarNotFound
}

patch := client.MergeFromWithOptions(backup.DeepCopy(), client.MergeFromWithOptimisticLock{})
Expand Down
14 changes: 7 additions & 7 deletions controllers/medusa/medusarestorejob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ func (r *MedusaRestoreJobReconciler) Reconcile(ctx context.Context, req ctrl.Req
err = r.Get(ctx, cassdcKey, cassdc)
if err != nil {
logger.Error(err, "failed to get cassandradatacenter", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}

// Set an owner reference on the restore job so that it can be cleaned up when the cassandra datacenter is deleted
if request.RestoreJob.OwnerReferences == nil {
if err = controllerutil.SetControllerReference(cassdc, request.RestoreJob, r.Scheme); err != nil {
logger.Error(err, "failed to set controller reference", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}
if err = r.Update(ctx, request.RestoreJob); err != nil {
logger.Error(err, "failed to update MedusaRestoreJob with owner reference", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
} else {
logger.Info("updated MedusaRestoreJob with owner reference", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, nil
Expand All @@ -110,7 +110,7 @@ func (r *MedusaRestoreJobReconciler) Reconcile(ctx context.Context, req ctrl.Req
request.RestoreJob.Status.Message = err.Error()
if err = r.Status().Update(ctx, request.RestoreJob); err != nil {
logger.Error(err, "failed to update MedusaRestoreJob with error message", "MedusaRestoreJob", req.NamespacedName.Name)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}

logger.Error(fmt.Errorf("unable to use target backup for restore of CassandraDatacenter: %s", request.RestoreJob.Status.Message), "backup can not be used for restore")
Expand Down Expand Up @@ -149,7 +149,7 @@ func (r *MedusaRestoreJobReconciler) Reconcile(ctx context.Context, req ctrl.Req
if err != nil {
request.Log.Error(err, "Failed to check if datacenter update is complete")
// Not going to bother applying updates here since we hit an error.
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}

if !complete {
Expand All @@ -173,7 +173,7 @@ func (r *MedusaRestoreJobReconciler) Reconcile(ctx context.Context, req ctrl.Req

request.SetMedusaRestoreFinishTime(metav1.Now())
if err := r.applyUpdates(ctx, request); err != nil {
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}

request.Log.Info("The restore operation is complete")
Expand Down Expand Up @@ -206,7 +206,7 @@ func (r *MedusaRestoreJobReconciler) applyUpdates(ctx context.Context, req *medu
func (r *MedusaRestoreJobReconciler) applyUpdatesAndRequeue(ctx context.Context, req *medusa.RestoreRequest) (ctrl.Result, error) {
if err := r.applyUpdates(ctx, req); err != nil {
req.Log.Error(err, "Failed to apply updates")
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}
return ctrl.Result{RequeueAfter: r.DefaultDelay}, nil
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/medusa/medusatask_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ func (r *MedusaTaskReconciler) Reconcile(ctx context.Context, req ctrl.Request)
err = r.Get(ctx, cassdcKey, cassdc)
if err != nil {
logger.Error(err, "failed to get cassandradatacenter", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}

// Set an owner reference on the task so that it can be cleaned up when the cassandra datacenter is deleted
if task.OwnerReferences == nil {
if err = controllerutil.SetControllerReference(cassdc, task, r.Scheme); err != nil {
logger.Error(err, "failed to set controller reference", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
}
if err = r.Update(ctx, task); err != nil {
logger.Error(err, "failed to update task with owner reference", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, err
return ctrl.Result{}, err
} else {
logger.Info("updated task with owner reference", "CassandraDatacenter", cassdcKey)
return ctrl.Result{RequeueAfter: r.DefaultDelay}, nil
Expand Down

0 comments on commit 6e668b1

Please sign in to comment.