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

*: Support user management through crd. #175 #218

Closed
wants to merge 6 commits into from

Conversation

runkecheng
Copy link
Collaborator

@runkecheng runkecheng commented Sep 10, 2021

What type of PR is this?

/enhancement

Which issue(s) this PR fixes?

Fixes #175 #198 #189 #220

What this PR does?

Summary:

  • Support adding and deleting users
  • Support for user authorization (databases, tables)
  • Support password modification
  • Support modifying hosts
  • Support automatic installation of msyqluser crd
  • Add the verification of user parameters.

Special notes for your reviewer?

The main logic is in this commit: *: Support user management through crd. #175

For test:

  1. Delete the original cluster and crd, and redeploy using the test image.
    • operator image: radondb/mysql-operator:test-2021910
    • sidecar image: radondb/mysql-sidecar:test-2021910
  2. Make sure that the root password of the msyql cluster is set.
  3. Make sure to create user secret before creating user crd.

@runkecheng runkecheng added the enhancement New feature or request label Sep 10, 2021
@runkecheng runkecheng added this to the v2.1.0 milestone Sep 10, 2021
@runkecheng runkecheng force-pushed the user_crd branch 2 times, most recently from 08524b3 to 504e29a Compare September 10, 2021 04:02
@runkecheng runkecheng force-pushed the user_crd branch 2 times, most recently from de84d79 to 6bf585b Compare September 14, 2021 07:26
@runkecheng runkecheng marked this pull request as ready for review September 15, 2021 08:21
@@ -0,0 +1,381 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor the file.


sqlRunner, err := r.getSqlRunner(ctx, user)
if err != nil {
return ctrl.Result{}, fmt.Errorf("get sqlrunner faild, err: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

faild -> failed

// 3. Set the password and permissions for the existing hosts according to the spec.
// Regardless of whether the password is modified or not, reset it to keep it up to date.
if err := r.setPassword(ctx, sqlRunner, userName, host, password); err != nil {
return fmt.Errorf("set password faild, err: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix

host := []string{host}
// Regardless of whether the permissions is modified or not, reset it to keep it up to date.
if err := r.setPermission(ctx, sqlRunner, permissions, userName, host); err != nil {
return fmt.Errorf("set permissions faild, err: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix

// 7. Authorize newly created user hosts.
// Ensure that the user has been successfully created before authorization.
if err := r.setPermission(ctx, sqlRunner, permissions, userName, unexistHosts); err != nil {
return fmt.Errorf("set permissions faild, err: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix

// createUser create users in mysql based on cr information.
func (r *MysqlUserReconciler) createUser(ctx context.Context, query internal.Query, sqlRunner *internal.SQLRunner) error {
if err := sqlRunner.RunQuery(query.String(), query.Args()...); err != nil {
return fmt.Errorf("create mysql user faild, err: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix

}

// If mysql user present, create or update.
cuErr := r.createOrUpdate(ctx, sqlRunner, user)
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor it.

// 6. Add finalizer.
// 7. Authorize newly created user hosts.
// 8. Update user`s status.
func (r *MysqlUserReconciler) createOrUpdate(ctx context.Context, sqlRunner *internal.SQLRunner, mysqlUser *mysqluser.MysqlUser) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor it.

@runkecheng runkecheng closed this Sep 22, 2021
@runkecheng runkecheng deleted the user_crd branch October 25, 2021 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] Support user management through crd
3 participants