Skip to content

Commit

Permalink
Merge pull request radondb#383 from acekingke/DebugMode
Browse files Browse the repository at this point in the history
mysqlcluster: Debug Mode for Pod radondb#375
  • Loading branch information
andyli029 authored Mar 3, 2022
2 parents 21d397a + 0e6a1d0 commit 49384da
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
15 changes: 15 additions & 0 deletions docs/en-us/DebugMode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Debug Mode
When you want avoid the restart-on-fail loop for mysql container, You should use Debug Mode.
it just use create a empty file `/var/lib/mysql/sleep-forever`
for example:
```bash
kubectl exec -it sample-mysql-0 -c mysql -- sh -c 'touch /var/lib/mysql/sleep-forever'
```
it make pod sample-mysql-0's mysql container will never restart when mysqld is crashed.

# Remove Debug Mode

```bash
kubectl exec -it sample-mysql-0 -c mysql -- sh -c 'rm /var/lib/mysql/sleep-forever'
```
restart the container
18 changes: 15 additions & 3 deletions mysqlcluster/container/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ func (c *mysql) getImage() string {

// getCommand get the container command.
func (c *mysql) getCommand() []string {
return nil
return []string{
"sh",
"-c",
"while [ -f '/var/lib/mysql/sleep-forever' ] ;do sleep 2 ; done; /docker-entrypoint.sh mysqld",
}
}

// getEnvVars get the container env.
Expand Down Expand Up @@ -88,7 +92,15 @@ func (c *mysql) getLivenessProbe() *corev1.Probe {
return &corev1.Probe{
Handler: corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{"pgrep", "mysqld"},

/* /var/lib/mysql/sleep-forever is used to prevent mysql's container from exiting.
kubectl exec -it sample-mysql-0 -c mysql -- sh -c 'touch /var/lib/mysql/sleep-forever'
*/
Command: []string{
"sh",
"-c",
"if [ -f '/var/lib/mysql/sleep-forever' ] ;then exit 0 ; fi; pgrep mysqld",
},
},
},
InitialDelaySeconds: 30,
Expand All @@ -107,7 +119,7 @@ func (c *mysql) getReadinessProbe() *corev1.Probe {
Command: []string{
"sh",
"-c",
fmt.Sprintf(`test $(mysql --defaults-file=%s -NB -e "SELECT 1") -eq 1`, utils.ConfClientPath),
fmt.Sprintf(`if [ -f '/var/lib/mysql/sleep-forever' ] ;then exit 0 ; fi; test $(mysql --defaults-file=%s -NB -e "SELECT 1") -eq 1`, utils.ConfClientPath),
},
},
},
Expand Down
7 changes: 4 additions & 3 deletions mysqlcluster/container/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func TestGetMysqlImage(t *testing.T) {
}

func TestGetMysqlCommand(t *testing.T) {
assert.Nil(t, mysqlCase.Command)
assert.Equal(t, mysqlCase.Command,
[]string{"sh", "-c", "while [ -f '/var/lib/mysql/sleep-forever' ] ;do sleep 2 ; done; /docker-entrypoint.sh mysqld"})
}

func TestGetMysqlEnvVar(t *testing.T) {
Expand Down Expand Up @@ -109,7 +110,7 @@ func TestGetMysqlLivenessProbe(t *testing.T) {
livenessProbe := &corev1.Probe{
Handler: corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{"pgrep", "mysqld"},
Command: []string{"sh", "-c", "if [ -f '/var/lib/mysql/sleep-forever' ] ;then exit 0 ; fi; pgrep mysqld"},
},
},
InitialDelaySeconds: 30,
Expand All @@ -125,7 +126,7 @@ func TestGetMysqlReadinessProbe(t *testing.T) {
readinessProbe := &corev1.Probe{
Handler: corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{"sh", "-c", `test $(mysql --defaults-file=/etc/mysql/client.conf -NB -e "SELECT 1") -eq 1`},
Command: []string{"sh", "-c", `if [ -f '/var/lib/mysql/sleep-forever' ] ;then exit 0 ; fi; test $(mysql --defaults-file=/etc/mysql/client.conf -NB -e "SELECT 1") -eq 1`},
},
},
InitialDelaySeconds: 10,
Expand Down

0 comments on commit 49384da

Please sign in to comment.