-
Notifications
You must be signed in to change notification settings - Fork 61
/
backup_types.go
169 lines (140 loc) · 5.07 KB
/
backup_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
// BackupSpec defines a single backup. It must contain all inforomation to connect to
// the backup repository when applied. If used with defaults or schedules the operator will
// ensure that the defaults are applied before creating the object on the API.
type BackupSpec struct {
RunnableSpec `json:",inline"`
// KeepJobs amount of jobs to keep for later analysis.
//
// Deprecated: Use FailedJobsHistoryLimit and SuccessfulJobsHistoryLimit respectively.
// +optional
KeepJobs *int `json:"keepJobs,omitempty"`
// FailedJobsHistoryLimit amount of failed jobs to keep for later analysis.
// KeepJobs is used property is not specified.
// +optional
FailedJobsHistoryLimit *int `json:"failedJobsHistoryLimit,omitempty"`
// SuccessfulJobsHistoryLimit amount of successful jobs to keep for later analysis.
// KeepJobs is used property is not specified.
// +optional
SuccessfulJobsHistoryLimit *int `json:"successfulJobsHistoryLimit,omitempty"`
// PromURL sets a prometheus push URL where the backup container send metrics to
// +optional
PromURL string `json:"promURL,omitempty"`
// StatsURL sets an arbitrary URL where the wrestic container posts metrics and
// information about the snapshots to. This is in addition to the prometheus
// pushgateway.
StatsURL string `json:"statsURL,omitempty"`
// Tags is a list of arbitrary tags that get added to the backup via Restic's tagging system
Tags []string `json:"tags,omitempty"`
}
type BackupTemplate struct {
Tags *[]string `json:"tags,omitempty"`
Backend Backend `json:"backend,omitempty"`
Env Env `json:"env,omitempty"`
}
type Env struct {
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Schedule Ref",type="string",JSONPath=`.metadata.ownerReferences[?(@.kind == "Schedule")].name`,description="Reference to Schedule"
// +kubebuilder:printcolumn:name="Completion",type="string",JSONPath=`.status.conditions[?(@.type == "Completed")].reason`,description="Status of Completion"
// +kubebuilder:printcolumn:name="PreBackup",type="string",JSONPath=`.status.conditions[?(@.type == "PreBackupPodReady")].reason`,description="Status of PreBackupPods"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// Backup is the Schema for the backups API
type Backup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec BackupSpec `json:"spec,omitempty"`
Status Status `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// BackupList contains a list of Backup
type BackupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Backup `json:"items"`
}
func init() {
SchemeBuilder.Register(&Backup{}, &BackupList{})
}
func (b *Backup) GetRuntimeObject() runtime.Object {
return b
}
func (b *Backup) GetMetaObject() metav1.Object {
return b
}
func (*Backup) GetType() JobType {
return BackupType
}
// GetJobName returns the name of the underlying batch/v1 job.
func (b *Backup) GetJobName() string {
return b.GetType().String() + "-" + b.Name
}
// GetStatus retrieves the Status property
func (b *Backup) GetStatus() Status {
return b.Status
}
// SetStatus sets the Status property
func (b *Backup) SetStatus(status Status) {
b.Status = status
}
// GetResources returns the resource requirements
func (b *Backup) GetResources() corev1.ResourceRequirements {
return b.Spec.Resources
}
// GetFailedJobsHistoryLimit returns failed jobs history limit.
// Returns KeepJobs if unspecified.
func (b *Backup) GetFailedJobsHistoryLimit() *int {
if b.Spec.FailedJobsHistoryLimit != nil {
return b.Spec.FailedJobsHistoryLimit
}
return b.Spec.KeepJobs
}
// GetSuccessfulJobsHistoryLimit returns successful jobs history limit.
// Returns KeepJobs if unspecified.
func (b *Backup) GetSuccessfulJobsHistoryLimit() *int {
if b.Spec.SuccessfulJobsHistoryLimit != nil {
return b.Spec.SuccessfulJobsHistoryLimit
}
return b.Spec.KeepJobs
}
// GetJobObjects returns a sortable list of jobs
func (b *BackupList) GetJobObjects() JobObjectList {
items := make(JobObjectList, len(b.Items))
for i := range b.Items {
items[i] = &b.Items[i]
}
return items
}
// GetDeepCopy returns a deep copy
func (in *BackupSchedule) GetDeepCopy() ScheduleSpecInterface {
return in.DeepCopy()
}
// GetRunnableSpec returns a pointer to RunnableSpec
func (in *BackupSchedule) GetRunnableSpec() *RunnableSpec {
return &in.RunnableSpec
}
// GetSchedule returns the schedule definition
func (in *BackupSchedule) GetSchedule() ScheduleDefinition {
return in.Schedule
}
// GetObjectCreator returns the ObjectCreator instance
func (in *BackupSchedule) GetObjectCreator() ObjectCreator {
return in
}
func (b BackupSpec) CreateObject(name, namespace string) runtime.Object {
return &Backup{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: b,
}
}