Skip to content

Commit

Permalink
feat: update backup expired time according completed time (#5514)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengluodb authored Oct 20, 2023
1 parent 184cbf1 commit 9bd65ca
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions controllers/dataprotection/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,18 @@ func (r *BackupReconciler) handleRunningPhase(
duration := request.Status.CompletionTimestamp.Sub(request.Status.StartTimestamp.Time).Round(time.Second)
request.Status.Duration = &metav1.Duration{Duration: duration}
}
if request.Spec.RetentionPeriod != "" {
// set expiration time
duration, err := request.Spec.RetentionPeriod.ToDuration()
if err != nil {
return r.updateStatusIfFailed(reqCtx, backup, request.Backup, fmt.Errorf("failed to parse retention period %s, %v", request.Spec.RetentionPeriod, err))
}
if duration.Seconds() > 0 {
request.Status.Expiration = &metav1.Time{
Time: request.Status.CompletionTimestamp.Add(duration),
}
}
}
r.Recorder.Event(backup, corev1.EventTypeNormal, "CreatedBackup", "Completed backup")
if err = r.Client.Status().Patch(reqCtx.Ctx, request.Backup, client.MergeFrom(backup)); err != nil {
return intctrlutil.CheckedRequeueWithError(err, reqCtx.Log, "")
Expand Down Expand Up @@ -538,6 +550,7 @@ func (r *BackupReconciler) handleCompletedPhase(
if err := r.deleteExternalResources(reqCtx, backup); err != nil {
return intctrlutil.CheckedRequeueWithError(err, reqCtx.Log, "")
}

return intctrlutil.Reconciled()
}

Expand Down

0 comments on commit 9bd65ca

Please sign in to comment.