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

Use vtbackup in scheduled backups #658

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions deploy/crds/planetscale.com_vitessbackupschedules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spec:
cluster:
type: string
concurrencyPolicy:
default: Forbid
enum:
- Allow
- Forbid
Expand Down Expand Up @@ -113,8 +114,6 @@ spec:
example: commerce
type: string
name:
enum:
- BackupShard
type: string
shard:
example: '-'
Expand Down Expand Up @@ -164,6 +163,11 @@ spec:
lastScheduledTime:
format: date-time
type: string
lastScheduledTimes:
additionalProperties:
format: date-time
type: string
type: object
type: object
type: object
served: true
Expand Down
3 changes: 1 addition & 2 deletions deploy/crds/planetscale.com_vitessclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ spec:
type: string
type: object
concurrencyPolicy:
default: Forbid
enum:
- Allow
- Forbid
Expand Down Expand Up @@ -239,8 +240,6 @@ spec:
example: commerce
type: string
name:
enum:
- BackupShard
type: string
shard:
example: '-'
Expand Down
49 changes: 27 additions & 22 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -647,16 +647,6 @@ SecretSource
</tr>
</tbody>
</table>
<h3 id="planetscale.com/v2.BackupStrategyName">BackupStrategyName
(<code>string</code> alias)</p></h3>
<p>
(<em>Appears on:</em>
<a href="#planetscale.com/v2.VitessBackupScheduleStrategy">VitessBackupScheduleStrategy</a>)
</p>
<p>
<p>BackupStrategyName describes the vtctldclient command that will be used to take a backup.
When scheduling a backup, you must specify at least one strategy.</p>
</p>
<h3 id="planetscale.com/v2.CephBackupLocation">CephBackupLocation
</h3>
<p>
Expand Down Expand Up @@ -2600,7 +2590,8 @@ The PullPolicy used will be the same as the one used to pull the vtctld image.</
</td>
<td>
<em>(Optional)</em>
<p>A list of pointers to currently running jobs.</p>
<p>A list of pointers to currently running jobs.
This field is deprecated and no longer used in &gt;= v2.15. It will be removed in a future release.</p>
</td>
</tr>
<tr>
Expand All @@ -2614,7 +2605,25 @@ Kubernetes meta/v1.Time
</td>
<td>
<em>(Optional)</em>
<p>Information when was the last time the job was successfully scheduled.</p>
<p>Information when was the last time the job was successfully scheduled.
This field is deprecated and no longer used in &gt;= v2.15. It will be removed in a future release.
Please use lastScheduledTimes instead which maps the last schedule time to each VitessBackupScheduleStrategy
in the VitessBackupSchedule.</p>
</td>
</tr>
<tr>
<td>
<code>lastScheduledTimes</code><br>
<em>
<a href="https://v1-18.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#*k8s.io/apimachinery/pkg/apis/meta/v1.time--">
map[string]*k8s.io/apimachinery/pkg/apis/meta/v1.Time
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>LastScheduledTimes lists for every VitessBackupScheduleStrategy what is the last schedule we executed.
It does not list when the last execution started, but to which scheduled time it corresponds.</p>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -2642,9 +2651,7 @@ command line that will be executed in the Job&rsquo;s pod.</p>
<td>
<code>name</code><br>
<em>
<a href="#planetscale.com/v2.BackupStrategyName">
BackupStrategyName
</a>
string
</em>
</td>
<td>
Expand Down Expand Up @@ -2741,11 +2748,9 @@ string
<td>
<p>Strategy defines how we are going to take a backup.
If you want to take several backups within the same schedule you can add more items
to the Strategy list. Each VitessBackupScheduleStrategy will be executed by the same
kubernetes job. This is useful if for instance you have one schedule, and you want to
take a backup of all shards in a keyspace and don&rsquo;t want to re-create a second schedule.
All the VitessBackupScheduleStrategy are concatenated into a single shell command that
is executed when the Job&rsquo;s container starts.</p>
to the Strategy list. Each VitessBackupScheduleStrategy will be executed within different
K8S Jobs. This is useful if you want to have a single schedule backing up multiple shards
at the same time.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -2828,8 +2833,8 @@ ConcurrencyPolicy
<em>(Optional)</em>
<p>ConcurrencyPolicy specifies ho to treat concurrent executions of a Job.
Valid values are:
- &ldquo;Allow&rdquo; (default): allows CronJobs to run concurrently;
- &ldquo;Forbid&rdquo;: forbids concurrent runs, skipping next run if previous run hasn&rsquo;t finished yet;
- &ldquo;Allow&rdquo;: allows CronJobs to run concurrently;
- &ldquo;Forbid&rdquo; (default): forbids concurrent runs, skipping next run if previous run hasn&rsquo;t finished yet;
- &ldquo;Replace&rdquo;: cancels currently running job and replaces it with a new one.</p>
</td>
</tr>
Expand Down
49 changes: 27 additions & 22 deletions docs/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -649,16 +649,6 @@ <h3 id="planetscale.com/v2.AzblobBackupLocation">AzblobBackupLocation
</tr>
</tbody>
</table>
<h3 id="planetscale.com/v2.BackupStrategyName">BackupStrategyName
(<code>string</code> alias)</p></h3>
<p>
(<em>Appears on:</em>
<a href="#planetscale.com/v2.VitessBackupScheduleStrategy">VitessBackupScheduleStrategy</a>)
</p>
<p>
<p>BackupStrategyName describes the vtctldclient command that will be used to take a backup.
When scheduling a backup, you must specify at least one strategy.</p>
</p>
<h3 id="planetscale.com/v2.CephBackupLocation">CephBackupLocation
</h3>
<p>
Expand Down Expand Up @@ -2602,7 +2592,8 @@ <h3 id="planetscale.com/v2.VitessBackupScheduleStatus">VitessBackupScheduleStatu
</td>
<td>
<em>(Optional)</em>
<p>A list of pointers to currently running jobs.</p>
<p>A list of pointers to currently running jobs.
This field is deprecated and no longer used in &gt;= v2.15. It will be removed in a future release.</p>
</td>
</tr>
<tr>
Expand All @@ -2616,7 +2607,25 @@ <h3 id="planetscale.com/v2.VitessBackupScheduleStatus">VitessBackupScheduleStatu
</td>
<td>
<em>(Optional)</em>
<p>Information when was the last time the job was successfully scheduled.</p>
<p>Information when was the last time the job was successfully scheduled.
This field is deprecated and no longer used in &gt;= v2.15. It will be removed in a future release.
Please use lastScheduledTimes instead which maps the last schedule time to each VitessBackupScheduleStrategy
in the VitessBackupSchedule.</p>
</td>
</tr>
<tr>
<td>
<code>lastScheduledTimes</code><br>
<em>
<a href="https://v1-18.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#*k8s.io/apimachinery/pkg/apis/meta/v1.time--">
map[string]*k8s.io/apimachinery/pkg/apis/meta/v1.Time
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>LastScheduledTimes lists for every VitessBackupScheduleStrategy what is the last schedule we executed.
It does not list when the last execution started, but to which scheduled time it corresponds.</p>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -2644,9 +2653,7 @@ <h3 id="planetscale.com/v2.VitessBackupScheduleStrategy">VitessBackupScheduleStr
<td>
<code>name</code><br>
<em>
<a href="#planetscale.com/v2.BackupStrategyName">
BackupStrategyName
</a>
string
</em>
</td>
<td>
Expand Down Expand Up @@ -2743,11 +2750,9 @@ <h3 id="planetscale.com/v2.VitessBackupScheduleTemplate">VitessBackupScheduleTem
<td>
<p>Strategy defines how we are going to take a backup.
If you want to take several backups within the same schedule you can add more items
to the Strategy list. Each VitessBackupScheduleStrategy will be executed by the same
kubernetes job. This is useful if for instance you have one schedule, and you want to
take a backup of all shards in a keyspace and don&rsquo;t want to re-create a second schedule.
All the VitessBackupScheduleStrategy are concatenated into a single shell command that
is executed when the Job&rsquo;s container starts.</p>
to the Strategy list. Each VitessBackupScheduleStrategy will be executed within different
K8S Jobs. This is useful if you want to have a single schedule backing up multiple shards
at the same time.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -2830,8 +2835,8 @@ <h3 id="planetscale.com/v2.VitessBackupScheduleTemplate">VitessBackupScheduleTem
<em>(Optional)</em>
<p>ConcurrencyPolicy specifies ho to treat concurrent executions of a Job.
Valid values are:
- &ldquo;Allow&rdquo; (default): allows CronJobs to run concurrently;
- &ldquo;Forbid&rdquo;: forbids concurrent runs, skipping next run if previous run hasn&rsquo;t finished yet;
- &ldquo;Allow&rdquo;: allows CronJobs to run concurrently;
- &ldquo;Forbid&rdquo; (default): forbids concurrent runs, skipping next run if previous run hasn&rsquo;t finished yet;
- &ldquo;Replace&rdquo;: cancels currently running job and replaces it with a new one.</p>
</td>
</tr>
Expand Down
47 changes: 29 additions & 18 deletions pkg/apis/planetscale/v2/vitessbackupschedule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ const (
ForbidConcurrent ConcurrencyPolicy = "Forbid"
)

