From 6e668b11d778c920f289bf77ef73fab625fd81f1 Mon Sep 17 00:00:00 2001 From: Alexander Dejanovski Date: Fri, 5 Jan 2024 16:18:08 +0100 Subject: [PATCH] Remove unnecessary requeues (#1153) --- CHANGELOG/CHANGELOG-1.12.md | 3 ++- .../medusa/medusabackupjob_controller.go | 18 +++++++++--------- .../medusa/medusarestorejob_controller.go | 14 +++++++------- controllers/medusa/medusatask_controller.go | 6 +++--- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/CHANGELOG/CHANGELOG-1.12.md b/CHANGELOG/CHANGELOG-1.12.md index 598182305..013836a84 100644 --- a/CHANGELOG/CHANGELOG-1.12.md +++ b/CHANGELOG/CHANGELOG-1.12.md @@ -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 \ No newline at end of file +- [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 diff --git a/controllers/medusa/medusabackupjob_controller.go b/controllers/medusa/medusabackupjob_controller.go index 347a07514..5e9399a5e 100644 --- a/controllers/medusa/medusabackupjob_controller.go +++ b/controllers/medusa/medusabackupjob_controller.go @@ -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() @@ -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 @@ -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 @@ -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 @@ -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 @@ -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{}) diff --git a/controllers/medusa/medusarestorejob_controller.go b/controllers/medusa/medusarestorejob_controller.go index 3308acc96..4da5cf73b 100644 --- a/controllers/medusa/medusarestorejob_controller.go +++ b/controllers/medusa/medusarestorejob_controller.go @@ -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 @@ -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") @@ -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 { @@ -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") @@ -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 } diff --git a/controllers/medusa/medusatask_controller.go b/controllers/medusa/medusatask_controller.go index 6f265a0f8..ec9d0419f 100644 --- a/controllers/medusa/medusatask_controller.go +++ b/controllers/medusa/medusatask_controller.go @@ -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