Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: Save Xenon's metadata to config map. #447

Merged
merged 3 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 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 All @@ -124,6 +125,7 @@ func (r *MysqlClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
clustersyncer.NewFollowerSVCSyncer(r.Client, instance),
clustersyncer.NewStatefulSetSyncer(r.Client, instance, cmRev, sctRev, r.SQLRunnerFactory, r.XenonExecutor),
clustersyncer.NewPDBSyncer(r.Client, instance),
clustersyncer.NewXenonCMSyncer(r.Client, instance),
}

if instance.Spec.MetricsOpts.Enabled {
Expand Down
5 changes: 2 additions & 3 deletions mysqlcluster/container/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,12 @@ func (c *backupSidecar) getReadinessProbe() *corev1.Probe {
func (c *backupSidecar) getVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
Name: utils.MysqlConfVolumeName,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
SubPath: utils.MysqlDataSubPath,
},
{
Name: utils.LogsVolumeName,
Expand Down
5 changes: 2 additions & 3 deletions mysqlcluster/container/init_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,12 @@ func (c *initMysql) getReadinessProbe() *corev1.Probe {
func (c *initMysql) getVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
Name: utils.MysqlConfVolumeName,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
SubPath: utils.MysqlDataSubPath,
},
{
Name: utils.LogsVolumeName,
Expand Down
5 changes: 2 additions & 3 deletions mysqlcluster/container/init_mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ var (
}
initMysqlVolumeMounts = []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
Name: utils.MysqlConfVolumeName,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
SubPath: utils.MysqlDataSubPath,
},
{
Name: utils.LogsVolumeName,
Expand Down
26 changes: 14 additions & 12 deletions mysqlcluster/container/init_sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,28 @@ func (c *initSidecar) getReadinessProbe() *corev1.Probe {
func (c *initSidecar) getVolumeMounts() []corev1.VolumeMount {
volumeMounts := []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
Name: utils.MysqlConfVolumeName,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.ConfMapVolumeName,
MountPath: utils.ConfMapVolumeMountPath,
Name: utils.MysqlCMVolumeName,
MountPath: utils.MysqlCMVolumeMountPath,
},
{
Name: utils.XenonCMVolumeName,
MountPath: utils.XenonCMVolumeMountPath,
},
{
Name: utils.XenonMetaVolumeName,
MountPath: utils.XenonMetaVolumeMountPath,
},
{
Name: utils.ScriptsVolumeName,
MountPath: utils.ScriptsVolumeMountPath,
},
{
Name: utils.XenonVolumeName,
MountPath: utils.XenonVolumeMountPath,
Name: utils.XenonConfVolumeName,
MountPath: utils.XenonConfVolumeMountPath,
},
{
Name: utils.InitFileVolumeName,
Expand All @@ -202,12 +210,6 @@ 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.XenonDataSubPath,
},
)
}
Expand Down
40 changes: 20 additions & 20 deletions mysqlcluster/container/init_sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,20 +272,28 @@ var (
}
defaultInitsidecarVolumeMounts = []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
Name: utils.MysqlConfVolumeName,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.ConfMapVolumeName,
MountPath: utils.ConfMapVolumeMountPath,
Name: utils.MysqlCMVolumeName,
MountPath: utils.MysqlCMVolumeMountPath,
},
{
Name: utils.XenonCMVolumeName,
MountPath: utils.XenonCMVolumeMountPath,
},
{
Name: utils.XenonMetaVolumeName,
MountPath: utils.XenonMetaVolumeMountPath,
},
{
Name: utils.ScriptsVolumeName,
MountPath: utils.ScriptsVolumeMountPath,
},
{
Name: utils.XenonVolumeName,
MountPath: utils.XenonVolumeMountPath,
Name: utils.XenonConfVolumeName,
MountPath: utils.XenonConfVolumeMountPath,
},
{
Name: utils.InitFileVolumeName,
Expand Down Expand Up @@ -437,7 +445,7 @@ func TestGetInitSidecarVolumeMounts(t *testing.T) {
MysqlCluster: &testToKuDBMysqlCluster,
}
tokudbCase := EnsureContainer("init-sidecar", &testTokuDBCluster)
tokuDBVolumeMounts := make([]corev1.VolumeMount, 6, 7)
tokuDBVolumeMounts := make([]corev1.VolumeMount, 8, 9)
copy(tokuDBVolumeMounts, defaultInitsidecarVolumeMounts)
tokuDBVolumeMounts = append(tokuDBVolumeMounts, corev1.VolumeMount{
Name: utils.SysVolumeName,
Expand All @@ -453,20 +461,12 @@ func TestGetInitSidecarVolumeMounts(t *testing.T) {
MysqlCluster: &testPersistenceMysqlCluster,
}
persistenceCase := EnsureContainer("init-sidecar", &testPersistenceCluster)
persistenceVolumeMounts := make([]corev1.VolumeMount, 6, 7)
persistenceVolumeMounts := make([]corev1.VolumeMount, 8, 9)
copy(persistenceVolumeMounts, defaultInitsidecarVolumeMounts)
persistenceVolumeMounts = append(persistenceVolumeMounts,
corev1.VolumeMount{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
SubPath: utils.MysqlDataSubPath,
},
corev1.VolumeMount{
Name: utils.DataVolumeName,
MountPath: utils.XenonDataVolumeMountPath,
SubPath: utils.XenonDataSubPath,
},
)
persistenceVolumeMounts = append(persistenceVolumeMounts, corev1.VolumeMount{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
})
assert.Equal(t, persistenceVolumeMounts, persistenceCase.VolumeMounts)
}
}
5 changes: 2 additions & 3 deletions mysqlcluster/container/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,12 @@ func (c *mysql) getReadinessProbe() *corev1.Probe {
func (c *mysql) getVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: utils.ConfVolumeName,
MountPath: utils.ConfVolumeMountPath,
Name: utils.MysqlConfVolumeName,
MountPath: utils.MysqlConfVolumeMountPath,
},
{
Name: utils.DataVolumeName,
MountPath: utils.DataVolumeMountPath,
SubPath: utils.MysqlDataSubPath,
},
{
Name: utils.LogsVolumeName,
Expand Down
3 changes: 1 addition & 2 deletions mysqlcluster/container/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,12 @@ func TestGetMysqlReadinessProbe(t *testing.T) {
func TestGetMysqlVolumeMounts(t *testing.T) {
volumeMounts := []corev1.VolumeMount{
{
Name: "conf",
Name: "mysql-conf",
MountPath: "/etc/mysql",
},
{
Name: "data",
MountPath: "/var/lib/mysql",
SubPath: "mysql",
},
{
Name: "logs",
Expand Down
9 changes: 4 additions & 5 deletions mysqlcluster/container/xenon.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ func (c *xenon) getVolumeMounts() []corev1.VolumeMount {
MountPath: utils.ScriptsVolumeMountPath,
},
{
Name: utils.DataVolumeName,
MountPath: utils.XenonDataVolumeMountPath,
SubPath: utils.XenonDataSubPath,
Name: utils.XenonConfVolumeName,
MountPath: utils.XenonConfVolumeMountPath,
},
{
Name: utils.XenonVolumeName,
MountPath: utils.XenonVolumeMountPath,
Name: utils.XenonMetaVolumeName,
runkecheng marked this conversation as resolved.
Show resolved Hide resolved
MountPath: utils.XenonMetaVolumeMountPath,
},
{
Name: utils.SysLocalTimeZone,
Expand Down
9 changes: 4 additions & 5 deletions mysqlcluster/container/xenon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,12 @@ func TestGetXenonVolumeMounts(t *testing.T) {
MountPath: "/scripts",
},
{
Name: "data",
MountPath: "/var/lib/xenon",
SubPath: "xenon",
Name: "xenon-conf",
MountPath: "/etc/xenon",
},
{
runkecheng marked this conversation as resolved.
Show resolved Hide resolved
Name: "xenon",
MountPath: "/etc/xenon",
Name: "xenon-meta",
MountPath: "/var/lib/xenon",
},
{
Name: utils.SysLocalTimeZone,
Expand Down
24 changes: 21 additions & 3 deletions mysqlcluster/mysqlcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (c *MysqlCluster) EnsureVolumes() []corev1.Volume {

volumes = append(volumes,
corev1.Volume{
Name: utils.ConfVolumeName,
Name: utils.MysqlConfVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
Expand All @@ -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 All @@ -214,14 +214,30 @@ func (c *MysqlCluster) EnsureVolumes() []corev1.Volume {
},
},
},
corev1.Volume{
Name: utils.XenonCMVolumeName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: c.GetNameForResource(utils.XenonMetaData),
},
},
},
},
corev1.Volume{
Name: utils.XenonMetaVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
corev1.Volume{
Name: utils.ScriptsVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
corev1.Volume{
Name: utils.XenonVolumeName,
Name: utils.XenonConfVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
Expand Down Expand Up @@ -294,6 +310,8 @@ func (c *MysqlCluster) GetNameForResource(name utils.ResourceName) string {
return fmt.Sprintf("%s-metrics", c.Name)
case utils.Secret:
return fmt.Sprintf("%s-secret", c.Name)
case utils.XenonMetaData:
return fmt.Sprintf("%s-xenon", c.Name)
default:
return c.Name
}
Expand Down
22 changes: 19 additions & 3 deletions mysqlcluster/mysqlcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestGetPodHostName(t *testing.T) {
func TestEnsureVolumes(t *testing.T) {
volume := []corev1.Volume{
{
Name: utils.ConfVolumeName,
Name: utils.MysqlConfVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
Expand All @@ -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 All @@ -266,14 +266,30 @@ func TestEnsureVolumes(t *testing.T) {
},
},
},
{
Name: utils.XenonCMVolumeName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "sample-xenon",
},
},
},
},
{
Name: utils.XenonMetaVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
{
Name: utils.ScriptsVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
{
Name: utils.XenonVolumeName,
Name: utils.XenonConfVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
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
Loading