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

made changes to AlterUser to accept maxUserConnections #723

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion api/v1alpha1/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type UserSpec struct {
// +optional
// +kubebuilder:default=10
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:number"}
MaxUserConnections int32 `json:"maxUserConnections,omitempty" webhook:"inmutable"`
MaxUserConnections int32 `json:"maxUserConnections,omitempty"` //webhook:"inmutable"`
AayushVinayDev marked this conversation as resolved.
Show resolved Hide resolved
// Name overrides the default name provided by metadata.name.
// +optional
// +kubebuilder:validation:MaxLength=80
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ func (wr *wrappedUserReconciler) Reconcile(ctx context.Context, mdbClient *sqlCl
if err := mdbClient.CreateUser(ctx, accountName, createUserOpts...); err != nil {
return fmt.Errorf("error creating User: %v", err)
}
} else if password != "" {
if err := mdbClient.AlterUser(ctx, username, password); err != nil {
} else if password != "" || wr.user.Spec.MaxUserConnections > 0 {
if err := mdbClient.AlterUser(ctx, username, password, wr.user.Spec.MaxUserConnections); err != nil {
AayushVinayDev marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("error altering User: %v", err)
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/replication/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (r *ReplicationConfig) reconcileUserSql(ctx context.Context, mariadb *maria
opts *userSqlOpts) error {
replPasswordRef := newReplPasswordRef(mariadb)
var replPassword string
var user *mariadbv1alpha1.User

req := secret.PasswordRequest{
Owner: mariadb,
Expand All @@ -207,7 +208,8 @@ func (r *ReplicationConfig) reconcileUserSql(ctx context.Context, mariadb *maria
return fmt.Errorf("error checking if replication user exists: %v", err)
}
if exists {
if err := client.AlterUser(ctx, opts.username, replPassword); err != nil {
maxUserConnections := user.Spec.MaxUserConnections
if err := client.AlterUser(ctx, opts.username, replPassword, maxUserConnections); err != nil {
AayushVinayDev marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("error altering replication user: %v", err)
}
} else {
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,9 @@ func (c *Client) DropUser(ctx context.Context, accountName string) error {
return c.ExecFlushingPrivileges(ctx, query)
}

func (c *Client) AlterUser(ctx context.Context, accountName, password string) error {
query := fmt.Sprintf("ALTER USER '%s' IDENTIFIED BY '%s';", accountName, password)
func (c *Client) AlterUser(ctx context.Context, accountName, password string, maxConnections int32) error {
AayushVinayDev marked this conversation as resolved.
Show resolved Hide resolved
query := fmt.Sprintf("ALTER USER '%s' IDENTIFIED BY '%s' MAX_USER_CONNECTIONS %d;",
accountName, password, maxConnections)

return c.ExecFlushingPrivileges(ctx, query)
}
Expand Down