From 6484be8cb96915dcc12083c2dac78a489720ad5d Mon Sep 17 00:00:00 2001 From: BCarvalheira Date: Sun, 28 Aug 2022 21:17:15 -0700 Subject: [PATCH 1/4] CloudError added for clusterDelete --- pkg/api/error.go | 3 ++- pkg/cluster/delete.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/api/error.go b/pkg/api/error.go index d00d857f8..01a32df06 100644 --- a/pkg/api/error.go +++ b/pkg/api/error.go @@ -95,7 +95,8 @@ const ( CloudErrorCodeDuplicateDomain = "DuplicateDomain" CloudErrorCodeResourceQuotaExceeded = "ResourceQuotaExceeded" CloudErrorCodeQuotaExceeded = "QuotaExceeded" - CloudErrorResourceProviderNotRegistered = "ResourceProviderNotRegistered" + CloudErrorCodeResourceProviderNotRegistered = "ResourceProviderNotRegistered" + CloudErrorCodeCannotDeleteLoadBalancerByID = "CannotDeleteLoadBalancerWithPrivateLinkService" ) // NewCloudError returns a new CloudError diff --git a/pkg/cluster/delete.go b/pkg/cluster/delete.go index e5599c7e4..ac15f614e 100644 --- a/pkg/cluster/delete.go +++ b/pkg/cluster/delete.go @@ -231,6 +231,16 @@ func (m *manager) deleteResources(ctx context.Context) error { m.log.Printf("deleting %s", *resource.ID) future, err := m.resources.DeleteByID(ctx, *resource.ID, apiVersion) if err != nil { + detailedError, ok := err.(autorest.DetailedError) + if ok { + if strings.Contains(detailedError.Original.Error(), "CannotDeleteLoadBalancerWithPrivateLinkService") { + err = api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeCannotDeleteLoadBalancerByID, + "features.ResourcesClient#DeleteByID", detailedError.Original.Error()) + } else if strings.Contains(detailedError.Original.Error(), "AuthorizationFailed") { + err = api.NewCloudError(http.StatusForbidden, api.CloudErrorCodeForbidden, + "features.ResourcesClient#DeleteByID", detailedError.Original.Error()) + } + } return err } From 3e3cbaa15f20e54e690d7c9c03959fa86675c7fa Mon Sep 17 00:00:00 2001 From: BCarvalheira Date: Mon, 29 Aug 2022 11:00:11 -0700 Subject: [PATCH 2/4] Uniform CloudErrorCode --- pkg/api/validate/dynamic/provider.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/api/validate/dynamic/provider.go b/pkg/api/validate/dynamic/provider.go index 82e2ec09f..011e56d2d 100644 --- a/pkg/api/validate/dynamic/provider.go +++ b/pkg/api/validate/dynamic/provider.go @@ -34,7 +34,7 @@ func (dv *dynamic) ValidateProviders(ctx context.Context) error { } { if providerMap[provider].RegistrationState == nil || *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) } } From 73a3581a569ce8174a961671925ef8780b7307f2 Mon Sep 17 00:00:00 2001 From: BCarvalheira Date: Mon, 19 Sep 2022 14:51:31 -0700 Subject: [PATCH 3/4] Created deleteByIdCloudError Function --- pkg/cluster/delete.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/pkg/cluster/delete.go b/pkg/cluster/delete.go index ac15f614e..71ec135df 100644 --- a/pkg/cluster/delete.go +++ b/pkg/cluster/delete.go @@ -231,17 +231,7 @@ func (m *manager) deleteResources(ctx context.Context) error { m.log.Printf("deleting %s", *resource.ID) future, err := m.resources.DeleteByID(ctx, *resource.ID, apiVersion) if err != nil { - detailedError, ok := err.(autorest.DetailedError) - if ok { - if strings.Contains(detailedError.Original.Error(), "CannotDeleteLoadBalancerWithPrivateLinkService") { - err = api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeCannotDeleteLoadBalancerByID, - "features.ResourcesClient#DeleteByID", detailedError.Original.Error()) - } else if strings.Contains(detailedError.Original.Error(), "AuthorizationFailed") { - err = api.NewCloudError(http.StatusForbidden, api.CloudErrorCodeForbidden, - "features.ResourcesClient#DeleteByID", detailedError.Original.Error()) - } - } - return err + return deleteByIdCloudError(err) } futures = append(futures, future) @@ -261,6 +251,22 @@ func (m *manager) deleteResources(ctx context.Context) error { return nil } +func deleteByIdCloudError(err error) error { + detailedError, ok := err.(autorest.DetailedError) + if ok { + 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 { resourceGroupID := m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID resourceGroup := stringutils.LastTokenByte(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/') From 6aacfb8832f5a3163335723139a9b78bc91ad7db Mon Sep 17 00:00:00 2001 From: carvalhe Date: Tue, 20 Sep 2022 13:35:41 -0700 Subject: [PATCH 4/4] Update pkg/cluster/delete.go Co-authored-by: Jeremy Facchetti --- pkg/cluster/delete.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/cluster/delete.go b/pkg/cluster/delete.go index 71ec135df..c50419a94 100644 --- a/pkg/cluster/delete.go +++ b/pkg/cluster/delete.go @@ -253,16 +253,17 @@ func (m *manager) deleteResources(ctx context.Context) error { func deleteByIdCloudError(err error) error { detailedError, ok := err.(autorest.DetailedError) - if ok { - switch { - case strings.Contains(detailedError.Original.Error(), "CannotDeleteLoadBalancerWithPrivateLinkService"): - return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeCannotDeleteLoadBalancerByID, - "features.ResourcesClient#DeleteByID", detailedError.Original.Error()) + 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()) - } + case strings.Contains(detailedError.Original.Error(), "AuthorizationFailed"): + return api.NewCloudError(http.StatusForbidden, api.CloudErrorCodeForbidden, + "features.ResourcesClient#DeleteByID", detailedError.Original.Error()) } return err }