This repository has been archived by the owner on Nov 5, 2021. It is now read-only.
/
cluster_types.go
295 lines (240 loc) · 10.7 KB
/
cluster_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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
Copyright 2021 zhyass.
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 v1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
// 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.
// ClusterSpec defines the desired state of Cluster
type ClusterSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Replicas is the number of pods.
// +optional
// +kubebuilder:validation:Enum=0;2;3;5
// +kubebuilder:default:=3
Replicas *int32 `json:"replicas,omitempty"`
// MysqlOpts is the options of MySQL container.
// +optional
// +kubebuilder:default:={rootPassword: "", user: "qc_usr", password: "Qing@123", database: "qingcloud", initTokuDB: true, resources: {limits: {cpu: "500m", memory: "1Gi"}, requests: {cpu: "100m", memory: "256Mi"}}}
MysqlOpts MysqlOpts `json:"mysqlOpts,omitempty"`
// XenonOpts is the options of xenon container.
// +optional
// +kubebuilder:default:={image: "zhyass/xenon:1.1.5-alpha", admitDefeatHearbeatCount: 5, electionTimeout: 10000, resources: {limits: {cpu: "100m", memory: "256Mi"}, requests: {cpu: "50m", memory: "128Mi"}}}
XenonOpts XenonOpts `json:"xenonOpts,omitempty"`
// +optional
// +kubebuilder:default:={image: "prom/mysqld-exporter:v0.12.1", resources: {limits: {cpu: "100m", memory: "128Mi"}, requests: {cpu: "10m", memory: "32Mi"}}, enabled: false}
MetricsOpts MetricsOpts `json:"metricsOpts,omitempty"`
// Represents the MySQL version that will be run. The available version can be found here:
// This field should be set even if the Image is set to let the operator know which mysql version is running.
// Based on this version the operator can take decisions which features can be used.
// +optional
// +kubebuilder:default:="5.7"
MysqlVersion string `json:"mysqlVersion,omitempty"`
// Pod extra specification
// +optional
// +kubebuilder:default:={imagePullPolicy: "IfNotPresent", resources: {requests: {cpu: "10m", memory: "32Mi"}}, sidecarImage: "zhyass/sidecar:0.1", busyboxImage: "busybox:1.32"}
PodSpec PodSpec `json:"podSpec,omitempty"`
// PVC extra specifiaction
// +optional
// +kubebuilder:default:={enabled: true, accessModes: {"ReadWriteOnce"}, size: "10Gi"}
Persistence Persistence `json:"persistence,omitempty"`
}
// MysqlOpts defines the options of MySQL container.
type MysqlOpts struct {
// Password for the root user.
// +optional
// +kubebuilder:default:=""
RootPassword string `json:"rootPassword,omitempty"`
// Username of new user to create.
// +optional
// +kubebuilder:default:="qc_usr"
User string `json:"user,omitempty"`
// Password for the new user.
// +optional
// +kubebuilder:default:="Qing@123"
Password string `json:"password,omitempty"`
// Name for new database to create.
// +optional
// +kubebuilder:default:="qingcloud"
Database string `json:"database,omitempty"`
// Install tokudb engine.
// +optional
// +kubebuilder:default:=true
InitTokuDB bool `json:"initTokuDB,omitempty"`
// A map[string]string that will be passed to my.cnf file.
// +optional
MysqlConf MysqlConf `json:"mysqlConf,omitempty"`
// +optional
// +kubebuilder:default:={limits: {cpu: "500m", memory: "1Gi"}, requests: {cpu: "100m", memory: "256Mi"}}
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
}
// XenonOpts defines the options of xenon container.
type XenonOpts struct {
// To specify the image that will be used for xenon container.
// +optional
// +kubebuilder:default:="zhyass/xenon:1.1.5-alpha"
Image string `json:"image,omitempty"`
// High available component admit defeat heartbeat count.
// +optional
// +kubebuilder:default:=5
AdmitDefeatHearbeatCount *int32 `json:"admitDefeatHearbeatCount,omitempty"`
// High available component election timeout. The unit is millisecond.
// +optional
// +kubebuilder:default:=10000
ElectionTimeout *int32 `json:"electionTimeout,omitempty"`
// +optional
// +kubebuilder:default:={limits: {cpu: "100m", memory: "256Mi"}, requests: {cpu: "50m", memory: "128Mi"}}
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
}
type MetricsOpts struct {
// +optional
// +kubebuilder:default:="prom/mysqld-exporter:v0.12.1"
Image string `json:"image,omitempty"`
// +optional
// +kubebuilder:default:={limits: {cpu: "100m", memory: "128Mi"}, requests: {cpu: "10m", memory: "32Mi"}}
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
// +optional
// +kubebuilder:default:=false
Enabled bool `json:"enabled,omitempty"`
}
// MysqlConf defines type for extra cluster configs. It's a simple map between
// string and string.
type MysqlConf map[string]intstr.IntOrString
// PodSpec defines type for configure cluster pod spec.
type PodSpec struct {
// +kubebuilder:validation:Enum=Always;IfNotPresent;Never
// +kubebuilder:default:="IfNotPresent"
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
SchedulerName string `json:"schedulerName,omitempty"`
// +optional
// +kubebuilder:default:={requests: {cpu: "10m", memory: "32Mi"}}
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
// +optional
// +kubebuilder:default:="zhyass/sidecar:0.1"
SidecarImage string `json:"sidecarImage,omitempty"`
// +optional
// +kubebuilder:default:="busybox:1.32"
BusyboxImage string `json:"busyboxImage,omitempty"`
// +optional
// +kubebuilder:default:=false
SlowLogTail bool `json:"slowLogTail,omitempty"`
// +optional
// +kubebuilder:default:=false
AuditLogTail bool `json:"auditLogTail,omitempty"`
}
// Persistence is the desired spec for storing mysql data. Only one of its
// members may be specified.
type Persistence struct {
// +optional
// +kubebuilder:default:=true
Enabled bool `json:"enabled,omitempty"`
// AccessModes contains the desired access modes the volume should have.
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1
// +optional
// +kubebuilder:default:={"ReadWriteOnce"}
AccessModes []corev1.PersistentVolumeAccessMode `json:"accessModes,omitempty"`
// Name of the StorageClass required by the claim.
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1
// +optional
StorageClass *string `json:"storageClass,omitempty"`
// +optional
// +kubebuilder:default:="10Gi"
Size string `json:"size,omitempty"`
}
type ClusterConditionType string
const (
ClusterInit ClusterConditionType = "Initializing"
ClusterReady ClusterConditionType = "Ready"
ClusterError ClusterConditionType = "Error"
)
// ClusterCondition defines type for cluster conditions.
type ClusterCondition struct {
// type of cluster condition, values in (\"Ready\")
Type ClusterConditionType `json:"type"`
// Status of the condition, one of (\"True\", \"False\", \"Unknown\")
Status corev1.ConditionStatus `json:"status"`
// LastTransitionTime
LastTransitionTime metav1.Time `json:"lastTransitionTime"`
// Reason
Reason string `json:"reason,omitempty"`
// Message
Message string `json:"message,omitempty"`
}
// NodeStatus defines type for status of a node into cluster.
type NodeStatus struct {
Name string `json:"name"`
Message string `json:"message,omitempty"`
Conditions []NodeCondition `json:"conditions,omitempty"`
}
// NodeCondition defines type for representing node conditions.
type NodeCondition struct {
Type NodeConditionType `json:"type"`
Status corev1.ConditionStatus `json:"status"`
LastTransitionTime metav1.Time `json:"lastTransitionTime"`
}
// NodeConditionType defines type for node condition type.
type NodeConditionType string
const (
// NodeConditionLagged represents if the node is lagged.
NodeConditionLagged NodeConditionType = "Lagged"
// NodeConditionLeader represents if the node is leader or not.
NodeConditionLeader NodeConditionType = "Leader"
// NodeConditionReadOnly repesents if the node is read only or not
NodeConditionReadOnly NodeConditionType = "ReadOnly"
// NodeConditionReplicating represents if the node is replicating or not.
NodeConditionReplicating NodeConditionType = "Replicating"
)
// ClusterStatus defines the observed state of Cluster
type ClusterStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
// ReadyNodes represents number of the nodes that are in ready state
ReadyNodes int `json:"readyNodes,omitempty"`
State ClusterConditionType `json:"state,omitempty"`
// Conditions contains the list of the cluster conditions fulfilled
Conditions []ClusterCondition `json:"conditions,omitempty"`
Nodes []NodeStatus `json:"nodes,omitempty"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.readyNodes
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type == 'Ready')].status",description="The cluster status"
// +kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".spec.replicas",description="The number of desired nodes"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:resource:shortName=mysql
// Cluster is the Schema for the clusters API
type Cluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ClusterSpec `json:"spec,omitempty"`
Status ClusterStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// ClusterList contains a list of Cluster
type ClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Cluster `json:"items"`
}
func init() {
SchemeBuilder.Register(&Cluster{}, &ClusterList{})
}