Merge pull request #2359 from carvalhe/asyncDelete_newCloudError

CloudError added for clusterDelete
This commit is contained in:
Ross Bryan 2022-09-22 15:19:50 -04:00 коммит произвёл GitHub
Родитель b7141226f3 6aacfb8832
Коммит 0f950d78f1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 21 добавлений и 3 удалений

Просмотреть файл

@ -96,7 +96,8 @@ const (
CloudErrorCodeDuplicateDomain = "DuplicateDomain" CloudErrorCodeDuplicateDomain = "DuplicateDomain"
CloudErrorCodeResourceQuotaExceeded = "ResourceQuotaExceeded" CloudErrorCodeResourceQuotaExceeded = "ResourceQuotaExceeded"
CloudErrorCodeQuotaExceeded = "QuotaExceeded" CloudErrorCodeQuotaExceeded = "QuotaExceeded"
CloudErrorResourceProviderNotRegistered = "ResourceProviderNotRegistered" CloudErrorCodeResourceProviderNotRegistered = "ResourceProviderNotRegistered"
CloudErrorCodeCannotDeleteLoadBalancerByID = "CannotDeleteLoadBalancerWithPrivateLinkService"
) )
// NewCloudError returns a new CloudError // NewCloudError returns a new CloudError

Просмотреть файл

@ -34,7 +34,7 @@ func (dv *dynamic) ValidateProviders(ctx context.Context) error {
} { } {
if providerMap[provider].RegistrationState == nil || if providerMap[provider].RegistrationState == nil ||
*providerMap[provider].RegistrationState != "Registered" { *providerMap[provider].RegistrationState != "Registered" {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorResourceProviderNotRegistered, "", "The resource provider '%s' is not registered.", provider) return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeResourceProviderNotRegistered, "", "The resource provider '%s' is not registered.", provider)
} }
} }

Просмотреть файл

@ -231,7 +231,7 @@ func (m *manager) deleteResources(ctx context.Context) error {
m.log.Printf("deleting %s", *resource.ID) m.log.Printf("deleting %s", *resource.ID)
future, err := m.resources.DeleteByID(ctx, *resource.ID, apiVersion) future, err := m.resources.DeleteByID(ctx, *resource.ID, apiVersion)
if err != nil { if err != nil {
return err return deleteByIdCloudError(err)
} }
futures = append(futures, future) futures = append(futures, future)
@ -251,6 +251,23 @@ func (m *manager) deleteResources(ctx context.Context) error {
return nil return nil
} }
func deleteByIdCloudError(err error) error {
detailedError, ok := err.(autorest.DetailedError)
if !ok {
return err
}
switch {
case strings.Contains(detailedError.Original.Error(), "CannotDeleteLoadBalancerWithPrivateLinkService"):
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeCannotDeleteLoadBalancerByID,
"features.ResourcesClient#DeleteByID", detailedError.Original.Error())
case strings.Contains(detailedError.Original.Error(), "AuthorizationFailed"):
return api.NewCloudError(http.StatusForbidden, api.CloudErrorCodeForbidden,
"features.ResourcesClient#DeleteByID", detailedError.Original.Error())
}
return err
}
func (m *manager) deleteRoleAssignments(ctx context.Context) error { func (m *manager) deleteRoleAssignments(ctx context.Context) error {
resourceGroupID := m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID resourceGroupID := m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID
resourceGroup := stringutils.LastTokenByte(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/') resourceGroup := stringutils.LastTokenByte(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/')