Skip to content

Commit

Permalink
Fix mariadb config file permissions and restart pod on config change
Browse files Browse the repository at this point in the history
Mariadb is using default conf as the conf file is not readable by the mysql user.
Also pass the config hash as an env to the pod to ensure it is recreated when
the config changes.
  • Loading branch information
olliewalsh committed Feb 20, 2023
1 parent 2ff4f7b commit 23f580d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions controllers/mariadb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ func (r *MariaDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct

op, err = controllerutil.CreateOrPatch(ctx, r.Client, pod, func() error {
pod.Spec.Containers[0].Image = instance.Spec.ContainerImage
pod.Spec.Containers[0].Env = []corev1.EnvVar{
{
Name: "KOLLA_CONFIG_STRATEGY",
Value: "COPY_ALWAYS",
},
{
Name: "CONFIG_HASH",
Value: configHash,
},
}
err := controllerutil.SetControllerReference(instance, pod, r.Scheme)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion templates/mariadb/bin/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"source": "/var/lib/config-data/galera.cnf",
"dest": "/etc/my.cnf.d/galera.cnf",
"owner": "root",
"owner": "mysql",
"perm": "0600"
}
]
Expand Down
2 changes: 1 addition & 1 deletion templates/mariadb/bin/galera.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ key_buffer_size = 16M

[mysqld]
basedir = /usr
bind-address = 127.0.0.1
bind-address = *
datadir = /var/lib/mysql
expire_logs_days = 10
innodb_file_per_table = ON
Expand Down
2 changes: 1 addition & 1 deletion templates/mariadb/bin/init_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"source": "/var/lib/config-data/galera.cnf",
"dest": "/etc/my.cnf.d/galera.cnf",
"owner": "root",
"owner": "mysql",
"perm": "0600"
},
{
Expand Down

0 comments on commit 23f580d

Please sign in to comment.