Skip to content

Commit fa20f80

Browse files
authored
mysqlcluser,sidecar: fix restart mysql container cause replication fail (#632)
mysqlcluser,sidecar: fix restart mysql container cause replication fail #626
1 parent 8a512b5 commit fa20f80

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

mysqlcluster/container/container.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,29 @@ type container interface {
3939
getVolumeMounts() []corev1.VolumeMount
4040
}
4141

42+
func getStartupProbe(name string) *corev1.Probe {
43+
if name == utils.ContainerMysqlName {
44+
return &corev1.Probe{
45+
Handler: corev1.Handler{
46+
Exec: &corev1.ExecAction{
47+
Command: []string{
48+
"sh",
49+
"-c",
50+
`if test $(mysql -uroot -h127.0.0.1 -NB -e "SELECT 1") -eq 1; then sed -i "/^RESET SLAVE ALL;/d" /etc/mysql/conf.d/init.sql; fi`,
51+
},
52+
},
53+
},
54+
InitialDelaySeconds: 10,
55+
TimeoutSeconds: 5,
56+
PeriodSeconds: 10,
57+
SuccessThreshold: 1,
58+
FailureThreshold: 5,
59+
}
60+
} else {
61+
return nil
62+
}
63+
}
64+
4265
// EnsureContainer ensure a container by the giving name.
4366
func EnsureContainer(name string, c *mysqlcluster.MysqlCluster) corev1.Container {
4467
var ctr container
@@ -72,6 +95,7 @@ func EnsureContainer(name string, c *mysqlcluster.MysqlCluster) corev1.Container
7295
Ports: ctr.getPorts(),
7396
LivenessProbe: ctr.getLivenessProbe(),
7497
ReadinessProbe: ctr.getReadinessProbe(),
98+
StartupProbe: getStartupProbe(name),
7599
VolumeMounts: ctr.getVolumeMounts(),
76100
}
77101
}

0 commit comments

Comments
 (0)