From 537824df8ec784038c020ce6629efa32ed70f8c0 Mon Sep 17 00:00:00 2001 From: runkecheng <1131648942@qq.com> Date: Tue, 15 Mar 2022 17:57:16 +0800 Subject: [PATCH] *: Save Xenon's metadata to persistent storage. #406 --- mysqlcluster/container/backup.go | 1 + mysqlcluster/container/init_mysql.go | 1 + mysqlcluster/container/init_mysql_test.go | 1 + mysqlcluster/container/init_sidecar.go | 6 ++++++ mysqlcluster/container/init_sidecar_test.go | 12 ++++++++++-- mysqlcluster/container/mysql.go | 1 + mysqlcluster/container/mysql_test.go | 1 + mysqlcluster/container/xenon.go | 5 +++++ mysqlcluster/container/xenon_test.go | 5 +++++ sidecar/init.go | 4 ++++ sidecar/util.go | 2 ++ utils/constants.go | 19 +++++++++++-------- 12 files changed, 48 insertions(+), 10 deletions(-) diff --git a/mysqlcluster/container/backup.go b/mysqlcluster/container/backup.go index b42eae833..8a401a49c 100644 --- a/mysqlcluster/container/backup.go +++ b/mysqlcluster/container/backup.go @@ -134,6 +134,7 @@ func (c *backupSidecar) getVolumeMounts() []corev1.VolumeMount { { Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, + SubPath: utils.MysqlDataSubPath, }, { Name: utils.LogsVolumeName, diff --git a/mysqlcluster/container/init_mysql.go b/mysqlcluster/container/init_mysql.go index 54c8b5412..69b6bd944 100644 --- a/mysqlcluster/container/init_mysql.go +++ b/mysqlcluster/container/init_mysql.go @@ -115,6 +115,7 @@ func (c *initMysql) getVolumeMounts() []corev1.VolumeMount { { Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, + SubPath: utils.MysqlDataSubPath, }, { Name: utils.LogsVolumeName, diff --git a/mysqlcluster/container/init_mysql_test.go b/mysqlcluster/container/init_mysql_test.go index b855be1e9..6b51d9b4f 100644 --- a/mysqlcluster/container/init_mysql_test.go +++ b/mysqlcluster/container/init_mysql_test.go @@ -59,6 +59,7 @@ var ( { Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, + SubPath: utils.MysqlDataSubPath, }, { Name: utils.LogsVolumeName, diff --git a/mysqlcluster/container/init_sidecar.go b/mysqlcluster/container/init_sidecar.go index 9c16eb7f6..1efaf3ad1 100644 --- a/mysqlcluster/container/init_sidecar.go +++ b/mysqlcluster/container/init_sidecar.go @@ -202,6 +202,12 @@ func (c *initSidecar) getVolumeMounts() []corev1.VolumeMount { corev1.VolumeMount{ Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, + SubPath: utils.MysqlDataSubPath, + }, + corev1.VolumeMount{ + Name: utils.DataVolumeName, + MountPath: utils.XenonDataVolumeMountPath, + SubPath: utils.XenonMetaDataSubPath, }, ) } diff --git a/mysqlcluster/container/init_sidecar_test.go b/mysqlcluster/container/init_sidecar_test.go index 2ea421d49..6d8e3ae3f 100644 --- a/mysqlcluster/container/init_sidecar_test.go +++ b/mysqlcluster/container/init_sidecar_test.go @@ -455,10 +455,18 @@ func TestGetInitSidecarVolumeMounts(t *testing.T) { persistenceCase := EnsureContainer("init-sidecar", &testPersistenceCluster) persistenceVolumeMounts := make([]corev1.VolumeMount, 6, 7) copy(persistenceVolumeMounts, defaultInitsidecarVolumeMounts) - persistenceVolumeMounts = append(persistenceVolumeMounts, corev1.VolumeMount{ + persistenceVolumeMounts = append(persistenceVolumeMounts, + corev1.VolumeMount{ Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, - }) + SubPath: utils.MysqlDataSubPath, + }, + corev1.VolumeMount{ + Name: utils.DataVolumeName, + MountPath: utils.XenonDataVolumeMountPath, + SubPath: utils.XenonMetaDataSubPath, + }, + ) assert.Equal(t, persistenceVolumeMounts, persistenceCase.VolumeMounts) } } diff --git a/mysqlcluster/container/mysql.go b/mysqlcluster/container/mysql.go index d01f9f275..6d1cd80af 100644 --- a/mysqlcluster/container/mysql.go +++ b/mysqlcluster/container/mysql.go @@ -141,6 +141,7 @@ func (c *mysql) getVolumeMounts() []corev1.VolumeMount { { Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, + SubPath: utils.MysqlDataSubPath, }, { Name: utils.LogsVolumeName, diff --git a/mysqlcluster/container/mysql_test.go b/mysqlcluster/container/mysql_test.go index e502021a1..49dddb53a 100644 --- a/mysqlcluster/container/mysql_test.go +++ b/mysqlcluster/container/mysql_test.go @@ -147,6 +147,7 @@ func TestGetMysqlVolumeMounts(t *testing.T) { { Name: "data", MountPath: "/var/lib/mysql", + SubPath: "mysql", }, { Name: "logs", diff --git a/mysqlcluster/container/xenon.go b/mysqlcluster/container/xenon.go index 0c8c3fd13..272fc2d09 100644 --- a/mysqlcluster/container/xenon.go +++ b/mysqlcluster/container/xenon.go @@ -110,6 +110,11 @@ func (c *xenon) getVolumeMounts() []corev1.VolumeMount { Name: utils.ScriptsVolumeName, MountPath: utils.ScriptsVolumeMountPath, }, + { + Name: utils.DataVolumeName, + MountPath: utils.XenonDataVolumeMountPath, + SubPath: utils.XenonMetaDataSubPath, + }, { Name: utils.XenonVolumeName, MountPath: utils.XenonVolumeMountPath, diff --git a/mysqlcluster/container/xenon_test.go b/mysqlcluster/container/xenon_test.go index 6f5c081f7..055fc5964 100644 --- a/mysqlcluster/container/xenon_test.go +++ b/mysqlcluster/container/xenon_test.go @@ -130,6 +130,11 @@ func TestGetXenonVolumeMounts(t *testing.T) { Name: "scripts", MountPath: "/scripts", }, + { + Name: "data", + MountPath: "/var/lib/xenon", + SubPath: "xenon", + }, { Name: "xenon", MountPath: "/etc/xenon", diff --git a/sidecar/init.go b/sidecar/init.go index e41466dfd..e82c7abcf 100644 --- a/sidecar/init.go +++ b/sidecar/init.go @@ -133,6 +133,10 @@ func runInitCommand(cfg *Config) error { if err = os.Chown(dataPath, uid, gid); err != nil { return fmt.Errorf("failed to chown %s: %s", dataPath, err) } + // chown -R mysql:mysql /var/lib/xenon. + if err = os.Chown(xenonMetaDataPath, uid, gid); err != nil { + return fmt.Errorf("failed to chown %s: %s", xenonMetaDataPath, err) + } } // copy appropriate my.cnf from config-map to config mount. diff --git a/sidecar/util.go b/sidecar/util.go index cfbf140b6..ecdba2af2 100644 --- a/sidecar/util.go +++ b/sidecar/util.go @@ -46,6 +46,8 @@ var ( // dataPath is the mysql data path. dataPath = utils.DataVolumeMountPath + xenonMetaDataPath = utils.XenonDataVolumeMountPath + // // scriptsPath is the scripts path used for xenon. // scriptsPath = utils.ScriptsVolumeMountPath diff --git a/utils/constants.go b/utils/constants.go index 3c4883c68..8a02aa96c 100644 --- a/utils/constants.go +++ b/utils/constants.go @@ -99,14 +99,17 @@ const ( InitFileVolumeName = "init-mysql" // volumes mount path. - ConfVolumeMountPath = "/etc/mysql" - ConfMapVolumeMountPath = "/mnt/config-map" - LogsVolumeMountPath = "/var/log/mysql" - DataVolumeMountPath = "/var/lib/mysql" - SysVolumeMountPath = "/host-sys" - ScriptsVolumeMountPath = "/scripts" - XenonVolumeMountPath = "/etc/xenon" - InitFileVolumeMountPath = "/docker-entrypoint-initdb.d" + ConfVolumeMountPath = "/etc/mysql" + ConfMapVolumeMountPath = "/mnt/config-map" + LogsVolumeMountPath = "/var/log/mysql" + DataVolumeMountPath = "/var/lib/mysql" + XenonDataVolumeMountPath = "/var/lib/xenon" + SysVolumeMountPath = "/host-sys" + ScriptsVolumeMountPath = "/scripts" + XenonVolumeMountPath = "/etc/xenon" + InitFileVolumeMountPath = "/docker-entrypoint-initdb.d" + MysqlDataSubPath = "mysql" + XenonMetaDataSubPath = "xenon" // Volume timezone name. SysLocalTimeZone = "localtime"