Skip to content

Commit

Permalink
Bug: SQL User error on GetDB in transitional state (#928)
Browse files Browse the repository at this point in the history
* refactor

* small update:

* parent error code

* additional error trap for db

* janani comment

* janani vnet fix

Co-authored-by: William Mortl <wmortl@Williams-MacBook-Pro.local>
Co-authored-by: Janani Vasudevan <49576785+jananivMS@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 15, 2020
1 parent 3eac712 commit c843020
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 18 deletions.
30 changes: 18 additions & 12 deletions pkg/resourcemanager/azuresql/azuresqldb/azuresqldb_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package azuresqldb
import (
"context"
"fmt"
"strings"

azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1"
"github.com/Azure/azure-service-operator/pkg/errhelp"
Expand Down Expand Up @@ -65,18 +66,16 @@ func (db *AzureSqlDbManager) Ensure(ctx context.Context, obj runtime.Object, opt
instance.Status.Message = resourcemanager.SuccessMsg
instance.Status.ResourceId = *dbGet.ID
return true, nil
} else {
azerr := errhelp.NewAzureErrorAzureError(err)
ignore := []string{
errhelp.NotFoundErrorCode,
errhelp.ResourceNotFound,
errhelp.ResourceGroupNotFoundErrorCode,
}
if !helpers.ContainsString(ignore, azerr.Type) {
instance.Status.Message = err.Error()
instance.Status.Provisioning = false
return false, fmt.Errorf("AzureSqlDb GetDB error %v", err)
}
}
instance.Status.Message = fmt.Sprintf("AzureSqlDb Get error %s", err.Error())
azerr := errhelp.NewAzureErrorAzureError(err)
requeuErrors := []string{
errhelp.ParentNotFoundErrorCode,
errhelp.ResourceGroupNotFoundErrorCode,
}
if helpers.ContainsString(requeuErrors, azerr.Type) {
instance.Status.Provisioning = false
return false, nil
}

resp, err := db.CreateOrUpdateDB(ctx, groupName, location, server, labels, azureSQLDatabaseProperties)
Expand All @@ -100,6 +99,13 @@ func (db *AzureSqlDbManager) Ensure(ctx context.Context, obj runtime.Object, opt
return false, nil
}

// if the database is busy, requeue
errorString := err.Error()
if strings.Contains(errorString, "Try again later") {
instance.Status.Provisioning = false
return false, nil
}

// assertion that a 404 error implies that the Azure SQL server hasn't been provisioned yet
if resp != nil && resp.StatusCode == 404 {
instance.Status.Message = fmt.Sprintf("Waiting for SQL Server %s to provision", server)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ func (fg *AzureSqlFailoverGroupManager) Ensure(ctx context.Context, obj runtime.
return true, nil
}
instance.Status.Message = fmt.Sprintf("AzureSqlFailoverGroup Get error %s", err.Error())
requeuErrors := []string{
errhelp.ResourceGroupNotFoundErrorCode,
errhelp.ParentNotFoundErrorCode,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(requeuErrors, azerr.Type) {
instance.Status.Provisioning = false
return false, nil
}

_, err = fg.CreateOrUpdateFailoverGroup(ctx, groupName, serverName, failoverGroupName, sqlFailoverGroupProperties)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ func (fw *AzureSqlFirewallRuleManager) Ensure(ctx context.Context, obj runtime.O
return true, nil
}
instance.Status.Message = fmt.Sprintf("AzureSqlFirewallRule Get error %s", err.Error())
requeuErrors := []string{
errhelp.ResourceGroupNotFoundErrorCode,
errhelp.ParentNotFoundErrorCode,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(requeuErrors, azerr.Type) {
instance.Status.Provisioning = false
return false, nil
}

_, err = fw.CreateOrUpdateSQLFirewallRule(ctx, groupName, server, ruleName, startIP, endIP)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,44 @@ func (s *AzureSqlUserManager) Ensure(ctx context.Context, obj runtime.Object, op

_, err = s.GetDB(ctx, instance.Spec.ResourceGroup, instance.Spec.Server, instance.Spec.DbName)
if err != nil {
instance.Status.Message = err.Error()
instance.Status.Message = errhelp.StripErrorIDs(err)
instance.Status.Provisioning = false

catch := []string{
requeuErrors := []string{
errhelp.ResourceNotFound,
errhelp.ParentNotFoundErrorCode,
errhelp.ResourceGroupNotFoundErrorCode,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(catch, azerr.Type) {
if helpers.ContainsString(requeuErrors, azerr.Type) {
return false, nil
}
return false, err

// if the database is busy, requeue
errorString := err.Error()
if strings.Contains(errorString, "Please retry the connection later") {
return false, nil
}

// if this is an unmarshall error - igmore and continue, otherwise report error and requeue
if !strings.Contains(errorString, "cannot unmarshal array into Go struct field serviceError2.details") {
return false, err
}
}

db, err := s.ConnectToSqlDb(ctx, DriverName, instance.Spec.Server, instance.Spec.DbName, SqlServerPort, adminUser, adminPassword)
if err != nil {
instance.Status.Message = errhelp.StripErrorIDs(err)
instance.Status.Provisioning = false

// catch firewall issue - keep cycling until it clears up
if strings.Contains(err.Error(), "create a firewall rule for this IP address") {
instance.Status.Provisioned = false
instance.Status.Provisioning = false
return false, nil
}

// if the database is busy, requeue
errorString := err.Error()
if strings.Contains(errorString, "Please retry the connection later") {
return false, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package azuresqlvnetrule
import (
"context"
"fmt"
"strings"

"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2015-05-01-preview/sql"
azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1"
Expand Down Expand Up @@ -43,6 +44,15 @@ func (vr *AzureSqlVNetRuleManager) Ensure(ctx context.Context, obj runtime.Objec
return false, nil
}
instance.Status.Message = fmt.Sprintf("AzureSqlVNetRule Get error %s", err.Error())
requeuErrors := []string{
errhelp.ResourceGroupNotFoundErrorCode,
errhelp.ParentNotFoundErrorCode,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(requeuErrors, azerr.Type) {
instance.Status.Provisioning = false
return false, nil
}

instance.Status.Provisioning = true
_, err = vr.CreateOrUpdateSQLVNetRule(ctx, groupName, server, ruleName, virtualNetworkRG, virtualnetworkname, subnetName, ignoreendpoint)
Expand All @@ -66,6 +76,13 @@ func (vr *AzureSqlVNetRuleManager) Ensure(ctx context.Context, obj runtime.Objec
return false, nil
}

// this happens when we try to create the VNet rule and the server doesnt exist yet
errorString := err.Error()
if strings.Contains(errorString, "does not have the server") {
instance.Status.Provisioning = false
return false, nil
}

return false, err
}

Expand Down

0 comments on commit c843020

Please sign in to comment.