-
Notifications
You must be signed in to change notification settings - Fork 61
/
restore_types.go
160 lines (134 loc) · 4.7 KB
/
restore_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
package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
// RestoreSpec can either contain an S3 restore point or a local one. For the local
// one you need to define an existing PVC.
type RestoreSpec struct {
RunnableSpec `json:",inline"`
RestoreMethod *RestoreMethod `json:"restoreMethod,omitempty"`
RestoreFilter string `json:"restoreFilter,omitempty"`
Snapshot string `json:"snapshot,omitempty"`
// 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"`
// Tags is a list of arbitrary tags that get added to the backup via Restic's tagging system
Tags []string `json:"tags,omitempty"`
}
func (r RestoreSpec) CreateObject(name, namespace string) runtime.Object {
return &Restore{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: r,
}
}
// RestoreMethod contains how and where the restore should happen
// all the settings are mutual exclusive.
type RestoreMethod struct {
S3 *S3Spec `json:"s3,omitempty"`
Folder *FolderRestore `json:"folder,omitempty"`
}
type FolderRestore struct {
*corev1.PersistentVolumeClaimVolumeSource `json:",inline"`
}
// +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="Age",type="date",JSONPath=".metadata.creationTimestamp"
// Restore is the Schema for the restores API
type Restore struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec RestoreSpec `json:"spec,omitempty"`
Status Status `json:"status,omitempty"`
}
func (r *Restore) GetRuntimeObject() runtime.Object {
return r
}
func (r *Restore) GetMetaObject() metav1.Object {
return r
}
// GetJobName returns the name of the underlying batch/v1 job.
func (r *Restore) GetJobName() string {
return r.GetType().String() + "-" + r.Name
}
func (r *Restore) GetType() JobType {
return RestoreType
}
// GetStatus retrieves the Status property
func (r *Restore) GetStatus() Status {
return r.Status
}
// SetStatus sets the Status property
func (r *Restore) SetStatus(status Status) {
r.Status = status
}
// GetResources returns the resource requirements
func (r *Restore) GetResources() corev1.ResourceRequirements {
return r.Spec.Resources
}
// GetFailedJobsHistoryLimit returns failed jobs history limit.
// Returns KeepJobs if unspecified.
func (r *Restore) GetFailedJobsHistoryLimit() *int {
if r.Spec.FailedJobsHistoryLimit != nil {
return r.Spec.FailedJobsHistoryLimit
}
return r.Spec.KeepJobs
}
// GetSuccessfulJobsHistoryLimit returns successful jobs history limit.
// Returns KeepJobs if unspecified.
func (r *Restore) GetSuccessfulJobsHistoryLimit() *int {
if r.Spec.SuccessfulJobsHistoryLimit != nil {
return r.Spec.SuccessfulJobsHistoryLimit
}
return r.Spec.KeepJobs
}
// GetJobObjects returns a sortable list of jobs
func (r *RestoreList) GetJobObjects() JobObjectList {
items := make(JobObjectList, len(r.Items))
for i := range r.Items {
items[i] = &r.Items[i]
}
return items
}
// GetDeepCopy returns a deep copy
func (in *RestoreSchedule) GetDeepCopy() ScheduleSpecInterface {
return in.DeepCopy()
}
// GetRunnableSpec returns a pointer to RunnableSpec
func (in *RestoreSchedule) GetRunnableSpec() *RunnableSpec {
return &in.RunnableSpec
}
// GetSchedule returns the schedule definition
func (in *RestoreSchedule) GetSchedule() ScheduleDefinition {
return in.Schedule
}
// GetObjectCreator returns the ObjectCreator instance
func (in *RestoreSchedule) GetObjectCreator() ObjectCreator {
return in
}
// +kubebuilder:object:root=true
// RestoreList contains a list of Restore
type RestoreList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Restore `json:"items"`
}
func init() {
SchemeBuilder.Register(&Restore{}, &RestoreList{})
}