diff --git a/pkg/resourcemanager/rediscaches/redis/rediscache_manager.go b/pkg/resourcemanager/rediscaches/redis/rediscache_manager.go index 4e573e2ebf1..66e2d388037 100644 --- a/pkg/resourcemanager/rediscaches/redis/rediscache_manager.go +++ b/pkg/resourcemanager/rediscaches/redis/rediscache_manager.go @@ -9,6 +9,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis" azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" "github.com/Azure/azure-service-operator/pkg/resourcemanager" + "github.com/Azure/go-autorest/autorest" ) // RedisCacheManager for RedisCache @@ -17,7 +18,7 @@ type RedisCacheManager interface { CreateRedisCache(ctx context.Context, instance azurev1alpha1.RedisCache) (*redis.ResourceType, error) // DeleteRedisCache removes the resource group named by env var - DeleteRedisCache(ctx context.Context, groupName string, redisCacheName string) (result redis.DeleteFuture, err error) + DeleteRedisCache(ctx context.Context, groupName string, redisCacheName string) (result autorest.Response, err error) // also embed async client methods resourcemanager.ARMClient diff --git a/pkg/resourcemanager/rediscaches/redis/rediscache_reconcile.go b/pkg/resourcemanager/rediscaches/redis/rediscache_reconcile.go index 8b1f72ba7f9..1be87e7d015 100644 --- a/pkg/resourcemanager/rediscaches/redis/rediscache_reconcile.go +++ b/pkg/resourcemanager/rediscaches/redis/rediscache_reconcile.go @@ -146,17 +146,27 @@ func (rc *AzureRedisCacheManager) Delete(ctx context.Context, obj runtime.Object return true, nil } - req, err := rc.DeleteRedisCache(ctx, groupName, name) + _, err = rc.DeleteRedisCache(ctx, groupName, name) if err != nil { instance.Status.Message = err.Error() + azerr := errhelp.NewAzureErrorAzureError(err) + + ignorableErr := []string{ + errhelp.AsyncOpIncompleteError, + } - if req.Response().StatusCode == http.StatusNotFound { + finished := []string{ + errhelp.ResourceNotFound, + } + if helpers.ContainsString(ignorableErr, azerr.Type) { + return true, nil + } + if helpers.ContainsString(finished, azerr.Type) { // Best case deletion of secrets rc.SecretClient.Delete(ctx, key) return false, nil } - - return true, fmt.Errorf("AzureRedisCacheManager Delete failed with %s", err) + return true, err } return true, nil diff --git a/pkg/resourcemanager/rediscaches/redis/rediscaches.go b/pkg/resourcemanager/rediscaches/redis/rediscaches.go index 702eaa52f78..ad9dc1fd080 100644 --- a/pkg/resourcemanager/rediscaches/redis/rediscaches.go +++ b/pkg/resourcemanager/rediscaches/redis/rediscaches.go @@ -14,6 +14,7 @@ import ( "github.com/Azure/azure-service-operator/pkg/resourcemanager/rediscaches" "github.com/Azure/azure-service-operator/pkg/resourcemanager/vnet" "github.com/Azure/azure-service-operator/pkg/secrets" + "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/to" "k8s.io/apimachinery/pkg/runtime" ) @@ -131,10 +132,16 @@ func (r *AzureRedisCacheManager) GetRedisCache(ctx context.Context, groupName st } // DeleteRedisCache removes the resource group named by env var -func (r *AzureRedisCacheManager) DeleteRedisCache(ctx context.Context, groupName string, redisCacheName string) (result redis.DeleteFuture, err error) { +func (r *AzureRedisCacheManager) DeleteRedisCache(ctx context.Context, groupName string, redisCacheName string) (result autorest.Response, err error) { redisClient, err := r.GetRedisCacheClient() if err != nil { return result, err } - return redisClient.Delete(ctx, groupName, redisCacheName) + future, err := redisClient.Delete(ctx, groupName, redisCacheName) + if err != nil { + return result, err + } + + return future.Result(redisClient) + }