Skip to content

Commit

Permalink
Merge pull request #27 from Azure/master
Browse files Browse the repository at this point in the history
pr
  • Loading branch information
WilliamMortlMicrosoft authored Apr 16, 2020
2 parents 0fa4980 + ab42d8b commit afdab93
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 58 deletions.
4 changes: 2 additions & 2 deletions config/samples/azure_v1alpha1_blobcontainer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ metadata:
name: blobcontainer-sample
spec:
location: westus
resourcegroup: resourcegroup-sample
accountname: storageaccount-sample
resourcegroup: resourcegroup-azure-operators
accountname: storageaccountsample777
# accessLevel - Specifies whether data in the container may be accessed publicly and the level of access.
# Possible values include: 'Container', 'Blob', 'None'
accesslevel: Container
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ func (bc *AzureBlobContainerManager) GetParents(obj runtime.Object) ([]resourcem
}

return []resourcemanager.KubeParent{
{
Key: types.NamespacedName{
Name: instance.Spec.AccountName,
Namespace: instance.Namespace,
},
Target: &azurev1alpha1.StorageAccount{},
},
{
Key: types.NamespacedName{
Name: instance.Spec.ResourceGroup,
Expand All @@ -133,6 +140,7 @@ func (bc *AzureBlobContainerManager) GetParents(obj runtime.Object) ([]resourcem
Target: &azurev1alpha1.ResourceGroup{},
},
}, nil

}

func (bc *AzureBlobContainerManager) GetStatus(obj runtime.Object) (*azurev1alpha1.ASOStatus, error) {
Expand Down
38 changes: 0 additions & 38 deletions pkg/util/util.go

This file was deleted.

0 comments on commit afdab93

Please sign in to comment.