Skip to content

Commit

Permalink
mysqlcluser,sidecar: fix restart mysql container cause replication fa…
Browse files Browse the repository at this point in the history
…il (#632)

mysqlcluser,sidecar: fix restart mysql container cause replication fail #626
  • Loading branch information
acekingke authored Aug 5, 2022
1 parent 8a512b5 commit fa20f80
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mysqlcluster/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
}
}

0 comments on commit fa20f80

Please sign in to comment.