Skip to content

Commit

Permalink
fixing several issues from feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jpflueger committed Apr 15, 2020
1 parent 7a53105 commit c8156b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions pkg/errhelp/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
NotFoundErrorCode = "NotFound"
NoSuchHost = "no such host"
ParentNotFoundErrorCode = "ParentResourceNotFound"
PreconditionFailed = "PreconditionFailed"
QuotaExceeded = "QuotaExceeded"
ResourceGroupNotFoundErrorCode = "ResourceGroupNotFound"
RegionDoesNotAllowProvisioning = "RegionDoesNotAllowProvisioning"
Expand Down
25 changes: 13 additions & 12 deletions pkg/resourcemanager/cosmosdbs/cosmosdb_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cosmosdbs
import (
"context"
"fmt"
"strings"

"github.com/Azure/azure-service-operator/api/v1alpha1"
"github.com/Azure/azure-service-operator/pkg/errhelp"
Expand Down Expand Up @@ -45,16 +46,13 @@ func (m *AzureCosmosDBManager) Ensure(ctx context.Context, obj runtime.Object, o
if err != nil {
azerr := errhelp.NewAzureErrorAzureError(err)

instance.Status.Message = err.Error()

switch azerr.Type {
case errhelp.ResourceGroupNotFoundErrorCode, errhelp.ParentNotFoundErrorCode:
instance.Status.Provisioning = false
instance.Status.Message = azerr.Error()
instance.Status.State = "Waiting"
return false, nil
case errhelp.ResourceNotFound:
//NO-OP, try to create
default:
instance.Status.Message = fmt.Sprintf("Unhandled error after Get %v", azerr.Error())
}

} else {
Expand Down Expand Up @@ -87,6 +85,8 @@ func (m *AzureCosmosDBManager) Ensure(ctx context.Context, obj runtime.Object, o
return true, nil
}

instance.Status.Provisioning = true

tags := helpers.LabelsToTags(instance.GetLabels())
accountName := instance.ObjectMeta.Name
groupName := instance.Spec.ResourceGroup
Expand Down Expand Up @@ -165,18 +165,19 @@ func (m *AzureCosmosDBManager) Delete(ctx context.Context, obj runtime.Object, o
if err != nil {
azerr := errhelp.NewAzureErrorAzureError(err)

// this is likely to happen on first try due to not waiting for the future to complete
if azerr.Type == errhelp.AsyncOpIncompleteError {
// request submitted or already in progress
if azerr.Type == errhelp.AsyncOpIncompleteError || (azerr.Type == errhelp.PreconditionFailed && strings.Contains(azerr.Reason, "operation in progress")) {
instance.Status.State = "Deleting"
instance.Status.Message = "Deletion request submitted successfully"
return true, nil
}

notFoundErrors := []string{
errhelp.NotFoundErrorCode, // happens on first request after deletion succeeds
errhelp.ResourceNotFound, // happens on subsequent requests after deletion succeeds
errhelp.ResourceGroupNotFoundErrorCode, // database doesn't exist in this resource group but the name exists globally
notFound := []string{
errhelp.NotFoundErrorCode,
errhelp.ResourceNotFound,
errhelp.ResourceGroupNotFoundErrorCode,
}
if helpers.ContainsString(notFoundErrors, azerr.Type) {
if helpers.ContainsString(notFound, azerr.Type) {
return false, m.deleteAccountKeysSecret(ctx, instance)
}

Expand Down

0 comments on commit c8156b9

Please sign in to comment.