From fa20f8005520e4f3f80b7e869c998f167f7b516a Mon Sep 17 00:00:00 2001 From: aceking Date: Fri, 5 Aug 2022 15:38:07 +0800 Subject: [PATCH] mysqlcluser,sidecar: fix restart mysql container cause replication fail (#632) mysqlcluser,sidecar: fix restart mysql container cause replication fail #626 --- mysqlcluster/container/container.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mysqlcluster/container/container.go b/mysqlcluster/container/container.go index c940a8ff..59e94615 100644 --- a/mysqlcluster/container/container.go +++ b/mysqlcluster/container/container.go @@ -39,6 +39,29 @@ type container interface { getVolumeMounts() []corev1.VolumeMount } +func getStartupProbe(name string) *corev1.Probe { + if name == utils.ContainerMysqlName { + return &corev1.Probe{ + Handler: corev1.Handler{ + Exec: &corev1.ExecAction{ + Command: []string{ + "sh", + "-c", + `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`, + }, + }, + }, + InitialDelaySeconds: 10, + TimeoutSeconds: 5, + PeriodSeconds: 10, + SuccessThreshold: 1, + FailureThreshold: 5, + } + } else { + return nil + } +} + // EnsureContainer ensure a container by the giving name. func EnsureContainer(name string, c *mysqlcluster.MysqlCluster) corev1.Container { var ctr container @@ -72,6 +95,7 @@ func EnsureContainer(name string, c *mysqlcluster.MysqlCluster) corev1.Container Ports: ctr.getPorts(), LivenessProbe: ctr.getLivenessProbe(), ReadinessProbe: ctr.getReadinessProbe(), + StartupProbe: getStartupProbe(name), VolumeMounts: ctr.getVolumeMounts(), } }