// BackupStrategyName describes the vtctldclient command that will be used to take a backup.
// When scheduling a backup, you must specify at least one strategy.
// +kubebuilder:validation:Enum=BackupShard
type BackupStrategyName string

const (
// BackupShard will use the "vtctldclient BackupShard" command to take a backup
BackupShard BackupStrategyName = "BackupShard"
)

// VitessBackupSchedule is the Schema for the VitessBackupSchedule API.
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
Expand Down Expand Up @@ -98,12 +88,12 @@ type VitessBackupScheduleTemplate struct {

// Strategy defines how we are going to take a backup.
// If you want to take several backups within the same schedule you can add more items
// to the Strategy list. Each VitessBackupScheduleStrategy will be executed by the same
// kubernetes job. This is useful if for instance you have one schedule, and you want to
// take a backup of all shards in a keyspace and don't want to re-create a second schedule.
// All the VitessBackupScheduleStrategy are concatenated into a single shell command that
// is executed when the Job's container starts.
// to the Strategy list. Each VitessBackupScheduleStrategy will be executed within different
// K8S Jobs. This is useful if you want to have a single schedule backing up multiple shards
// at the same time.
// +kubebuilder:validation:MinItems=1
// +patchMergeKey=name
// +patchStrategy=merge
Strategy []VitessBackupScheduleStrategy `json:"strategies"`

// Resources specify the compute resources to allocate for every Jobs's pod.
Expand Down Expand Up @@ -136,11 +126,12 @@ type VitessBackupScheduleTemplate struct {

// ConcurrencyPolicy specifies ho to treat concurrent executions of a Job.
// Valid values are:
// - "Allow" (default): allows CronJobs to run concurrently;
// - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet;
// - "Allow": allows CronJobs to run concurrently;
// - "Forbid" (default): forbids concurrent runs, skipping next run if previous run hasn't finished yet;
// - "Replace": cancels currently running job and replaces it with a new one.
// +optional
// +kubebuilder:example="Forbid"
// +kubebuilder:default="Forbid"
ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy,omitempty"`

// AllowedMissedRuns defines how many missed run of the schedule will be allowed before giving up on finding the last job.
Expand Down Expand Up @@ -180,7 +171,7 @@ type VitessBackupScheduleTemplate struct {
// command line that will be executed in the Job's pod.
type VitessBackupScheduleStrategy struct {
// Name of the backup strategy.
Name BackupStrategyName `json:"name"`
Name string `json:"name"`

// Keyspace defines the keyspace on which we want to take the backup.
// +kubebuilder:example="commerce"
Expand All @@ -198,12 +189,32 @@ type VitessBackupScheduleStrategy struct {
// VitessBackupScheduleStatus defines the observed state of VitessBackupSchedule
type VitessBackupScheduleStatus struct {
// A list of pointers to currently running jobs.
// This field is deprecated and no longer used in >= v2.15. It will be removed in a future release.
// +optional
Active []corev1.ObjectReference `json:"active,omitempty"`

// Information when was the last time the job was successfully scheduled.
// This field is deprecated and no longer used in >= v2.15. It will be removed in a future release.
// Please use lastScheduledTimes instead which maps the last schedule time to each VitessBackupScheduleStrategy
// in the VitessBackupSchedule.
// +optional
LastScheduledTime *metav1.Time `json:"lastScheduledTime,omitempty"`

// LastScheduledTimes lists for every VitessBackupScheduleStrategy what is the last schedule we executed.
// It does not list when the last execution started, but to which scheduled time it corresponds.
// +optional
LastScheduledTimes map[string]*metav1.Time `json:"lastScheduledTimes,omitempty"`
}

// NewVitessBackupScheduleStatus creates a new status with default values.
func NewVitessBackupScheduleStatus(status VitessBackupScheduleStatus) VitessBackupScheduleStatus {
newStatus := VitessBackupScheduleStatus{
LastScheduledTimes: status.LastScheduledTimes,
}
if status.LastScheduledTimes == nil {
newStatus.LastScheduledTimes = make(map[string]*metav1.Time)
}
return newStatus
}

func init() {
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/planetscale/v2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading