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

Fix mariadb config file permissions and restart pod on config change #78

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
24 changes: 17 additions & 7 deletions controllers/mariadb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ type MariaDBReconciler struct {

// +kubebuilder:rbac:groups=mariadb.openstack.org,resources=mariadbs,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=mariadb.openstack.org,resources=mariadbs/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=mariadb.openstack.org,resources=mariadbs/finalizers,verbs=update
// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;delete;
// +kubebuilder:rbac:groups=core,resources=endpoints,verbs=get;list;watch;create;update;delete;
// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;delete;
// +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;create;update;delete;
// +kubebuilder:rbac:groups=core,resources=persistentvolumeclaims,verbs=get;list;watch;create;update;delete;
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;update;delete;
// +kubebuilder:rbac:groups=mariadb.openstack.org,resources=mariadbs/finalizers,verbs=update;patch
// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;delete;patch
// +kubebuilder:rbac:groups=core,resources=endpoints,verbs=get;list;watch;create;update;delete;patch
// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;delete;patch
// +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;create;update;delete;patch
// +kubebuilder:rbac:groups=core,resources=persistentvolumeclaims,verbs=get;list;watch;create;update;delete;patch
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;update;delete;patch

// Reconcile reconcile mariadb API requests
func (r *MariaDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
Expand Down 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",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dciabrin is this also an issue for the galera controller?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the galera pod is started as root as well and mysqld switches to user mysql, so the owner of this file is still root.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up, in TripleO all files under /etc/my.cnf.d are owned by root, and this config is also owned by root with perms 644.
I think this is what we want here as well, and I did the same for the galera CR.

"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