Skip to content
Open
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
41 changes: 20 additions & 21 deletions pkg/controller/pxc/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,11 @@ func (r *ReconcilePerconaXtraDBCluster) syncPXCUsersWithProxySQL(ctx context.Con

command := []string{"proxysql-admin", "--syncusers", "--add-query-rule"}
if cr.Spec.ProxySQL.Scheduler.Enabled {
command = []string{"percona-scheduler-admin",
command = []string{
"percona-scheduler-admin",
"--config-file=" + statefulset.SchedulerConfigPath,
"--syncusers", "--add-query-rule"}
"--syncusers", "--add-query-rule",
}
}

err = r.clientcmd.Exec(&pod, "proxysql", command, nil, &outb, &errb, false)
Expand Down Expand Up @@ -1164,30 +1166,27 @@ func (r *ReconcilePerconaXtraDBCluster) updateUserPassExpirationPolicy(ctx conte
return nil
}

if cr.CompareVersionWith("1.13.0") >= 0 {
um, err := getUserManager(cr, internalSecrets)
if err != nil {
return err
}

if err := um.UpdatePassExpirationPolicy(user); err != nil {
return errors.Wrapf(err, "update %s user password expiration policy", user.Name)
}
um, err := getUserManager(cr, internalSecrets)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I also think we have a potential problem on updateProxyUser

	for i := 0; i < int(cr.Spec.ProxySQL.Size); i++ {
		um, err := users.NewManager(cr.Name+"-proxysql-"+strconv.Itoa(i)+"."+cr.Name+"-proxysql-unready."+cr.Namespace+":6032", users.ProxyAdmin, string(internalSecrets.Data[users.ProxyAdmin]), cr.Spec.PXC.ReadinessProbes.TimeoutSeconds)
		if err != nil {
			return errors.Wrap(err, "new users manager")
		}
		defer um.Close()
		err = um.UpdateProxyUser(user)
		if err != nil {
			return errors.Wrap(err, "update proxy users")
		}
	}

We are deferring inside a loop essentially. Defers accumulate until function return, so all ProxySQL.Size connections remain open simultaneously instead of being closed after each iteration.

if err != nil {
return err
}
defer um.Close()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's handle the error and log it for full visibility


if internalSecrets.Annotations == nil {
internalSecrets.Annotations = make(map[string]string)
}
if err := um.UpdatePassExpirationPolicy(user); err != nil {
return errors.Wrapf(err, "update %s user password expiration policy", user.Name)
}

internalSecrets.Annotations[annotationName] = "done"
err = r.client.Update(ctx, internalSecrets)
if err != nil {
return errors.Wrap(err, "update internal sys users secret annotation")
}
if internalSecrets.Annotations == nil {
internalSecrets.Annotations = make(map[string]string)
}

log.Info("Password expiration policy updated", "user", user.Name)
return nil
internalSecrets.Annotations[annotationName] = "done"
if err = r.client.Update(ctx, internalSecrets); err != nil {
return errors.Wrap(err, "update internal sys users secret annotation")
}

log.Info("Password expiration policy updated", "user", user.Name)

return nil
}

Expand Down
Loading