/
restore_batch_types.go
152 lines (133 loc) · 6.8 KB
/
restore_batch_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
/*
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"
)
const (
ResourceKindRestoreBatch = "RestoreBatch"
ResourceSingularRestoreBatch = "restorebatch"
ResourcePluralRestoreBatch = "restorebatches"
)
// +genclient
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=restorebatches,singular=restorebatch,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 RestoreBatch struct {
metav1.TypeMeta `json:",inline,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec RestoreBatchSpec `json:"spec,omitempty"`
Status RestoreBatchStatus `json:"status,omitempty"`
}
type RestoreBatchSpec struct {
// 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 holds backend information
// +optional
Repository kmapi.ObjectReference `json:"repository,omitempty"`
// Members is a list of restore targets and their configuration that are part of this batch
// +optional
Members []RestoreTargetSpec `json:"members,omitempty"`
// ExecutionOrder indicate whether to restore the members in the sequential order as they appear in the members list.
// The default value is "Parallel" which means the members will be restored in parallel.
// +kubebuilder:default=Parallel
// +optional
ExecutionOrder ExecutionOrder `json:"executionOrder,omitempty"`
// Hooks specifies the actions that Stash should take before or after restore.
// Cannot be updated.
// +optional
Hooks *RestoreHooks `json:"hooks,omitempty"`
// TimeOut specifies the maximum duration of restore. RestoreBatch will be considered Failed
// if restore does not complete within this time limit. By default, Stash don't set any timeout for restore.
// +optional
TimeOut *metav1.Duration `json:"timeOut,omitempty"`
}
type RestoreBatchStatus struct {
// Phase indicates the overall phase of the restore process for this RestoreBatch. Phase will be "Succeeded" only if
// phase of all members are "Succeeded". If the restore process fail for any of the members, Phase will be "Failed".
// +optional
Phase RestorePhase `json:"phase,omitempty"`
// SessionDuration specify total time taken to complete restore of all the members.
// +optional
SessionDuration string `json:"sessionDuration,omitempty"`
// Conditions shows the condition of different steps for the RestoreBatch.
// +optional
Conditions []kmapi.Condition `json:"conditions,omitempty"`
// Members shows the restore status for the members of the RestoreBatch.
// +optional
Members []RestoreMemberStatus `json:"members,omitempty"`
// SessionDeadline specifies the deadline of restore process. RestoreBatch will be
// considered Failed if restore does not complete within this deadline
// +optional
SessionDeadline *metav1.Time `json:"sessionDeadline,omitempty"`
}
// +kubebuilder:validation:Enum=Pending;Succeeded;Running;Failed
type RestoreTargetPhase string
const (
TargetRestorePending RestoreTargetPhase = "Pending"
TargetRestoreRunning RestoreTargetPhase = "Running"
TargetRestoreSucceeded RestoreTargetPhase = "Succeeded"
TargetRestoreFailed RestoreTargetPhase = "Failed"
TargetRestorePhaseUnknown RestoreTargetPhase = "Unknown"
)
type RestoreMemberStatus struct {
// Ref is the reference to the respective target whose status is shown here.
Ref TargetRef `json:"ref"`
// Conditions shows the condition of different steps to restore this member.
// +optional
Conditions []kmapi.Condition `json:"conditions,omitempty"`
// TotalHosts specifies total number of hosts that will be restored for this member.
// +optional
TotalHosts *int32 `json:"totalHosts,omitempty"`
// Phase indicates restore phase of this member
// +optional
Phase RestoreTargetPhase `json:"phase,omitempty"`
// Stats shows restore statistics of individual hosts for this member
// +optional
Stats []HostRestoreStats `json:"stats,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type RestoreBatchList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RestoreBatch `json:"items,omitempty"`
}
// =============================== Condition Types =====================================
const (
// GlobalPreRestoreHookSucceeded indicates whether the global PreRestoreHook was executed successfully or not
GlobalPreRestoreHookSucceeded = "GlobalPreRestoreHookSucceeded"
// GlobalPostRestoreHookSucceeded indicates whether the global PostRestoreHook was executed successfully or not
GlobalPostRestoreHookSucceeded = "GlobalPostRestoreHookSucceeded"
)
// ============================== Condition Reasons ===================================
const (
// GlobalPreRestoreHookExecutedSuccessfully indicates that the condition transitioned to this state because the global PreRestoreHook was executed successfully
GlobalPreRestoreHookExecutedSuccessfully = "GlobalPreRestoreHookExecutedSuccessfully"
// GlobalPreRestoreHookExecutionFailed indicates that the condition transitioned to this state because the Stash was unable to execute global PreRestoreHook
GlobalPreRestoreHookExecutionFailed = "GlobalPreRestoreHookExecutionFailed"
// GlobalPostRestoreHookExecutedSuccessfully indicates that the condition transitioned to this state because the global PostRestoreHook was executed successfully
GlobalPostRestoreHookExecutedSuccessfully = "GlobalPostRestoreHookExecutedSuccessfully"
// GlobalPostRestoreHookExecutionFailed indicates that the condition transitioned to this state because the Stash was unable to execute global PostRestoreHook
GlobalPostRestoreHookExecutionFailed = "GlobalPostRestoreHookExecutionFailed"
)