Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for async deletion of non-existent resource #3980

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

EronWright
Copy link
Contributor

@EronWright EronWright commented Feb 21, 2025

This PR fixes an error that occurs in the deletion of a (non-existent) Azure resource. The issue impacts resources that have an async-style DELETE call (as is the case for Subnet, see schema).

The user-facing error is:

  azure-native:network:Subnet (subnet):
    error: the operation failed or was cancelled

The call to runtime.NewPoller should not be made with a failed response, otherwise we hit a precondition within it:

	// this is a back-stop in case the swagger is incorrect (i.e. missing one or more status codes for success).
	// ideally the codegen should return an error if the initial response failed and not even create a poller.
	if !poller.StatusCodeValid(resp) {
		return nil, errors.New("the operation failed or was cancelled")
	}

To fix, I encapsulated the request-to-final-response logic into an anonymous function, to be able to uniformly check for the 404 result. And I ensure that the initial response was successful before making a poller.

This PR relaxes the logic for detecting a 404 during resource deletion, to not care about the specific error code. I find that at least two codes are possible: ResourceNotFound and ResourceGroupNotFound. Note that the sync path did not check the error code.

TODO:

  • new unit tests
  • manual testing for various types of resources (w/ sync and async delete operations).

Closes #3978
See also: #3783

@EronWright EronWright requested a review from thomas11 February 21, 2025 19:57
Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

// Some APIs are explicitly marked `x-ms-long-running-operation` and we should only do the
// poll for the deletion result in that case.
if asyncStyle != "" {
pt, err := runtime.NewPoller[any](resp, c.pipeline, nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomas11 , I notice that normalizeLocationHeader isn't being called here, as is in putOrPatch.
Given this discussion, it probably doesn't matter, but I bring it up in case you'd like me to act on that.

Comment on lines +302 to +304
if err, ok := err.(*azcore.ResponseError); ok {
return nil, created, newResponseError(err.RawResponse)
}
Copy link
Contributor Author

@EronWright EronWright Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix is actually a follow-up to #3783. I think it is justifiably in here because the Delete call is being similarly fixed here.

@@ -418,7 +429,7 @@ func TestErrorStatusCodes(t *testing.T) {
{
StatusCode: 503, // temporary failure
Header: http.Header{"Location": []string{"https://management.azure.com/operation"}},
Body: io.NopCloser(strings.NewReader(`{"status": "Unavailable"}`)),
Copy link
Contributor Author

@EronWright EronWright Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we fake an error response, it is good to use the error schema because you can make assertions about the final error code.

@EronWright EronWright marked this pull request as ready for review February 21, 2025 23:42
Copy link

codecov bot commented Feb 22, 2025

Codecov Report

Attention: Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.

Project coverage is 57.49%. Comparing base (73833a7) to head (8ef8cbc).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
provider/pkg/azure/client_azcore.go 73.91% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3980   +/-   ##
=======================================
  Coverage   57.49%   57.49%           
=======================================
  Files          82       82           
  Lines       13078    13077    -1     
=======================================
  Hits         7519     7519           
+ Misses       4984     4983    -1     
  Partials      575      575           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to destroy stack containing a deleted subnet
1 participant