Skip to content

Commit

Permalink
Merge pull request #551 from jananivMS/sqltesting
Browse files Browse the repository at this point in the history
Fix issues with SQL operators before release to testing
  • Loading branch information
jananivMS authored Jan 5, 2020
2 parents cb2fd82 + bbe9df5 commit f0d7777
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 21 deletions.
6 changes: 1 addition & 5 deletions controllers/azuresqlaction_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ func (r *AzureSqlActionReconciler) reconcileExternal(ctx context.Context, instan
instance.Status.Provisioning = true
instance.Status.Provisioned = false
instance.Status.Message = "AzureSqlAction in progress"
// write information back to instance
if updateerr := r.Status().Update(ctx, instance); updateerr != nil {
r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to update instance")
}

//get owner instance of AzureSqlServer
r.Recorder.Event(instance, corev1.EventTypeNormal, "UpdatingOwner", "Updating owner AzureSqlServer instance")
Expand Down Expand Up @@ -182,7 +178,7 @@ func (r *AzureSqlActionReconciler) reconcileExternal(ctx context.Context, instan
newPassword, _ := generateRandomPassword(passwordLength)
azureSqlServerProperties.AdministratorLoginPassword = to.StringPtr(newPassword)

if _, err := r.AzureSqlServerManager.CreateOrUpdateSQLServer(ctx, groupName, *server.Location, serverName, azureSqlServerProperties); err != nil {
if _, err := r.AzureSqlServerManager.CreateOrUpdateSQLServer(ctx, groupName, *server.Location, serverName, azureSqlServerProperties, true); err != nil {
if !strings.Contains(err.Error(), "not complete") {
r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to provision or update instance")
return err
Expand Down
2 changes: 2 additions & 0 deletions controllers/azuresqlfailovergroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func (r *AzureSqlFailoverGroupReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
errhelp.NotFoundErrorCode,
errhelp.AsyncOpIncompleteError,
errhelp.InvalidServerName,
errhelp.ResourceNotFound,
errhelp.FailoverGroupBusy,
}
if azerr, ok := err.(*errhelp.AzureError); ok {
if helpers.ContainsString(catch, azerr.Type) {
Expand Down
4 changes: 2 additions & 2 deletions controllers/azuresqlserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (r *AzureSqlServerReconciler) reconcileExternal(instance *azurev1alpha1.Azu
}

// write information back to instance
if err := r.Status().Update(ctx, instance); err != nil {
if err := r.Update(ctx, instance); err != nil {
r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to update instance")
}

Expand All @@ -230,7 +230,7 @@ func (r *AzureSqlServerReconciler) reconcileExternal(instance *azurev1alpha1.Azu

// create the sql server
instance.Status.Provisioning = true
if _, err := r.AzureSqlServerManager.CreateOrUpdateSQLServer(ctx, groupName, location, name, azureSqlServerProperties); err != nil {
if _, err := r.AzureSqlServerManager.CreateOrUpdateSQLServer(ctx, groupName, location, name, azureSqlServerProperties, false); err != nil {
if !strings.Contains(err.Error(), "not complete") {
msg := fmt.Sprintf("CreateOrUpdateSQLServer not complete: %v", err)
instance.Status.Message = msg
Expand Down
2 changes: 1 addition & 1 deletion controllers/azuresqluser_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (r *AzureSQLUserReconciler) reconcileExternal(instance azurev1alpha1.AzureS
if len(roles) == 0 {
log.Info("No roles specified for user")
} else {
r.AzureSqlUserManager.GrantUserRoles(ctx, user, roles, db)
r.AzureSqlUserManager.GrantUserRoles(ctx, string(DBSecret[SecretUsernameKey]), roles, db)
}

// publish user secret
Expand Down
1 change: 1 addition & 0 deletions pkg/errhelp/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
BadRequest = "BadRequest"
AccountNameInvalid = "AccountNameInvalid"
RequestConflictError = "Conflict"
FailoverGroupBusy = "FailoverGroupBusy"
)

func NewAzureError(err error) error {
Expand Down
14 changes: 8 additions & 6 deletions pkg/resourcemanager/azuresql/azuresqlserver/azuresqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ func (_ *AzureSqlServerManager) GetServer(ctx context.Context, resourceGroupName
}

// CreateOrUpdateSQLServer creates a SQL server in Azure
func (_ *AzureSqlServerManager) CreateOrUpdateSQLServer(ctx context.Context, resourceGroupName string, location string, serverName string, properties azuresqlshared.SQLServerProperties) (result sql.Server, err error) {
func (_ *AzureSqlServerManager) CreateOrUpdateSQLServer(ctx context.Context, resourceGroupName string, location string, serverName string, properties azuresqlshared.SQLServerProperties, forceUpdate bool) (result sql.Server, err error) {
serversClient := azuresqlshared.GetGoServersClient()
serverProp := azuresqlshared.SQLServerPropertiesToServer(properties)

checkNameResult, err := CheckNameAvailability(ctx, resourceGroupName, serverName)
if checkNameResult.Reason == sql.AlreadyExists {
return result, errors.New("AlreadyExists")
} else if checkNameResult.Reason == sql.Invalid {
return result, errors.New("InvalidServerName")
if forceUpdate == false {
checkNameResult, _ := CheckNameAvailability(ctx, resourceGroupName, serverName)
if checkNameResult.Reason == sql.AlreadyExists {
return result, errors.New("AlreadyExists")
} else if checkNameResult.Reason == sql.Invalid {
return result, errors.New("InvalidServerName")
}
}

// issue the creation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

type SqlServerManager interface {
CreateOrUpdateSQLServer(ctx context.Context, resourceGroupName string, location string, serverName string, properties azuresqlshared.SQLServerProperties) (result sql.Server, err error)
CreateOrUpdateSQLServer(ctx context.Context, resourceGroupName string, location string, serverName string, properties azuresqlshared.SQLServerProperties, forceUpdate bool) (result sql.Server, err error)
DeleteSQLServer(ctx context.Context, resourceGroupName string, serverName string) (result autorest.Response, err error)
GetServer(ctx context.Context, resourceGroupName string, serverName string) (result sql.Server, err error)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// ResourceClient contains the helper functions for interacting with SQL servers / databases
type ResourceClient interface {
CreateOrUpdateSQLServer(ctx context.Context, resourceGroupName string, location string, serverName string, properties SQLServerProperties) (result sql.Server, err error)
CreateOrUpdateSQLServer(ctx context.Context, resourceGroupName string, location string, serverName string, properties SQLServerProperties, forceUpdate bool) (result sql.Server, err error)
DeleteSQLServer(ctx context.Context, resourceGroupName string, serverName string) (result autorest.Response, err error)
GetServer(ctx context.Context, resourceGroupName string, serverName string) (result sql.Server, err error)
DeleteSQLFirewallRule(ctx context.Context, resourceGroupName string, serverName string, ruleName string) (err error)
Expand Down
1 change: 0 additions & 1 deletion pkg/resourcemanager/azuresql/azuresqluser/azuresqluser.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func (m *AzureSqlUserManager) ConnectToSqlDb(ctx context.Context, drivername str
fullServerAddress := fmt.Sprintf("%s.database.windows.net", server)
connString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d;database=%s;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30", fullServerAddress, user, password, port, database)

m.Log.Info("ConnectToSqlDb:", "conn string:", connString)
db, err := sql.Open(drivername, connString)
if err != nil {
m.Log.Info("ConnectToSqlDb", "error from sql.Open is:", err.Error())
Expand Down
4 changes: 2 additions & 2 deletions pkg/resourcemanager/azuresql/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestCreateOrUpdateSQLServer(t *testing.T) {
}

// wait for server to be created, then only proceed once activated
server, err := tc.sqlServerManager.CreateOrUpdateSQLServer(ctx, groupName, location, serverName, sqlServerProperties)
server, err := tc.sqlServerManager.CreateOrUpdateSQLServer(ctx, groupName, location, serverName, sqlServerProperties, false)
azerr := errhelp.NewAzureErrorAzureError(err)
if err != nil && !helpers.ContainsString(ignorableErrors, azerr.Type) {
util.PrintAndLog(fmt.Sprintf("cannot create sql server: %v", err))
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestCreateOrUpdateSQLServer(t *testing.T) {
}

// wait for server to be created, then only proceed once activated
server, err = tc.sqlServerManager.CreateOrUpdateSQLServer(ctx, groupName, secLocation, secSrvName, sqlServerProperties)
server, err = tc.sqlServerManager.CreateOrUpdateSQLServer(ctx, groupName, secLocation, secSrvName, sqlServerProperties, false)
azerr = errhelp.NewAzureErrorAzureError(err)

if err != nil && !helpers.ContainsString(ignorableErrors, azerr.Type) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcemanager/mock/azuresql/azuresqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func findSqlServer(res []MockSqlServerResource, predicate func(MockSqlServerReso
}

// CreateOrUpdateSqlServer creates a new sql server
func (manager *MockSqlServerManager) CreateOrUpdateSQLServer(ctx context.Context, resourceGroupName string, location string, serverName string, properties azuresqlshared.SQLServerProperties) (result sql.Server, err error) {
func (manager *MockSqlServerManager) CreateOrUpdateSQLServer(ctx context.Context, resourceGroupName string, location string, serverName string, properties azuresqlshared.SQLServerProperties, forceUpdate bool) (result sql.Server, err error) {
index, _ := findSqlServer(manager.sqlServers, func(s MockSqlServerResource) bool {
return s.resourceGroupName == resourceGroupName && *s.sqlServer.Name == serverName
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcemanager/mock/sqlclient/sqlclient_gosdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type MockGoSDKClient struct {
}

// CreateOrUpdateSQLServer creates a new sql server
func (sdk *MockGoSDKClient) CreateOrUpdateSQLServer(ctx context.Context, resourceGroupName string, location string, serverName string, properties azuresqlshared.SQLServerProperties) (result sql.Server, err error) {
func (sdk *MockGoSDKClient) CreateOrUpdateSQLServer(ctx context.Context, resourceGroupName string, location string, serverName string, properties azuresqlshared.SQLServerProperties, forceUpdate bool) (result sql.Server, err error) {
var sqlServer = sql.Server{
Response: helpers.GetRestResponse(http.StatusCreated),
}
Expand Down

0 comments on commit f0d7777

Please sign in to comment.