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

Don't create a backup immediately after creating a schedule #4281

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelogs/unreleased/4281-ywk253100
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't create a backup immediately after creating a schedule
4 changes: 2 additions & 2 deletions pkg/controller/schedule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@ func (c *scheduleController) submitBackupIfDue(item *api.Schedule, cronSchedule
}

func getNextRunTime(schedule *api.Schedule, cronSchedule cron.Schedule, asOf time.Time) (bool, time.Time) {
// get the latest run time (if the schedule hasn't run yet, this will be the zero value which will trigger
// an immediate backup)
var lastBackupTime time.Time
if schedule.Status.LastBackup != nil {
lastBackupTime = schedule.Status.LastBackup.Time
} else {
lastBackupTime = schedule.CreationTimestamp.Time
}

nextRunTime := cronSchedule.Next(lastBackupTime)
Expand Down
9 changes: 6 additions & 3 deletions pkg/controller/schedule_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func TestGetNextRunTime(t *testing.T) {
{
name: "first run",
schedule: defaultSchedule(),
expectedDue: true,
expectedDue: false,
expectedNextRunTimeOffset: "5m",
},
{
Expand Down Expand Up @@ -319,18 +319,21 @@ func TestGetNextRunTime(t *testing.T) {
require.NoError(t, err, "unable to parse test.lastRanOffset: %v", err)

test.schedule.Status.LastBackup = &metav1.Time{Time: testClock.Now().Add(-offsetDuration)}
test.schedule.CreationTimestamp = *test.schedule.Status.LastBackup
} else {
test.schedule.CreationTimestamp = metav1.Time{Time: testClock.Now()}
}

nextRunTimeOffset, err := time.ParseDuration(test.expectedNextRunTimeOffset)
if err != nil {
panic(err)
}

// calculate expected next run time (if the schedule hasn't run yet, this
// will be the zero value which will trigger an immediate backup)
var baseTime time.Time
if test.lastRanOffset != "" {
baseTime = test.schedule.Status.LastBackup.Time
} else {
baseTime = test.schedule.CreationTimestamp.Time
}
expectedNextRunTime := baseTime.Add(nextRunTimeOffset)

Expand Down