generated from cybozu-go/neco-template
/
constants.go
324 lines (255 loc) · 10.4 KB
/
constants.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
package moco
import (
"errors"
"fmt"
corev1 "k8s.io/api/core/v1"
)
const (
// RootUser is the name of root user in the MySQL context.
RootUser = "root"
// OperatorUser is a name of MOCO operator user in the MySQL context.
OperatorUser = "moco"
// OperatorAdminUser is a name of MOCO operator-admin user in the MySQL context.
// This user is a super user especially for creating and granting privileges to other users.
OperatorAdminUser = "moco-admin"
// ReplicationUser is a name of MOCO replicator user in the MySQL context.
ReplicationUser = "moco-repl"
// CloneDonorUser is a name of MOCO clone-donor user in the MySQL context.
CloneDonorUser = "moco-clone-donor"
// MiscUser is a name of MOCO misc user in the MySQL context.
MiscUser = "moco-misc"
// ReadOnlyUser is a name of MOCO predefined human user with wide read-only rights used for manual operation.
ReadOnlyUser = "moco-readonly"
// WritableUser is a name of MOCO predefined human user with wide read/write rights used for manual operation.
WritableUser = "moco-writable"
)
const (
// MySQLDataPath is a path for MySQL data dir.
MySQLDataPath = "/var/lib/mysql"
// MySQLConfPath is a path for MySQL conf dir.
MySQLConfPath = "/etc/mysql"
// MySQLConfName is a filename for MySQL conf.
MySQLConfName = "my.cnf"
// VarRunPath is a path for variable files which concerns MySQLd.
VarRunPath = "/var/run/mysqld"
// VarLogPath is a path for /var/log/mysql.
VarLogPath = "/var/log/mysql"
// MySQLErrorLogName is a filename of error log for MySQL.
MySQLErrorLogName = "mysql.err"
// MySQLSlowLogName is a filename of slow query log for MySQL.
MySQLSlowLogName = "mysql.slow"
// TmpPath is a path for /tmp.
TmpPath = "/tmp"
// MyCnfSecretPath is the path for my.cnf formated credentials for CLI
MyCnfSecretPath = "/mysql-credentials"
// MySQLConfTemplatePath is
MySQLConfTemplatePath = "/etc/mysql_template"
// DonorPasswordPath is the path to donor user passsword file
DonorPasswordPath = MySQLDataPath + "/donor-password"
// MiscPasswordPath is the path to misc user passsword file
MiscPasswordPath = MySQLDataPath + "/misc-password"
// ReplicationSourceSecretPath is the path to replication source secret file
ReplicationSourceSecretPath = MySQLDataPath + "/replication-source-secret"
// InnoDBBufferPoolRatioPercent is the ratio of InnoDB buffer pool size to resource.limits.memory or resource.requests.memory
// Note that the pool size doesn't set to lower than 128MiB, which is the default innodb_buffer_pool_size value
InnoDBBufferPoolRatioPercent = 70
)
const (
// MySQLPort is a port number for MySQL
MySQLPort = 3306
// MySQLAdminPort is a port number for MySQL Admin
MySQLAdminPort = 33062
// MySQLXPort is a port number for MySQL XProtocol
MySQLXPort = 33060
)
const (
// AgentPort is a port number for agent container
AgentPort = 9080
// AgentTokenEnvName is a name of the environment variable of agent token.
AgentTokenEnvName = "MOCO_AGENT_TOKEN"
// AgentTokenParam is a name of the param of agent token.
AgentTokenParam = "token"
)
// env names must correspond to options in entrypoint/init.go
const (
// PodNameEnvName is a name of the environment variable of a pod name.
PodNameEnvName = "POD_NAME"
// PodNameFlag is a name of the flag of a pod name.
PodNameFlag = "pod-name"
// PodNamespaceEnvName is a name of the environment variable of a pod namespace.
PodNamespaceEnvName = "POD_NAMESPACE"
// PodNamespaceFlag is a name of the flag of a pod namespace.
PodNamespaceFlag = "pod-namespace"
// PodIPEnvName is a name of the environment variable of a pod IP.
PodIPEnvName = "POD_IP"
// PodNameFlag is a name of the flag of a pod IP.
PodIPFlag = "pod-ip"
// NodeNameEnvName is a name of the environment variable of a node name where the pod runs.
NodeNameEnvName = "NODE_NAME"
// NodeNameFlag is a name of the flag of a node name where the pod runs.
NodeNameFlag = "node-name"
// RootPasswordEnvName is a name of the environment variable of a root password.
RootPasswordEnvName = "ROOT_PASSWORD"
// OperatorPasswordEnvName is a name of the environment variable of a password for both operator and operator-admin.
OperatorPasswordEnvName = "OPERATOR_PASSWORD"
// ReplicationPasswordEnvName is a name of the environment variable of a password for replication user.
ReplicationPasswordEnvName = "REPLICATION_PASSWORD"
// ClonePasswordEnvName is a name of the environment variable of a password for donor user.
ClonePasswordEnvName = "CLONE_DONOR_PASSWORD"
// MiscPasswordEnvName is a name of the environment variable of a password for the misc user.
MiscPasswordEnvName = "MISC_PASSWORD"
// ReadOnlyPasswordEnvName is a name of the environment variable of a password for moco-readonly.
ReadOnlyPasswordEnvName = "READONLY_PASSWORD"
// WritablePasswordEnvName is a name of the environment variable of a password for moco-writable.
WritablePasswordEnvName = "WRITABLE_PASSWORD"
)
const (
// RootPasswordKey is a Secret key for root password.
RootPasswordKey = "ROOT_PASSWORD"
// OperatorPasswordKey is a Secret key for operator password.
OperatorPasswordKey = "OPERATOR_PASSWORD"
// ReplicationPasswordKey is a Secret key for operator replication password.
ReplicationPasswordKey = "REPLICATION_PASSWORD"
// CloneDonorPasswordKey is a Secret key for operator donor password.
CloneDonorPasswordKey = "CLONE_DONOR_PASSWORD"
// MiscPasswordKey is a Secret key for misc user password.
MiscPasswordKey = "MISC_PASSWORD"
// ReadOnlyPasswordKey is a Secret key for moco-readonly user password.
ReadOnlyPasswordKey = "READONLY_PASSWORD"
// ReadOnlyPasswordKey is a Secret key for moco-writable user password.
WritablePasswordKey = "WRITABLE_PASSWORD"
// RootMyCnfKey is the username and password of root formated as my.cnf
RootMyCnfKey = RootUser + "-my.cnf"
// ReadOnlyMyCnfKey is the username and password of moco-readonly formated as my.cnf
ReadOnlyMyCnfKey = ReadOnlyUser + "-my.cnf"
// WritableMyCnfKey is the username and password or moco-writable formated as my.cnf
WritableMyCnfKey = WritableUser + "-my.cnf"
// ReplicationSourcePrimaryHostKey etc. are Secret key for replication source secret
ReplicationSourcePrimaryHostKey = "PRIMARY_HOST"
ReplicationSourcePrimaryUserKey = "PRIMARY_USER"
ReplicationSourcePrimaryPasswordKey = "PRIMARY_PASSWORD"
ReplicationSourcePrimaryPortKey = "PRIMARY_PORT"
ReplicationSourceCloneUserKey = "CLONE_USER"
ReplicationSourceClonePasswordKey = "CLONE_PASSWORD"
ReplicationSourceInitAfterCloneUserKey = "INIT_AFTER_CLONE_USER"
ReplicationSourceInitAfterClonePasswordKey = "INIT_AFTER_CLONE_PASSWORD"
)
const (
// InitializedClusterIndexField is an index name for Initialized MySQL Clusters
InitializedClusterIndexField = ".status.conditions.type.initialized"
)
const (
MyName = "moco"
AppName = "moco-mysql"
ClusterKey = "app.kubernetes.io/instance"
ManagedByKey = "app.kubernetes.io/managed-by"
AppNameKey = "app.kubernetes.io/name"
RoleKey = "moco.cybozu.com/role"
PrimaryRole = "primary"
ReplicaRole = "replica"
MysqldContainerName = "mysqld"
)
const (
CloneParamDonorHostName = "donor_hostname"
CloneParamDonorPort = "donor_port"
CloneParamExternal = "external"
)
const (
ReplicaRunConnect = "Yes"
ReplicaNotRun = "No"
ReplicaRunNotConnect = "Connecting"
CloneStatusNotStarted = "Not Started"
CloneStatusInProgress = "In Progress"
CloneStatusCompleted = "Completed"
CloneStatusFailed = "Failed"
)
type OperationPhase string
const (
PhaseInitializing = OperationPhase("initializing")
PhaseWaitRelayLog = OperationPhase("wait-relay-log")
PhaseRestoreInstance = OperationPhase("restoring-instance")
PhaseCompleted = OperationPhase("completed")
)
var AllOperationPhases = []OperationPhase{
PhaseInitializing,
PhaseWaitRelayLog,
PhaseRestoreInstance,
PhaseCompleted,
}
var (
// ErrConstraintsViolation is returned when the constraints violation occurs
ErrConstraintsViolation = errors.New("constraints violation occurs")
// ErrConstraintsRecovered is returned when the constrains recovered but once violated
ErrConstraintsRecovered = errors.New("constrains recovered but once violated")
// ErrCannotCompareGTIDs is returned if GTID comparison returns error
ErrCannotCompareGTIDs = errors.New("cannot compare gtids")
)
type MOCOEvent struct {
Type string
Reason string
Message string
}
func (e MOCOEvent) FillVariables(val ...interface{}) *MOCOEvent {
e.Message = fmt.Sprintf(e.Message, val...)
return &e
}
var (
EventInitializationSucceeded = MOCOEvent{
corev1.EventTypeNormal,
"Initialization Succeeded",
"Initialization phase finished successfully.",
}
EventInitializationFailed = MOCOEvent{
corev1.EventTypeWarning,
"Initialization Failed",
"Initialization phase failed. err=%s",
}
EventWaitingAllInstancesAvailable = MOCOEvent{
corev1.EventTypeNormal,
"Waiting All Instances Available",
"Waiting for all instances to become connected from MOCO. unavailable=%v",
}
EventViolationOccurred = MOCOEvent{
corev1.EventTypeWarning,
"Violation Occurred",
"Constraint violation occurred. Please resolve via manual operation. err=%v",
}
EventWatingRelayLogExecution = MOCOEvent{
corev1.EventTypeNormal,
"Waiting Relay Log Execution",
"Waiting relay log execution on replica instance(s).",
}
EventWaitingCloneFromExternal = MOCOEvent{
corev1.EventTypeNormal,
"Waiting External Clone",
"Waiting for the intermediate primary to clone from the external primary",
}
EventRestoringReplicaInstances = MOCOEvent{
corev1.EventTypeNormal,
"Restoring Replica Instance(s)",
"Restoring replica instance(s) by cloning with primary instance.",
}
EventPrimaryChanged = MOCOEvent{
corev1.EventTypeNormal,
"Primary Changed",
"Primary instance was changed from %s to %s because of failover or switchover.",
}
EventIntermediatePrimaryConfigured = MOCOEvent{
corev1.EventTypeNormal, "Intermediate Primary Configured",
"Intermediate primary instance was configured with host=%s",
}
EventIntermediatePrimaryUnset = MOCOEvent{
corev1.EventTypeNormal, "Intermediate Primary Unset",
"Intermediate primary instance was unset.",
}
EventClusteringCompletedSynced = MOCOEvent{
corev1.EventTypeNormal,
"Clustering Completed and Synced",
"Clustering are completed. All instances are synced.",
}
EventClusteringCompletedNotSynced = MOCOEvent{
corev1.EventTypeWarning,
"Clustering Completed but Not Synced",
"Clustering are completed. Some instance(s) are not synced. out_of_sync=%v",
}
)