/
mysqlcluster_types.go
394 lines (322 loc) · 15.6 KB
/
mysqlcluster_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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/*
Copyright 2018 Pressinfra SRL
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 v1alpha1
import (
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
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.
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
// MysqlClusterSpec defines the desired state of MysqlCluster
// nolint: maligned
type MysqlClusterSpec struct {
// The number of pods. This updates replicas filed
// Defaults to 0
// +optional
Replicas *int32 `json:"replicas,omitempty"`
// The secret name that contains connection information to initialize database, like
// USER, PASSWORD, ROOT_PASSWORD and so on
// This secret will be updated with DB_CONNECT_URL and some more configs.
// Can be specified partially
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=63
SecretName string `json:"secretName"`
// Represents the MySQL version that will be run. The available version can be found here:
// https://github.com/bitpoke/mysql-operator/blob/0fd4641ce4f756a0aab9d31c8b1f1c44ee10fcb2/pkg/util/constants/constants.go#L87
// 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.
// Defaults to 5.7
// +optional
MysqlVersion string `json:"mysqlVersion,omitempty"`
// To specify the image that will be used for mysql server container.
// If this is specified then the mysqlVersion is used as source for MySQL server version.
// +optional
Image string `json:"image,omitempty"`
// A bucket URL that contains a xtrabackup to initialize the mysql database.
// +optional
InitBucketURL string `json:"initBucketURL,omitempty"`
// Same as InitBucketURL but is DEPRECATED
// +optional
InitBucketURI string `json:"initBucketURI,omitempty"`
InitBucketSecretName string `json:"initBucketSecretName,omitempty"`
// The number of pods from that set that must still be available after the
// eviction, even in the absence of the evicted pod
// Defaults to 50%
// +optional
MinAvailable string `json:"minAvailable,omitempty"`
// Specify under crontab format interval to take backups
// leave it empty to deactivate the backup process
// Defaults to ""
// +optional
BackupSchedule string `json:"backupSchedule,omitempty"`
// Represents an URL to the location where to put backups.
// +optional
BackupURL string `json:"backupURL,omitempty"`
// BackupRemoteDeletePolicy the deletion policy that specify how to treat the data from remote storage. By
// default it's used softDelete.
// +optional
BackupRemoteDeletePolicy DeletePolicy `json:"backupRemoteDeletePolicy,omitempty"`
// Represents the name of the secret that contains credentials to connect to
// the storage provider to store backups.
// +optional
BackupSecretName string `json:"backupSecretName,omitempty"`
// If set keeps last BackupScheduleJobsHistoryLimit Backups
// +optional
BackupScheduleJobsHistoryLimit *int `json:"backupScheduleJobsHistoryLimit,omitempty"`
// A map[string]string that will be passed to my.cnf file.
// +optional
MysqlConf MysqlConf `json:"mysqlConf,omitempty"`
// Pod extra specification
// +optional
PodSpec PodSpec `json:"podSpec,omitempty"`
// PVC extra specifiaction
// +optional
VolumeSpec VolumeSpec `json:"volumeSpec,omitempty"`
// TmpfsSize if specified, mounts a tmpfs of this size into /tmp
// DEPRECATED: use instead PodSpec.Volumes and PodSpec.VolumeMounts
// +optional
TmpfsSize *resource.Quantity `json:"tmpfsSize,omitempty"`
// MaxSlaveLatency represents the allowed latency for a slave node in
// seconds. If set then the node with a latency grater than this is removed
// from service.
// +optional
MaxSlaveLatency *int64 `json:"maxSlaveLatency,omitempty"`
// QueryLimits represents limits for a query
// +optional
QueryLimits *QueryLimits `json:"queryLimits,omitempty"`
// Makes the cluster READ ONLY. This has not a strong guarantee, in case of a failover the cluster will be writable
// for at least a few seconds.
// +optional
ReadOnly bool `json:"readOnly,omitempty"`
// Set a custom offset for Server IDs. ServerID for each node will be the index of the statefulset, plus offset
// +optional
ServerIDOffset *int `json:"serverIDOffset,omitempty"`
// BackupCompressCommand is a command to use for compressing the backup.
// +optional
BackupCompressCommand []string `json:"backupCompressCommand,omitempty"`
// BackupDecompressCommand is a command to use for decompressing the backup.
// +optional
BackupDecompressCommand []string `json:"backupDecompressCommand,omitempty"`
// MetricsExporterExtraArgs is a list of extra command line arguments to pass to MySQL metrics exporter.
// See https://github.com/prometheus/mysqld_exporter for the list of available flags.
// +optional
MetricsExporterExtraArgs []string `json:"metricsExporterExtraArgs,omitempty"`
// RcloneExtraArgs is a list of extra command line arguments to pass to rclone.
// +optional
RcloneExtraArgs []string `json:"rcloneExtraArgs,omitempty"`
// XbstreamExtraArgs is a list of extra command line arguments to pass to xbstream.
// +optional
XbstreamExtraArgs []string `json:"xbstreamExtraArgs,omitempty"`
// XtrabackupExtraArgs is a list of extra command line arguments to pass to xtrabackup.
// +optional
XtrabackupExtraArgs []string `json:"xtrabackupExtraArgs,omitempty"`
// XtrabackupPrepareExtraArgs is a list of extra command line arguments to pass to xtrabackup
// during --prepare.
// +optional
XtrabackupPrepareExtraArgs []string `json:"xtrabackupPrepareExtraArgs,omitempty"`
// XtrabackupTargetDir is a backup destination directory for xtrabackup.
// +optional
XtrabackupTargetDir string `json:"xtrabackupTargetDir,omitempty"`
// InitFileExtraSQL is a list of extra sql commands to append to init_file.
// +optional
InitFileExtraSQL []string `json:"initFileExtraSQL,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 {
ImagePullPolicy core.PullPolicy `json:"imagePullPolicy,omitempty"`
ImagePullSecrets []core.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Resources core.ResourceRequirements `json:"resources,omitempty"`
Affinity *core.Affinity `json:"affinity,omitempty"`
MysqlLifecycle *core.Lifecycle `json:"mysqlLifecycle,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Tolerations []core.Toleration `json:"tolerations,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
BackupAffinity *core.Affinity `json:"backupAffinity,omitempty"`
BackupNodeSelector map[string]string `json:"backupNodeSelector,omitempty"`
BackupPriorityClassName string `json:"backupPriorityClassName,omitempty"`
BackupTolerations []core.Toleration `json:"backupTolerations,omitempty"`
// Volumes allows adding extra volumes to the statefulset
// +optional
Volumes []core.Volume `json:"volumes,omitempty"`
// VolumesMounts allows mounting extra volumes to the mysql container
// +optional
VolumeMounts []core.VolumeMount `json:"volumeMounts,omitempty"`
// InitContainers allows the user to specify extra init containers
// +optional
InitContainers []core.Container `json:"initContainers,omitempty"`
// Containers allows for user to specify extra sidecar containers to run along with mysql
// +optional
Containers []core.Container `json:"containers,omitempty"`
// MetricsExporterResources allows you to specify resources for metrics exporter container
// +optional
MetricsExporterResources core.ResourceRequirements `json:"metricsExporterResources,omitempty"`
// MySQLOperatorSidecarResources allows you to specify resources for sidecar container
// used to take backups with xtrabackup
// +optional
MySQLOperatorSidecarResources core.ResourceRequirements `json:"mysqlOperatorSidecarResources,omitempty"`
// PtHeartbeatResources allows you to specify resources for pt-heartbeat container
// +optional
PtHeartbeatResources core.ResourceRequirements `json:"ptHeartbeatResources,omitempty"`
}
// VolumeSpec is the desired spec for storing mysql data. Only one of its
// members may be specified.
type VolumeSpec struct {
// EmptyDir to use as data volume for mysql. EmptyDir represents a temporary
// directory that shares a pod's lifetime.
// +optional
EmptyDir *core.EmptyDirVolumeSource `json:"emptyDir,omitempty"`
// HostPath to use as data volume for mysql. HostPath represents a
// pre-existing file or directory on the host machine that is directly
// exposed to the container.
// +optional
HostPath *core.HostPathVolumeSource `json:"hostPath,omitempty"`
// PersistentVolumeClaim to specify PVC spec for the volume for mysql data.
// It has the highest level of precedence, followed by HostPath and
// EmptyDir. And represents the PVC specification.
// +optional
PersistentVolumeClaim *core.PersistentVolumeClaimSpec `json:"persistentVolumeClaim,omitempty"`
// KeepAfterDelete specifies whether the PVC should be kept after the MysqlCluster is deleted.
// +optional
KeepAfterDelete bool `json:"keepAfterDelete,omitempty"`
}
// QueryLimits represents the pt-kill parameters, more info can be found
// here: https://www.percona.com/doc/percona-toolkit/LATEST/pt-kill.html
type QueryLimits struct {
// MaxIdleTime match queries that have been idle for longer then this time,
// in seconds. (--idle-time flag)
// + optional
MaxIdleTime *int `json:"maxIdleTime,omitempty"`
// MaxQueryTime match queries that have been running for longer then this
// time, in seconds. This field is required. (--busy-time flag)
MaxQueryTime int `json:"maxQueryTime"`
// Kill represents the mode of which the matching queries in each class will
// be killed, (the --victims flag). Can be one of oldest|all|all-but-oldest.
// By default, the matching query with the highest Time value is killed (the
// oldest query.
// +optional
Kill string `json:"kill,omitempty"`
// KillMode can be: `connection` or `query`, when it's used `connection`
// means that when a query is matched the connection is killed (using --kill
// flag) and if it's used `query` means that the query is killed (using
// --kill-query flag)
// +optional
KillMode string `json:"killMode,omitempty"`
// IgnoreDb is the list of database that are ignored by pt-kill (--ignore-db
// flag).
// +optional
IgnoreDb []string `json:"ignoreDb,omitempty"`
// IgnoreCommands the list of commands to be ignored.
// +optional
IgnoreCommand []string `json:"ignoreCommands,omitempty"`
// IgnoreUser the list of users to be ignored.
// +optional
IgnoreUser []string `json:"ignoreUser,omitempty"`
}
// 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 core.ConditionStatus `json:"status"`
// LastTransitionTime
LastTransitionTime metav1.Time `json:"lastTransitionTime"`
// Reason
Reason string `json:"reason"`
// Message
Message string `json:"message"`
}
// ClusterConditionType defines type for cluster condition type.
type ClusterConditionType string
const (
// ClusterConditionReady represents the readiness of the cluster. This
// condition is the same sa statefulset Ready condition.
ClusterConditionReady ClusterConditionType = "Ready"
// ClusterConditionFailoverAck represents if the cluster has pending ack in
// orchestrator or not.
ClusterConditionFailoverAck ClusterConditionType = "PendingFailoverAck"
// ClusterConditionReadOnly describe cluster state if it's in read only or
// writable.
ClusterConditionReadOnly ClusterConditionType = "ReadOnly"
// ClusterConditionFailoverInProgress indicates if there is a current failover in progress
// done by the Orchestrator
ClusterConditionFailoverInProgress ClusterConditionType = "FailoverInProgress"
)
// NodeStatus defines type for status of a node into cluster.
type NodeStatus struct {
Name string `json:"name"`
Conditions []NodeCondition `json:"conditions,omitempty"`
}
// NodeCondition defines type for representing node conditions.
type NodeCondition struct {
Type NodeConditionType `json:"type"`
Status core.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 marked as lagged by
// orchestrator.
NodeConditionLagged NodeConditionType = "Lagged"
// NodeConditionReplicating represents if the node is replicating or not.
NodeConditionReplicating NodeConditionType = "Replicating"
// NodeConditionMaster represents if the node is master or not.
NodeConditionMaster NodeConditionType = "Master"
// NodeConditionReadOnly repesents if the node is read only or not
NodeConditionReadOnly NodeConditionType = "ReadOnly"
)
// MysqlClusterStatus defines the observed state of MysqlCluster
type MysqlClusterStatus struct {
// ReadyNodes represents number of the nodes that are in ready state
ReadyNodes int `json:"readyNodes,omitempty"`
// Conditions contains the list of the cluster conditions fulfilled
Conditions []ClusterCondition `json:"conditions,omitempty"`
// Nodes contains informations from orchestrator
Nodes []NodeStatus `json:"nodes,omitempty"`
}
// MysqlCluster is the Schema for the mysqlclusters API
// +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
//
type MysqlCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec MysqlClusterSpec `json:"spec,omitempty"`
Status MysqlClusterStatus `json:"status,omitempty"`
}
// MysqlClusterList contains a list of MysqlCluster
// +kubebuilder:object:root=true
//
type MysqlClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MysqlCluster `json:"items"`
}
func init() {
SchemeBuilder.Register(&MysqlCluster{}, &MysqlClusterList{})
}