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

Ensure DB connections are closed when we've finished with them #1619

Merged
merged 5 commits into from
Jul 6, 2021
Merged
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 controllers/mysql_combined_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestMySQLHappyPath(t *testing.T) {
ctx := context.Background()

// Add any setup steps that needs to be executed before each test
rgLocation := "eastus2"
rgLocation := "westus2"
rgName := tc.resourceGroupName
mySQLServerName := GenerateTestResourceNameWithRandom("mysql-srv", 10)
mySQLReplicaName := GenerateTestResourceNameWithRandom("mysql-rep", 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (s *AzureSqlActionManager) UpdateUserPassword(
if err != nil {
return err
}
defer db.Close()

instance := &azurev1alpha1.AzureSQLUser{
TypeMeta: metav1.TypeMeta{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (s *AzureSqlManagedUserManager) Ensure(ctx context.Context, obj runtime.Obj
instance.Status.SetFailedProvisioning(instance.Status.Message)
return false, nil
}
defer db.Close()

userExists, err := s.UserExists(ctx, db, requestedUsername)
if err != nil {
Expand Down Expand Up @@ -189,6 +190,7 @@ func (s *AzureSqlManagedUserManager) Delete(ctx context.Context, obj runtime.Obj

return true, nil
}
defer db.Close()

userExists, err := s.UserExists(ctx, db, requestedUsername)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (s *AzureSqlUserManager) Ensure(ctx context.Context, obj runtime.Object, op

return false, err
}
defer db.Close()

userSecretKey := MakeSecretKey(userSecretClient, instance)

Expand Down Expand Up @@ -352,6 +353,7 @@ func (s *AzureSqlUserManager) Delete(ctx context.Context, obj runtime.Object, op
}
return false, err
}
defer db.Close()

var sqlUserSecretClient secrets.SecretClient
if options.SecretClient != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/resourcemanager/mysql/mysqlaaduser/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (m *MySQLAADUserManager) Ensure(ctx context.Context, obj runtime.Object, op

return false, mysql.IgnoreDatabaseBusy(err)
}
defer db.Close()

instance.Status.SetProvisioning("")

Expand Down Expand Up @@ -179,6 +180,7 @@ func (m *MySQLAADUserManager) Delete(ctx context.Context, obj runtime.Object, op
}
return false, err
}
defer db.Close()

err = mysql.DropUser(ctx, db, instance.Username())
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/resourcemanager/mysql/mysqluser/mysqluser_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (s *MySqlUserManager) Ensure(ctx context.Context, obj runtime.Object, opts

return false, err
}
defer db.Close()

secretKey := secrets.SecretKey{Name: instance.Name, Namespace: instance.Namespace, Kind: instance.TypeMeta.Kind}
// create or get new user secret
Expand Down Expand Up @@ -228,6 +229,7 @@ func (s *MySqlUserManager) Delete(ctx context.Context, obj runtime.Object, opts
}
return false, err
}
defer db.Close()

var userSecretClient secrets.SecretClient
if options.SecretClient != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/resourcemanager/psql/psqluser/psqluser_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (m *PostgreSqlUserManager) Ensure(ctx context.Context, obj runtime.Object,

return false, err
}
defer db.Close()

secretKey := secrets.SecretKey{Name: instance.Name, Namespace: instance.Namespace, Kind: instance.TypeMeta.Kind}

Expand Down Expand Up @@ -250,6 +251,7 @@ func (m *PostgreSqlUserManager) Delete(ctx context.Context, obj runtime.Object,
//stop the reconcile with unkown error
return false, err
}
defer db.Close()

var psqlUserSecretClient secrets.SecretClient
if options.SecretClient != nil {
Expand Down