/
restore_session_types.go
228 lines (193 loc) · 9.8 KB
/
restore_session_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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
Copyright AppsCode Inc. and Contributors
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 v1beta1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kmapi "kmodules.xyz/client-go/api/v1"
ofst "kmodules.xyz/offshoot-api/api/v1"
prober "kmodules.xyz/prober/api/v1"
)
const (
ResourceKindRestoreSession = "RestoreSession"
ResourcePluralRestoreSession = "restoresessions"
ResourceSingularRestoreSession = "restoresession"
)
// +genclient
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=restoresessions,singular=restoresession,shortName=restore,categories={stash,appscode,all}
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Repository",type="string",JSONPath=".spec.repository.name"
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Duration",type="string",JSONPath=".status.sessionDuration"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type RestoreSession struct {
metav1.TypeMeta `json:",inline,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec RestoreSessionSpec `json:"spec,omitempty"`
Status RestoreSessionStatus `json:"status,omitempty"`
}
type RestoreSessionSpec struct {
RestoreTargetSpec `json:",inline,omitempty"`
// Driver indicates the name of the agent to use to restore the target.
// Supported values are "Restic", "VolumeSnapshotter".
// Default value is "Restic".
// +optional
// +kubebuilder:default=Restic
Driver Snapshotter `json:"driver,omitempty"`
// Repository refer to the Repository crd that hold backend information
// +optional
Repository kmapi.ObjectReference `json:"repository,omitempty"`
// Rules specifies different restore options for different hosts
// +optional
// Deprecated. Use rules section inside `target`.
Rules []Rule `json:"rules,omitempty"`
}
type RestoreTargetSpec struct {
// Task specify the Task crd that specifies the steps for recovery process
// +optional
Task TaskRef `json:"task,omitempty"`
// Target indicates the target where the recovered data will be stored
// +optional
Target *RestoreTarget `json:"target,omitempty"`
// RuntimeSettings allow to specify Resources, NodeSelector, Affinity, Toleration, ReadinessProbe etc.
// +optional
RuntimeSettings ofst.RuntimeSettings `json:"runtimeSettings,omitempty"`
// Temp directory configuration for functions/sidecar
// An `EmptyDir` will always be mounted at /tmp with this settings
// +optional
TempDir EmptyDirSettings `json:"tempDir,omitempty"`
// InterimVolumeTemplate specifies a template for a volume to hold targeted data temporarily
// before uploading to backend or inserting into target. It is only usable for job model.
// Don't specify it in sidecar model.
// +optional
InterimVolumeTemplate *ofst.PersistentVolumeClaim `json:"interimVolumeTemplate,omitempty"`
// Actions that Stash should take in response to restore sessions.
// +optional
Hooks *RestoreHooks `json:"hooks,omitempty"`
}
// Hooks describes actions that Stash should take in response to restore sessions. For the PostRestore
// and PreRestore handlers, restore process blocks until the action is complete,
// unless the container process fails, in which case the handler is aborted.
type RestoreHooks struct {
// PreRestore is called immediately before a restore session is initiated.
// +optional
PreRestore *prober.Handler `json:"preRestore,omitempty"`
// PostRestore is called immediately after a restore session is complete.
// +optional
PostRestore *prober.Handler `json:"postRestore,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type RestoreSessionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RestoreSession `json:"items,omitempty"`
}
// +kubebuilder:validation:Enum=Pending;Running;Succeeded;Failed;Unknown;Invalid
type RestorePhase string
const (
RestorePending RestorePhase = "Pending"
RestoreRunning RestorePhase = "Running"
RestoreSucceeded RestorePhase = "Succeeded"
RestoreFailed RestorePhase = "Failed"
RestorePhaseUnknown RestorePhase = "Unknown"
RestorePhaseInvalid RestorePhase = "Invalid"
)
// +kubebuilder:validation:Enum=Succeeded;Failed;Running;Unknown
type HostRestorePhase string
const (
HostRestoreSucceeded HostRestorePhase = "Succeeded"
HostRestoreFailed HostRestorePhase = "Failed"
HostRestoreRunning HostRestorePhase = "Running"
HostRestoreUnknown HostRestorePhase = "Unknown"
)
type RestoreSessionStatus struct {
// Phase indicates the overall phase of the restore process for this RestoreSession. Phase will be "Succeeded" only if
// phase of all hosts are "Succeeded". If any of the host fail to complete restore, Phase will be "Failed".
// +optional
Phase RestorePhase `json:"phase,omitempty"`
// TotalHosts specifies total number of hosts that will be restored for this RestoreSession
// +optional
TotalHosts *int32 `json:"totalHosts,omitempty"`
// SessionDuration specify total time taken to complete current restore session (sum of restore duration of all hosts)
// +optional
SessionDuration string `json:"sessionDuration,omitempty"`
// Stats shows statistics of individual hosts for this restore session
// +optional
Stats []HostRestoreStats `json:"stats,omitempty"`
// Conditions shows current restore condition of the RestoreSession.
// +optional
Conditions []kmapi.Condition `json:"conditions,omitempty"`
}
type HostRestoreStats struct {
// Hostname indicate name of the host that has been restored
// +optional
Hostname string `json:"hostname,omitempty"`
// Phase indicates restore phase of this host
// +optional
Phase HostRestorePhase `json:"phase,omitempty"`
// Duration indicates total time taken to complete restore for this hosts
// +optional
Duration string `json:"duration,omitempty"`
// Error indicates string value of error in case of restore failure
// +optional
Error string `json:"error,omitempty"`
}
// ========================= Condition Types ===================
const (
// RestoreTargetFound indicates whether the restore target was found
RestoreTargetFound = "RestoreTargetFound"
// StashInitContainerInjected indicates whether stash init-container was injected into the targeted workload
// This condition is applicable only for sidecar model
StashInitContainerInjected = "StashInitContainerInjected"
// RestoreJobCreated indicates whether the restore job was created
RestoreJobCreated = "RestoreJobCreated"
// RestoreCompleted condition indicates whether the restore process has been completed or not.
// This condition is particularly helpful when the restore addon require some additional operations to perform
// before marking the RestoreSession Succeeded/Failed.
RestoreCompleted = "RestoreCompleted"
// RestoreExecutorEnsured condition indicates whether the restore job / init-container was ensured or not.
RestoreExecutorEnsured = "RestoreExecutorEnsured"
// MetricsPushed whether the metrics for this backup session were pushed or not
MetricsPushed = "MetricsPushed"
// PreRestoreHookExecutionSucceeded indicates whether the preRestore hook was executed successfully or not
PreRestoreHookExecutionSucceeded = "PreRestoreHookExecutionSucceeded"
// PostRestoreHookExecutionSucceeded indicates whether the postRestore hook was executed successfully or not
PostRestoreHookExecutionSucceeded = "PostRestoreHookExecutionSucceeded"
)
// ======================== Condition Reasons ===================
const (
// InitContainerInjectionSucceeded indicates that the condition transitioned to this state because stash init-container
// was injected successfully into the targeted workload
InitContainerInjectionSucceeded = "InitContainerInjectionSucceeded"
// InitContainerInjectionFailed indicates that the condition transitioned to this state because operator was unable
// to inject stash init-container into the targeted workload
InitContainerInjectionFailed = "InitContainerInjectionFailed"
// RestoreJobCreationSucceeded indicates that the condition transitioned to this state because restore job was created successfully
RestoreJobCreationSucceeded = "RestoreJobCreationSucceeded"
// RestoreJobCreationFailed indicates that the condition transitioned to this state because operator was unable to create restore job
RestoreJobCreationFailed = "RestoreJobCreationFailed"
// SuccessfullyPushedMetrics indicates that the condition transitioned to this state because the metrics was successfully pushed to the pushgateway
SuccessfullyPushedMetrics = "SuccessfullyPushedMetrics"
// FailedToPushMetrics indicates that the condition transitioned to this state because the Stash was unable to push the metrics to the pushgateway
FailedToPushMetrics = "FailedToPushMetrics"
SuccessfullyEnsuredRestoreExecutor = "SuccessfullyEnsuredRestoreExecutor"
FailedToEnsureRestoreExecutor = "FailedToEnsureRestoreExecutor"
SuccessfullyExecutedPreRestoreHook = "SuccessfullyExecutedPreRestoreHook"
FailedToExecutePreRestoreHook = "FailedToExecutePreRestoreHook"
SuccessfullyExecutedPostRestoreHook = "SuccessfullyExecutedPostRestoreHook"
FailedToExecutePostRestoreHook = "FailedToExecutePostRestoreHook"
PostRestoreTasksExecuted = "PostRestoreTasksExecuted"
PostRestoreTasksNotExecuted = "PostRestoreTasksNotExecuted"
)