This is an automated email from the ASF dual-hosted git repository.

houston pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr-operator.git


The following commit(s) were added to refs/heads/main by this push:
     new c3cda10  Fix non-recurring backups (#509)
c3cda10 is described below

commit c3cda1075f0a335fdb5c2054405b6a8edb9fc09c
Author: Houston Putman <[email protected]>
AuthorDate: Fri Dec 23 12:18:52 2022 -0600

    Fix non-recurring backups (#509)
---
 controllers/solrbackup_controller.go | 21 ++++++++++-----------
 helm/solr-operator/Chart.yaml        |  5 +++++
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/controllers/solrbackup_controller.go 
b/controllers/solrbackup_controller.go
index b73fd16..dfffd52 100644
--- a/controllers/solrbackup_controller.go
+++ b/controllers/solrbackup_controller.go
@@ -92,17 +92,18 @@ func (r *SolrBackupReconciler) Reconcile(ctx 
context.Context, req ctrl.Request)
 
        requeueOrNot := reconcile.Result{}
 
-       var backupNeedsToWait bool
+       // Backup work needs to be done by default if the current backup is not 
finished
+       doBackupWork := !backup.Status.IndividualSolrBackupStatus.Finished
 
        // Check if we should start the next backup
-       if backup.Status.NextScheduledTime != nil {
-               // If the backup no longer enabled, remove the next scheduled 
time
+       // Do not check if already doing a backup
+       if !doBackupWork && backup.Status.NextScheduledTime != nil {
                if !backup.Spec.Recurrence.IsEnabled() {
                        backup.Status.NextScheduledTime = nil
-                       backupNeedsToWait = false
+                       doBackupWork = false
                } else if 
backup.Status.NextScheduledTime.UTC().Before(time.Now().UTC()) {
                        // We have hit the next scheduled restart time.
-                       backupNeedsToWait = false
+                       doBackupWork = true
                        backup.Status.NextScheduledTime = nil
 
                        // Add the current backup to the front of the history.
@@ -119,14 +120,12 @@ func (r *SolrBackupReconciler) Reconcile(ctx 
context.Context, req ctrl.Request)
                } else {
                        // If we have not hit the next scheduled restart, wait 
to requeue until that is true.
                        updateRequeueAfter(&requeueOrNot, 
backup.Status.NextScheduledTime.UTC().Sub(time.Now().UTC()))
-                       backupNeedsToWait = true
+                       doBackupWork = false
                }
-       } else {
-               backupNeedsToWait = false
        }
 
-       // Do backup work if we are not waiting and the current backup is not 
finished
-       if !backupNeedsToWait && 
!backup.Status.IndividualSolrBackupStatus.Finished {
+       // Do backup work if a backup is in-progress or needs to be started
+       if doBackupWork {
                solrCloud, _, err1 := r.reconcileSolrCloudBackup(ctx, backup, 
&backup.Status.IndividualSolrBackupStatus, logger)
                if err1 != nil {
                        // TODO Should we be failing the backup for some 
sub-set of errors here?
@@ -146,7 +145,7 @@ func (r *SolrBackupReconciler) Reconcile(ctx 
context.Context, req ctrl.Request)
        }
 
        // Schedule the next backupTime, if it doesn't have a next scheduled 
time, it has recurrence and the current backup is finished
-       if backup.Status.IndividualSolrBackupStatus.Finished {
+       if backup.Status.IndividualSolrBackupStatus.Finished && 
backup.Spec.Recurrence.IsEnabled() {
                if nextBackupTime, err1 := 
util.ScheduleNextBackup(backup.Spec.Recurrence.Schedule, 
backup.Status.IndividualSolrBackupStatus.StartTime.Time); err1 != nil {
                        logger.Error(err1, "Could not update backup scheduling 
due to bad cron schedule", "cron", backup.Spec.Recurrence.Schedule)
                } else {
diff --git a/helm/solr-operator/Chart.yaml b/helm/solr-operator/Chart.yaml
index 6b45ffc..bf82466 100644
--- a/helm/solr-operator/Chart.yaml
+++ b/helm/solr-operator/Chart.yaml
@@ -89,6 +89,11 @@ annotations:
       links:
         - name: GitHub PR
           url: https://github.com/apache/solr-operator/pull/512/files
+    - kind: fixed
+      description: Fix bug in non-recurring SolrBackups
+      links:
+        - name: GitHub PR
+          url: https://github.com/apache/solr-operator/pull/509
   artifacthub.io/images: |
     - name: solr-operator
       image: apache/solr-operator:v0.7.0-prerelease

Reply via email to