/
serverlessdb_types.go
211 lines (171 loc) · 6.6 KB
/
serverlessdb_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
package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// ClusterPhase is the current state of tidb
type ClusterPhase string
const (
// Creating represents normal state of cluster.
PhaseCreating ClusterPhase = "Creating"
// Indicates cluster is being recovering or going to recover.
PhaseRecovering ClusterPhase = "Recovering"
// PhaseAvailable indicates that the cluster status is normal and available
PhaseAvailable ClusterPhase = "Available"
// Unavailable represents the scaling state of cluster.
PhaseUnavailable ClusterPhase = "Unavailable"
// PhaseFailed indicates that the cluster completely failed, unable to recover
PhaseFailed ClusterPhase = "Failed"
)
type MaxValue struct {
Metric `json:",inline"`
Component Storage `json:"component,omitempty"`
}
type StorageType string
const (
CLOUD StorageType = "cloud"
LOCAL StorageType = "local"
)
type Storage struct {
// StorageSize is the request storage size for backup job
StorageType StorageType `json:"type,omitempty"`
// The storageClassName of the persistent volume for Backup data storage.
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`
// StorageSize is the request storage size
StorageSize string `json:"storageSize,omitempty"`
}
type PeriodType string
const (
CUSTOMIZE PeriodType = ""
DAY PeriodType = "day"
WEEK PeriodType = "week"
MONTH PeriodType = "month"
)
type Rule struct {
StartTime *metav1.Time `json:"startTime,omitempty"`
EndTime *metav1.Time `json:"endTime,omitempty"`
Metric Metric `json:"metric,omitempty"`
Period PeriodType `json:"period,omitempty"`
}
type Metric struct {
HashRate string `json:"hashRate,omitempty"`
}
type Proxy struct {
// Defaults to "0".
// +optional
// +kubebuilder:default=0
SilentPeriod string `json:"silentPeriod,omitempty"`
}
// ServerlessDBSpec defines the desired state of ServerlessDB
// +k8s:openapi-gen=true
type ServerlessDBSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
// Add custom validation using kubebuilder tags: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html
// Indicates that the severlessdb is paused and will not be processed by
// the controller.
// +optional
Paused bool `json:"paused,omitempty"`
// Prevent external connections to tidb server
// +optional
Freeze bool `json:"freeze,omitempty"`
// +optional
// +kubebuilder:default=IfNotPresent
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy"`
Proxy Proxy `json:"proxy,omitempty"`
MaxValue MaxValue `json:"maxValue,omitempty"`
// Indicates that the tiflash cluster is used and will not be processed by
// the controller.
// +optional
UseTiFlash bool `json:"useTiFlash,omitempty"`
ScaleOut string `json:"scaleOut,omitempty"`
ScaleIn string `json:"scaleIn,omitempty"`
RateOfScaleDown string `json:"rateOfScaleDown,omitempty"`
TimeToScaleDown string `json:"timeToScaleDown,omitempty"`
NormalResource corev1.ResourceRequirements `json:"normalResource,omitempty"`
MinResource corev1.ResourceRequirements `json:"minResource,omitempty"`
Rule map[string]Rule `json:"rule,omitempty"`
}
// ConditionType represents a cluster condition value.
type ConditionType string
const (
// Ready indicates that the cluster is ready or not.
// This is defined as:
// - All Components reach usable level
// todo: add condition type
Ready ConditionType = "Ready"
// TiDBInitial: waiting tidb initial successful,
// status.phase will still be Creating if condition exist TiDBInitial type
TiDBInitial ConditionType = "TiDBInitial"
TiDBRestart ConditionType = "TiDBRestart"
TiDBSilence ConditionType = "TiDBSilence"
TiDBReadonly ConditionType = "TiDBReadonly"
)
// ServerlessDBCondition describes the state of a cluster at a certain point.
type ServerlessDBCondition struct {
// Type of the condition.
Type ConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
Status corev1.ConditionStatus `json:"status"`
// The last time this condition was updated.
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
// Last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// The reason for the condition's last transition.
// +optional
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
// +optional
Message string `json:"message,omitempty"`
}
type PortName string
const (
Prometheus PortName = "Prometheus"
TiDBServer PortName = "TiDBServer"
)
type StorageUse string
const (
TiKVSingleStoreMax StorageUse = "TiKVSingleStoreMax"
TiKVTotalStoreUsage StorageUse = "TiKVTotalStoreUsage"
)
// ServerlessDBStatus defines the observed state of ServerlessDB
type ServerlessDBStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
// Add custom validation using kubebuilder tags: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html
// Rule is the Currently triggered rule
Rule []string `json:"rule,omitempty"`
// Represents the latest phase
Phase ClusterPhase `json:"phase,omitempty"`
// Node port for sldb
NodePort map[PortName]int32 `json:"nodePort,omitempty"`
// storage usage
StorageUsage map[StorageUse]resource.Quantity `json:"storageUsage,omitempty"`
// Represents the latest available observations of a cluster's state.
// +optional
Conditions []ServerlessDBCondition `json:"conditions,omitempty"`
}
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ServerlessDB is the Schema for the serverlessdbs API
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=serverlessdbs,scope=Namespaced
type ServerlessDB struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ServerlessDBSpec `json:"spec"`
Status ServerlessDBStatus `json:"status"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ServerlessDBList contains a list of ServerlessDB
type ServerlessDBList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []ServerlessDB `json:"items"`
}