Skip to content

Commit

Permalink
Name backups after the current moment, not the scheduled moment.
Browse files Browse the repository at this point in the history
Naming them after scheduled moment makes for nicer timestamps, and prevents
double creation of backup jobs if multiple controllers (or multiple workers)
are active. This is why I originally chose this approach. However, it also
causes issues when the job cannot be created because it already exists at the
scheduled time but something is wrong with it. Also, in the case of many missed
schedule moments, the name refers to the first missed one instead of the newly
made moment.

So, to make the controller more robust, I'm switching to naming them after the
current moment, not the scheduled moment.
  • Loading branch information
sgielen committed Aug 3, 2024
1 parent 7a7b741 commit 9400767
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/controller/automatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,16 @@ func (r *AutomaticPVCBackupCreator) Reconcile(ctx context.Context, req ctrl.Requ
)

// If the next backup is in the future, schedule our next reconcile then
if nextBackup.After(time.Now()) {
now := time.Now()
if nextBackup.After(now) {
return ctrl.Result{
Requeue: true,
RequeueAfter: time.Until(nextBackup),
}, nil
}

// Like jobs from cronjobs, give backup names a deterministic name to avoid duplicates
backupName := fmt.Sprintf("%s-%d", pvc.Name, nextBackup.Unix())
// Give backup names a unique name containing their scheduled unix timestamps.
backupName := fmt.Sprintf("%s-%d", pvc.Name, now.Unix())

newBackup := &v1alpha1.PVCBackup{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 9400767

Please sign in to comment.