-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathinit_mysql.go
141 lines (120 loc) · 3.68 KB
/
init_mysql.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
/*
Copyright 2021 RadonDB.
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 container
import (
corev1 "k8s.io/api/core/v1"
"github.com/radondb/radondb-mysql-kubernetes/mysqlcluster"
"github.com/radondb/radondb-mysql-kubernetes/utils"
)
// initMysql used for init-mysql container.
type initMysql struct {
*mysqlcluster.MysqlCluster
// The name of the init-mysql container.
name string
}
// getName get the container name.
func (c *initMysql) getName() string {
return c.name
}
// getImage get the container image.
func (c *initMysql) getImage() string {
img := c.Spec.MysqlOpts.Image
return img
}
// getCommand get the container command.
func (c *initMysql) getCommand() []string {
// Because initialize mysql contain error, so do it in commands.
pluginscript := "if test -f /docker-entrypoint-initdb.d/plugin.sh; then /docker-entrypoint-initdb.d/plugin.sh; fi ;"
clonescript := "if test -f " + utils.RadonDBBinDir + "/clone.sh;" + " then " + utils.RadonDBBinDir + "/clone.sh;fi;"
updgradescript := "if test -f " + utils.RadonDBBinDir + "/upgrade.sh; then " + utils.RadonDBBinDir + "/upgrade.sh;fi;"
restorescript := "if test -f " + utils.RadonDBBinDir + "/restore.sh; then " + utils.RadonDBBinDir + "/restore.sh; fi ;"
return []string{"bash", "-c", "/docker-entrypoint.sh mysqld;" + pluginscript + clonescript + updgradescript + restorescript}
}
// getEnvVars get the container env.
func (c *initMysql) getEnvVars() []corev1.EnvVar {
envs := []corev1.EnvVar{
{
Name: "MYSQL_ALLOW_EMPTY_PASSWORD",
Value: "yes",
},
{
Name: "MYSQL_ROOT_HOST",
Value: c.Spec.MysqlOpts.RootHost,
},
{
Name: "MYSQL_INIT_ONLY",
Value: "1",
},
}
sctName := c.GetNameForResource(utils.Secret)
envs = append(
envs,
getEnvVarFromSecret(sctName, "MYSQL_ROOT_PASSWORD", "root-password", false),
)
if c.Spec.MysqlOpts.InitTokuDB {
envs = append(envs, corev1.EnvVar{
Name: "INIT_TOKUDB",
Value: "1",
})
}
return envs
}
// getLifecycle get the container lifecycle.
func (c *initMysql) getLifecycle() *corev1.Lifecycle {
return nil
}
// getResources get the container resources.
func (c *initMysql) getResources() corev1.ResourceRequirements {
return c.Spec.MysqlOpts.Resources
}
// getPorts get the container ports.
func (c *initMysql) getPorts() []corev1.ContainerPort {
return nil
}
// getLivenessProbe get the container livenessProbe.
func (c *initMysql) getLivenessProbe() *corev1.Probe {
return nil
}
// getReadinessProbe get the container readinessProbe.
func (c *initMysql) getReadinessProbe() *corev1.Probe {
return nil
}
// getVolumeMounts get the container volumeMounts.
func (c *initMysql) getVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: utils.MysqlConfVolumeName,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
},
{
Name: utils.LogsVolumeName,
MountPath: utils.LogsVolumeMountPath,
},
{
Name: utils.InitFileVolumeName,
MountPath: utils.InitFileVolumeMountPath,
},
{
Name: utils.SysLocalTimeZone,
MountPath: utils.SysLocalTimeZoneMountPath,
},
{
Name: utils.MySQLcheckerVolumeName,
MountPath: utils.RadonDBBinDir,
},
}
}