Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backup): Duplicated backups & restores #1021

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading