Skip to content

Commit

Permalink
Azure: Display proper error message on failure to delete
Browse files Browse the repository at this point in the history
If there are other resources in the resource group that are in use
by resources in other groups then the deletion will be blocked.
The error message displayed is not user friendly and hence adding
a check to see if the error code returned by azure autorest is
409, which is ResourceGroupDeletionBlocked, and display a proper
message to the user.
  • Loading branch information
rna-afk committed Aug 18, 2021
1 parent 6fb15ac commit 03f6539
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/destroy/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ func (o *ClusterUninstaller) Run() error {
if isAuthError(err) {
cancel()
errs = append(errs, errors.Wrap(err, "unable to authenticate when deleting resource group"))
} else if isResourceGroupBlockedError(err) {
cancel()
errs = append(errs, errors.Wrap(err, "unable to delete resource group, resources in the group are in use by others"))
}
return
}
Expand Down Expand Up @@ -505,6 +508,24 @@ func isAuthError(err error) bool {
return false
}

func isResourceGroupBlockedError(err error) bool {
if err == nil {
return false
}

var dErr autorest.DetailedError
if errors.As(err, &dErr) {
switch statusCode := dErr.StatusCode.(type) {
case int:
if statusCode == 409 {
return true
}
}
}

return false
}

func deleteApplicationRegistrations(ctx context.Context, appClient graphrbac.ApplicationsClient, spClient graphrbac.ServicePrincipalsClient, logger logrus.FieldLogger, infraID string) error {
errorList := []error{}

Expand Down

0 comments on commit 03f6539

Please sign in to comment.