#273 Prevent make backup with the same number before pod deletion
This commit is contained in:
		
							parent
							
								
									ae945fbd63
								
							
						
					
					
						commit
						6b96d2dd94
					
				|  | @ -158,7 +158,7 @@ func (bar *BackupAndRestore) Restore(jenkinsClient jenkinsclient.Jenkins) error | |||
| } | ||||
| 
 | ||||
| // Backup performs Jenkins backup operation
 | ||||
| func (bar *BackupAndRestore) Backup() error { | ||||
| func (bar *BackupAndRestore) Backup(setBackupDoneBeforePodDeletion bool) error { | ||||
| 	jenkins := bar.Configuration.Jenkins | ||||
| 	if len(jenkins.Spec.Backup.ContainerName) == 0 || jenkins.Spec.Backup.Action.Exec == nil { | ||||
| 		bar.logger.V(log.VDebug).Info("Skipping restore backup, backup restore not configured") | ||||
|  | @ -176,11 +176,13 @@ func (bar *BackupAndRestore) Backup() error { | |||
| 	_, _, err := bar.Exec(podName, jenkins.Spec.Backup.ContainerName, command) | ||||
| 
 | ||||
| 	if err == nil { | ||||
| 		bar.logger.V(log.VDebug).Info(fmt.Sprintf("Backup completed '%d', updating status", backupNumber)) | ||||
| 		if jenkins.Status.RestoredBackup == 0 { | ||||
| 			jenkins.Status.RestoredBackup = backupNumber | ||||
| 		} | ||||
| 		jenkins.Status.LastBackup = backupNumber | ||||
| 		jenkins.Status.PendingBackup = backupNumber | ||||
| 		jenkins.Status.BackupDoneBeforePodDeletion = setBackupDoneBeforePodDeletion | ||||
| 		return bar.Client.Update(context.TODO(), jenkins) | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -190,17 +190,13 @@ func (r *ReconcileJenkinsBaseConfiguration) ensureJenkinsMasterPod(meta metav1.O | |||
| 		backupAndRestore := backuprestore.New(r.Configuration, r.logger) | ||||
| 		if backupAndRestore.IsBackupTriggerEnabled() { | ||||
| 			backupAndRestore.StopBackupTrigger() | ||||
| 			return reconcile.Result{Requeue: true}, nil | ||||
| 		} | ||||
| 		if r.Configuration.Jenkins.Spec.Backup.MakeBackupBeforePodDeletion { | ||||
| 			if r.Configuration.Jenkins.Status.LastBackup == r.Configuration.Jenkins.Status.PendingBackup && !r.Configuration.Jenkins.Status.BackupDoneBeforePodDeletion { | ||||
| 		if r.Configuration.Jenkins.Spec.Backup.MakeBackupBeforePodDeletion && !r.Configuration.Jenkins.Status.BackupDoneBeforePodDeletion { | ||||
| 			if r.Configuration.Jenkins.Status.LastBackup == r.Configuration.Jenkins.Status.PendingBackup { | ||||
| 				r.Configuration.Jenkins.Status.PendingBackup = r.Configuration.Jenkins.Status.PendingBackup + 1 | ||||
| 				r.Configuration.Jenkins.Status.BackupDoneBeforePodDeletion = true | ||||
| 				err = r.Client.Update(context.TODO(), r.Configuration.Jenkins) | ||||
| 				if err != nil { | ||||
| 					return reconcile.Result{}, err | ||||
| 				} | ||||
| 			} | ||||
| 			if err = backupAndRestore.Backup(); err != nil { | ||||
| 			if err = backupAndRestore.Backup(true); err != nil { | ||||
| 				return reconcile.Result{}, err | ||||
| 			} | ||||
| 		} | ||||
|  |  | |||
|  | @ -55,7 +55,7 @@ func (r *ReconcileUserConfiguration) Reconcile() (reconcile.Result, error) { | |||
| 		return reconcile.Result{}, err | ||||
| 	} | ||||
| 
 | ||||
| 	if err := backupAndRestore.Backup(); err != nil { | ||||
| 	if err := backupAndRestore.Backup(false); err != nil { | ||||
| 		return reconcile.Result{}, err | ||||
| 	} | ||||
| 	if err := backupAndRestore.EnsureBackupTrigger(); err != nil { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue