Skip to content

Commit

Permalink
Merge pull request #2 from logicnow/NS-3176
Browse files Browse the repository at this point in the history
fix (NS-3176): Fix duplicated backups and restores
  • Loading branch information
DionJones615 authored Jun 21, 2024
2 parents e400324 + adf438f commit b210623
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pkg/configuration/backuprestore/backuprestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,7 @@ func (bar *BackupAndRestore) Restore(jenkinsClient jenkinsclient.Jenkins) error
if err != nil {
return err
}
//TODO fix me because we're doing two saves unatomically
jenkins.Spec.Restore.RecoveryOnce = 0
err = bar.Client.Update(context.TODO(), jenkins)
if err != nil {
return err
}

key := types.NamespacedName{
Namespace: jenkins.Namespace,
Name: jenkins.Name,
Expand All @@ -194,6 +189,12 @@ func (bar *BackupAndRestore) Restore(jenkinsClient jenkinsclient.Jenkins) error
if err != nil {
return err
}

jenkins.Spec.Restore.RecoveryOnce = 0
err = bar.Client.Update(context.TODO(), jenkins)
if err != nil {
return err
}
bar.Configuration.Jenkins = jenkins

jenkins.Status.RestoredBackup = backupNumber
Expand Down Expand Up @@ -223,6 +224,15 @@ func (bar *BackupAndRestore) Backup(setBackupDoneBeforePodDeletion bool) error {
_, _, err := bar.Exec(podName, jenkins.Spec.Backup.ContainerName, command)

if err == nil {
key := types.NamespacedName{
Namespace: jenkins.Namespace,
Name: jenkins.Name,
}
err = bar.Client.Get(context.TODO(), key, jenkins)
if err != nil {
return err
}

bar.logger.V(log.VDebug).Info(fmt.Sprintf("Backup completed '%d', updating status", backupNumber))
if jenkins.Status.RestoredBackup == 0 {
jenkins.Status.RestoredBackup = backupNumber
Expand Down

0 comments on commit b210623

Please sign in to comment.