Skip to content

Commit

Permalink
*: Rename mysql config and volume.
Browse files Browse the repository at this point in the history
  • Loading branch information
runkecheng committed Apr 13, 2022
1 parent 3375b1c commit 42e595f
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 47 deletions.
7 changes: 4 additions & 3 deletions controllers/mysqlcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func (r *MysqlClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
}
}()

configMapSyncer := clustersyncer.NewConfigMapSyncer(r.Client, instance)
if err = syncer.Sync(ctx, configMapSyncer, r.Recorder); err != nil {
mysqlCMSyncer := clustersyncer.NewMysqlCMSyncer(r.Client, instance)
if err = syncer.Sync(ctx, mysqlCMSyncer, r.Recorder); err != nil {
return ctrl.Result{}, err
}

Expand All @@ -109,7 +109,8 @@ func (r *MysqlClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{}, err
}

cmRev := configMapSyncer.Object().(*corev1.ConfigMap).ResourceVersion
// Todo: modify mysql cm will trigger rolling update but it will not be applied.
cmRev := mysqlCMSyncer.Object().(*corev1.ConfigMap).ResourceVersion
sctRev := secretSyncer.Object().(*corev1.Secret).ResourceVersion

r.XenonExecutor.SetRootPassword(instance.Spec.MysqlOpts.RootPassword)
Expand Down
2 changes: 1 addition & 1 deletion mysqlcluster/container/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (c *backupSidecar) getVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.DataVolumeName,
Expand Down
2 changes: 1 addition & 1 deletion mysqlcluster/container/init_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (c *initMysql) getVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.DataVolumeName,
Expand Down
2 changes: 1 addition & 1 deletion mysqlcluster/container/init_mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (
initMysqlVolumeMounts = []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.DataVolumeName,
Expand Down
6 changes: 3 additions & 3 deletions mysqlcluster/container/init_sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ func (c *initSidecar) getVolumeMounts() []corev1.VolumeMount {
volumeMounts := []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.ConfMapVolumeName,
MountPath: utils.ConfMapVolumeMountPath,
Name: utils.MysqlCMVolumeName,
MountPath: utils.MysqlCMVolumeMountPath,
},
{
Name: utils.ScriptsVolumeName,
Expand Down
6 changes: 3 additions & 3 deletions mysqlcluster/container/init_sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ var (
defaultInitsidecarVolumeMounts = []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.ConfMapVolumeName,
MountPath: utils.ConfMapVolumeMountPath,
Name: utils.MysqlCMVolumeName,
MountPath: utils.MysqlCMVolumeMountPath,
},
{
Name: utils.ScriptsVolumeName,
Expand Down
2 changes: 1 addition & 1 deletion mysqlcluster/container/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (c *mysql) getVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.DataVolumeName,
Expand Down
2 changes: 1 addition & 1 deletion mysqlcluster/container/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestGetMysqlReadinessProbe(t *testing.T) {
func TestGetMysqlVolumeMounts(t *testing.T) {
volumeMounts := []corev1.VolumeMount{
{
Name: "conf",
Name: "mysql-conf",
MountPath: "/etc/mysql",
},
{
Expand Down
2 changes: 1 addition & 1 deletion mysqlcluster/mysqlcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (c *MysqlCluster) EnsureVolumes() []corev1.Volume {
},
},
corev1.Volume{
Name: utils.ConfMapVolumeName,
Name: utils.MysqlCMVolumeName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Expand Down
2 changes: 1 addition & 1 deletion mysqlcluster/mysqlcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func TestEnsureVolumes(t *testing.T) {
},
},
{
Name: utils.ConfMapVolumeName,
Name: utils.MysqlCMVolumeName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"github.com/radondb/radondb-mysql-kubernetes/utils"
)

// NewConfigMapSyncer returns configmap syncer.
func NewConfigMapSyncer(cli client.Client, c *mysqlcluster.MysqlCluster) syncer.Interface {
// NewMysqlCMSyncer returns mysql configmap syncer.
func NewMysqlCMSyncer(cli client.Client, c *mysqlcluster.MysqlCluster) syncer.Interface {
cm := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand Down
12 changes: 6 additions & 6 deletions sidecar/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,19 +533,19 @@ func (cfg *Config) executeS3Restore(path string) error {
}
}
// Xtrabackup prepare and apply-log-only.
cmd := exec.Command(xtrabackupCommand, "--defaults-file="+utils.ConfVolumeMountPath+"/my.cnf", "--prepare", "--apply-log-only", "--target-dir=/root/backup")
cmd := exec.Command(xtrabackupCommand, "--defaults-file="+utils.MysqlConfVolumeMountPath+"/my.cnf", "--prepare", "--apply-log-only", "--target-dir=/root/backup")
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to xtrabackup prepare and apply-log-only : %s", err)
}
// Xtrabackup prepare.
cmd = exec.Command(xtrabackupCommand, "--defaults-file="+utils.ConfVolumeMountPath+"/my.cnf", "--prepare", "--target-dir=/root/backup")
cmd = exec.Command(xtrabackupCommand, "--defaults-file="+utils.MysqlConfVolumeMountPath+"/my.cnf", "--prepare", "--target-dir=/root/backup")
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to xtrabackup prepare : %s", err)
}
// Xtrabackup copy-back to /var/lib/mysql.
cmd = exec.Command(xtrabackupCommand, "--defaults-file="+utils.ConfVolumeMountPath+"/my.cnf", "--datadir="+utils.DataVolumeMountPath, "--copy-back", "--copy-back", "--target-dir=/root/backup")
cmd = exec.Command(xtrabackupCommand, "--defaults-file="+utils.MysqlConfVolumeMountPath+"/my.cnf", "--datadir="+utils.DataVolumeMountPath, "--copy-back", "--copy-back", "--target-dir=/root/backup")
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to xtrabackup copy-back : %s", err)
Expand Down Expand Up @@ -577,13 +577,13 @@ func (cfg *Config) executeCloneRestore() error {
os.RemoveAll(path.Join([]string{utils.DataVolumeMountPath, d.Name()}...))
}
// Xtrabackup prepare and apply-log-only.
cmd := exec.Command(xtrabackupCommand, "--defaults-file="+utils.ConfVolumeMountPath+"/my.cnf", "--use-memory=3072M", "--prepare", "--apply-log-only", "--target-dir=/backup/"+cfg.XRestoreFrom)
cmd := exec.Command(xtrabackupCommand, "--defaults-file="+utils.MysqlConfVolumeMountPath+"/my.cnf", "--use-memory=3072M", "--prepare", "--apply-log-only", "--target-dir=/backup/"+cfg.XRestoreFrom)
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to xtrabackup prepare apply-log-only : %s", err)
}
// Xtrabackup Prepare.
cmd = exec.Command(xtrabackupCommand, "--defaults-file="+utils.ConfVolumeMountPath+"/my.cnf", "--use-memory=3072M", "--prepare", "--target-dir=/backup/"+cfg.XRestoreFrom)
cmd = exec.Command(xtrabackupCommand, "--defaults-file="+utils.MysqlConfVolumeMountPath+"/my.cnf", "--use-memory=3072M", "--prepare", "--target-dir=/backup/"+cfg.XRestoreFrom)
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to xtrabackup prepare : %s", err)
Expand All @@ -595,7 +595,7 @@ func (cfg *Config) executeCloneRestore() error {
}
log.Info("get master gtid purged :", "gtid purged", cfg.GtidPurged)
// Xtrabackup copy-back.
cmd = exec.Command(xtrabackupCommand, "--defaults-file="+utils.ConfVolumeMountPath+"/my.cnf", "--use-memory=3072M", "--datadir="+utils.DataVolumeMountPath, "--copy-back", "--target-dir=/backup/"+cfg.XRestoreFrom)
cmd = exec.Command(xtrabackupCommand, "--defaults-file="+utils.MysqlConfVolumeMountPath+"/my.cnf", "--use-memory=3072M", "--datadir="+utils.DataVolumeMountPath, "--copy-back", "--target-dir=/backup/"+cfg.XRestoreFrom)
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to xtrabackup copy-back : %s", err)
Expand Down
4 changes: 2 additions & 2 deletions sidecar/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func runInitCommand(cfg *Config) error {
}

// copy appropriate my.cnf from config-map to config mount.
if err = copyFile(path.Join(configMapPath, "my.cnf"), path.Join(configPath, "my.cnf")); err != nil {
if err = copyFile(path.Join(mysqlCMPath, "my.cnf"), path.Join(mysqlConfigPath, "my.cnf")); err != nil {
return fmt.Errorf("failed to copy my.cnf: %s", err)
}

Expand Down Expand Up @@ -266,7 +266,7 @@ func RunRequestBackup(cfg *Config, host string) error {

// Save plugin.cnf and extra.cnf to specified path.
func saveCnfTo(targetPath string, extraCnf *ini.File) error {
if err := copyFile(path.Join(configMapPath, utils.PluginConfigs), path.Join(targetPath, utils.PluginConfigs)); err != nil {
if err := copyFile(path.Join(mysqlCMPath, utils.PluginConfigs), path.Join(targetPath, utils.PluginConfigs)); err != nil {
return fmt.Errorf("failed to copy plugin.cnf: %s", err)
}
if err := extraCnf.SaveTo(path.Join(targetPath, "extra.cnf")); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions sidecar/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ var (
// MysqlServerIDOffset represents the offset with which all server ids are shifted from 0
mysqlServerIDOffset = 100

// configPath is the mysql configs path.
configPath = utils.ConfVolumeMountPath
// mysqlConfigPath is the mysql configs path.
mysqlConfigPath = utils.MysqlConfVolumeMountPath

// clientConfPath is the client.cnf path.
clientConfPath = utils.ConfClientPath

// extraConfPath is the mysql extra configs path.
extraConfPath = utils.ConfVolumeMountPath + "/conf.d"
extraConfPath = utils.MysqlConfVolumeMountPath + "/conf.d"

// configMapPath is the mounted configmap.
configMapPath = utils.ConfMapVolumeMountPath
// mysqlCMPath is the mounted configmap.
mysqlCMPath = utils.MysqlCMVolumeMountPath

// dataPath is the mysql data path.
dataPath = utils.DataVolumeMountPath
Expand Down
33 changes: 17 additions & 16 deletions utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,25 @@ const (
BackupUser = "sys_backup"

// volumes names.
ConfVolumeName = "conf"
ConfMapVolumeName = "config-map"
LogsVolumeName = "logs"
DataVolumeName = "data"
SysVolumeName = "host-sys"
ScriptsVolumeName = "scripts"
XenonVolumeName = "xenon"
InitFileVolumeName = "init-mysql"
ConfVolumeName = "mysql-conf"
MysqlCMVolumeName = "mysql-cm"
LogsVolumeName = "logs"
DataVolumeName = "data"
SysVolumeName = "host-sys"
ScriptsVolumeName = "scripts"
XenonVolumeName = "xenon"
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"
MysqlConfVolumeMountPath = "/etc/mysql"
MysqlCMVolumeMountPath = "/mnt/mysql-cm"
XenonMetaVolumeMountPath = "/var/lib/xenon"
LogsVolumeMountPath = "/var/log/mysql"
DataVolumeMountPath = "/var/lib/mysql"
SysVolumeMountPath = "/host-sys"
ScriptsVolumeMountPath = "/scripts"
XenonVolumeMountPath = "/etc/xenon"
InitFileVolumeMountPath = "/docker-entrypoint-initdb.d"

// Volume timezone name.
SysLocalTimeZone = "localtime"
Expand Down

0 comments on commit 42e595f

Please sign in to comment.