Skip to content

Commit

Permalink
Fix: Allows fresh database to get user password (when removed acciden…
Browse files Browse the repository at this point in the history
…tally from db side)

Noticed issue when re-pointing DatabaseUser to new server or a fresh server container: the password wouldn't get set.
  • Loading branch information
cuppett committed Nov 25, 2023
1 parent 5fa89ad commit 632332a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions controllers/databaseuser_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (r *DatabaseUserReconciler) userCreate(ctx context.Context, loop *UserLoopC
createQuery := "CREATE USER '" + mysqlv1alpha1.Escape(loop.instance.Status.Username) + "'"
params := make([]interface{}, 0)

userDetails, err := r.userDetailString(ctx, loop)
userDetails, err := r.userDetailString(ctx, loop, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func (r *DatabaseUserReconciler) userUpdate(ctx context.Context, loop *UserLoopC
}

// Determining if we need to update the user wrt their authentication
userDetails, err := r.userDetailString(ctx, loop)
userDetails, err := r.userDetailString(ctx, loop, false)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -372,7 +372,7 @@ func (r *DatabaseUserReconciler) userUpdate(ctx context.Context, loop *UserLoopC
return permsDiff, err
}

func (r *DatabaseUserReconciler) userDetailString(ctx context.Context, loop *UserLoopContext) (string, error) {
func (r *DatabaseUserReconciler) userDetailString(ctx context.Context, loop *UserLoopContext, createUser bool) (string, error) {

var err error
queryFragment := ""
Expand Down Expand Up @@ -408,7 +408,7 @@ func (r *DatabaseUserReconciler) userDetailString(ctx context.Context, loop *Use
}
authPlugin = mysqlv1alpha1.Escape(authPlugin)

if passwordUpdated || pluginsDiff {
if passwordUpdated || pluginsDiff || createUser {
if authPlugin != "" {
queryFragment += " IDENTIFIED WITH '" + authPlugin + "'"
if authString != "" {
Expand Down

0 comments on commit 632332a

Please sign in to comment.