From b9be014fbeab64ceced011019f4f8588965c2f8a Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Tue, 28 Nov 2023 10:18:49 -0500 Subject: [PATCH] Add `velero install` Signed-off-by: Tiger Kaovilai --- ...schedule-skip-immediately-config_design.md | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/design/schedule-skip-immediately-config_design.md b/design/schedule-skip-immediately-config_design.md index 70f559a8ec..85b09a6802 100644 --- a/design/schedule-skip-immediately-config_design.md +++ b/design/schedule-skip-immediately-config_design.md @@ -21,7 +21,7 @@ With this design, user can skip the first immediately due backup when schedule i - Changing the default behavior ## High-Level Design -Add a new field with to the schedule spec and as a new cli flags for install, server, schedule commands; allowing user to skip immediately due backup when unpausing. +Add a new field with to the schedule spec and as a new cli flags for install, server, schedule commands; allowing user to skip immediately due backup when unpausing or schedule creation. If CLI flag is specified during schedule unpause, velero will update the schedule spec accordingly and override prior spec for `skipImmediately``. @@ -29,14 +29,16 @@ If CLI flag is specified during schedule unpause, velero will update the schedul ### CLI Changes `velero schedule unpause` will now take an optional bool flag `--skip-immediately` to allow user to override the behavior configured previously in the schedule spec. -`velero schedule unpause schedule-1 --skip-immediately=false` will unpause the schedule but not skip the backup if due immediately from `schedule.status.lastBackup` timestamp. Backup will be run at the next cron schedule. +`velero schedule unpause schedule-1 --skip-immediately=false` will unpause the schedule but not skip the backup if due immediately from `Schedule.Status.LastBackup` timestamp. Backup will be run at the next cron schedule. -`velero schedule unpause schedule-1 --skip-immediately=true` will unpause the schedule and skip the backup if due immediately from `schedule.status.lastBackup` timestamp. Backup will also be run at the next cron schedule. +`velero schedule unpause schedule-1 --skip-immediately=true` will unpause the schedule and skip the backup if due immediately from `Schedule.Status.LastBackup` timestamp. Backup will also be run at the next cron schedule. `velero schedule unpause schedule-1` will check `.spec.SkipImmediately` in the schedule to determine behavior. This field will default to false to maintain prior behavior. `velero server` will add a new flag `--skip-immediately` to configure default value to patch new schedules created without the field. This flag will default to false to maintain prior behavior if not set. +`velero install` will add a new flag `--skip-immediately` to configure default value to patch new schedules created without the field. This flag will default to false to maintain prior behavior if not set. + ### API Changes `pkg/apis/velero/v1/schedule_types.go` ```diff @@ -60,16 +62,16 @@ type ScheduleSpec struct { // +optional Paused bool `json:"paused,omitempty"` -+ // SkipImmediately specifies whether to skip backup if schedule is due immediately from `schedule.status.lastBackup` timestamp when schedule is unpaused or if schedule is new. ++ // SkipImmediately specifies whether to skip backup if schedule is due immediately from `Schedule.Status.LastBackup` timestamp when schedule is unpaused or if schedule is new. + // If true, backup will be skipped immediately when schedule is unpaused if it is due based on .Status.LastBackupTimestamp or schedule is new, and will run at next schedule time. + // If false, backup will not be skipped immediately when schedule is unpaused, but will run at next schedule time. + // If empty, will follow server configuration (default: false). + // +optional -+ SkipImmediately *bool `json:"skipImmediately,omitempty"` ++ SkipImmediately bool `json:"skipImmediately,omitempty"` } ``` -`LastUnpaused` will be added to `ScheduleStatus` struct to track the last time a schedule was unpaused to support configurable unpause behavior. +`LastSkipped` will be added to `ScheduleStatus` struct to track the last time a schedule was skipped. ```diff // ScheduleStatus captures the current state of a Velero schedule type ScheduleStatus struct { @@ -83,10 +85,10 @@ type ScheduleStatus struct { // +nullable LastBackup *metav1.Time `json:"lastBackup,omitempty"` -+ // LastUnpaused is the last time a Schedule was unpaused ++ // LastSkipped is the last time a Schedule was skipped + // +optional + // +nullable -+ LastUnpaused *metav1.Time `json:"lastUnpaused,omitempty"` ++ LastSkipped *metav1.Time `json:"lastSkipped,omitempty"` // ValidationErrors is a slice of all validation errors (if // applicable) @@ -95,11 +97,31 @@ type ScheduleStatus struct { } ``` -`LastUnpaused` will be set to the current time when a schedule is unpaused. When a schedule is paused, `LastUnpaused` will be set to nil. +When `schedule.spec.SkipImmediately` is `true`, `LastSkipped` will be set to the current time, and `schedule.spec.SkipImmediately` set to nil so it can be used again. + +The `getNextRunTime()` function below is updated so `LastSkipped` which is after `LastBackup` will be used to determine next run time. + +```go +func getNextRunTime(schedule *velerov1.Schedule, cronSchedule cron.Schedule, asOf time.Time) (bool, time.Time) { + var lastBackupTime time.Time + if schedule.Status.LastBackup != nil { + lastBackupTime = schedule.Status.LastBackup.Time + } else { + lastBackupTime = schedule.CreationTimestamp.Time + } + if schedule.Status.LastSkipped != nil && schedule.Status.LastSkipped.After(lastBackupTime) { + lastBackupTime = schedule.Status.LastSkipped.Time + } + + nextRunTime := cronSchedule.Next(lastBackupTime) + + return asOf.After(nextRunTime), nextRunTime +} +``` -When schedule is unpaused, and `schedule.status.lastBackup` is not nil, if `.spec.SkipImmediately` is true, a backup will not be created if the schedule is due immediately from lastBackup timestamp. Backup will be run at the next cron schedule. +When schedule is unpaused, and `Schedule.Status.LastBackup` is not nil, if `.spec.SkipImmediately` is true, a backup will not be created if the schedule is due immediately from lastBackup timestamp. Backup will be run at the next cron schedule. -When schedule is unpaused with `schedule.status.lastBackup` set to nil or schedule is newly created, normally a backup will be created immediately. If `.spec.SkipImmediately` is true, a backup will not be created. Backup will be run at the next cron schedule. +When schedule is unpaused with `Schedule.Status.LastBackup` set to nil or schedule is newly created, normally a backup will be created immediately. If `Schedule.Status.LastSkipped` is recent, a backup will not be created. Backup will be run at the next cron schedule after `lastSkipped`. When schedule is created, if `.spec.SkipImmediately` is true, a backup will not be created. Backup will run at the next cron schedule.