/
backupschedule_types.go
106 lines (87 loc) · 3.75 KB
/
backupschedule_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2024 Upbound Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1alpha1
import (
"reflect"
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// BackupScheduleLabelKey is the label key used to identify Backups created by
// a BackupSchedule.
const BackupScheduleLabelKey = "spaces.upbound.io/backupschedule"
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Schedule",type="string",JSONPath=".spec.schedule"
// +kubebuilder:printcolumn:name="LastBackup",type="date",JSONPath=".status.lastBackup"
// +kubebuilder:printcolumn:name="ControlPlane",type="string",JSONPath=".spec.controlPlane"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Suspended",type="boolean",JSONPath=".spec.suspend"
// +kubebuilder:resource:scope=Namespaced,categories=spaces
// BackupSchedule represents a single ControlPlane schedule for Backups.
type BackupSchedule struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec BackupScheduleSpec `json:"spec"`
Status BackupScheduleStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// BackupScheduleList contains a list of BackupSchedules.
type BackupScheduleList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BackupSchedule `json:"items"`
}
// BackupScheduleDefinition defines the schedule for a Backup.
type BackupScheduleDefinition struct {
// Suspend specifies whether the schedule is suspended. If true, no
// Backups will be created, but running backups will be allowed to
// complete.
// +optional
Suspend bool `json:"suspend,omitempty"`
// Schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
// +kubebuilder:validation:MinLength=1
Schedule string `json:"schedule"`
BackupDefinition `json:",inline"`
}
// BackupScheduleSpec defines a backup schedule over a set of ControlPlanes.
type BackupScheduleSpec struct {
// ControlPlane is the name of the ControlPlane to which the schedule
// applies.
// Requires "get" permission on the referenced ControlPlane.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="target can not be changed after creation"
ControlPlane string `json:"controlPlane"`
// UseOwnerReferencesBackup specifies whether an ownership chain should be
// established between this resource and the Backup it creates.
// If set to true, the Backup will be garbage collected when this resource
// is deleted.
// +optional
UseOwnerReferencesInBackup bool `json:"useOwnerReferencesInBackup,omitempty"`
BackupScheduleDefinition `json:",inline"`
}
// BackupScheduleStatus represents the observed state of a BackupSchedule.
type BackupScheduleStatus struct {
xpv1.ResourceStatus `json:",inline"`
// LastBackup is the last time a Backup was run for this
// Schedule schedule
// +optional
LastBackup *metav1.Time `json:"lastBackup,omitempty"`
}
var (
// BackupScheduleKind is the kind of BackupSchedule.
BackupScheduleKind = reflect.TypeOf(BackupSchedule{}).Name()
)
func init() {
SchemeBuilder.Register(&BackupSchedule{}, &BackupScheduleList{})
}