Skip to content

Commit

Permalink
fix redis panic on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
jananivMS committed Jun 22, 2020
1 parent b0aa9d3 commit 0ddc3c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pkg/resourcemanager/rediscaches/redis/rediscache_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 14 additions & 4 deletions pkg/resourcemanager/rediscaches/redis/rediscache_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions pkg/resourcemanager/rediscaches/redis/rediscaches.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)

}

0 comments on commit 0ddc3c4

Please sign in to comment.