Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle 404 as success in recipe deletion (#6467)
# Description * Fixes an issue if you try to delete a recipe with nested azure resources. For some resources (like Azure ServiceBus and Azure SQL), if the top-level resource gets deleted, we still try to delete the sub-resources. This results in a 404 error, which we should handle in our code as "already deleted". ## Type of change <!-- Please select **one** of the following options that describes your change and delete the others. Clearly identifying the type of change you are making will help us review your PR faster, and is used in authoring release notes. If you are making a bug fix or functionality change to Radius and do not have an associated issue link please create one now. --> - This pull request fixes a bug in Radius and has an approved issue (issue link required). - This pull request adds or changes features of Radius and has an approved issue (issue link required). - This pull request is a minor refactor, code cleanup, test improvement, or other maintenance task and doesn't change the functionality of Radius (issue link optional). <!-- Please update the following to link the associated issue. This is required for some kinds of changes (see above). --> Fixes: #6468 ## Auto-generated summary <!-- GitHub Copilot for docs will auto-generate a summary of the PR --> <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at f2f60c4</samp> ### Summary 🧪🐛🚀 <!-- 1. 🧪 for adding unit tests 2. 🐛 for fixing a formatting issue 3. 🚀 for enhancing and improving the code --> This pull request enhances the `Is404Error` function in the `pkg/cli/clients` package to handle more types of 404 errors, and uses it to improve the error handling of the `deleteAzureResource` function in the `pkg/portableresources/processors` package. It also adds unit tests for both functions and fixes a minor formatting issue in the `pkg/corerp/handlers` package. > _Sing, O Muse, of the code review that tested the skillful programmers_ > _Who sought to enhance the `Is404Error` function, a helper of clients_ > _And to improve the `deleteAzureResource` function, a destroyer of ARM_ > _And to fix the formatting of the log message, a guide of the proxy_ ### Walkthrough * Add unit tests for `Is404Error` function in `errors_test.go` ([link](https://github.com/radius-project/radius/pull/6467/files?diff=unified&w=0#diff-d1d1bc081d6d8848bd347c3ef8d06b3d5aeeb4e19b42ed5a8b26ef1a1c005536R1-R65)) * Import `net/http` package to use `http.StatusNotFound` constant in `Is404Error` function ([link](https://github.com/radius-project/radius/pull/6467/files?diff=unified&w=0#diff-9d16b3ee1ba941f7b1f44e52d83f3baf301e00f1ba95a85ddfe48b2db62d1ae1R22)) * Update comment of `Is404Error` function to reflect additional condition ([link](https://github.com/radius-project/radius/pull/6467/files?diff=unified&w=0#diff-9d16b3ee1ba941f7b1f44e52d83f3baf301e00f1ba95a85ddfe48b2db62d1ae1L31-R35)) * Add condition to check if error is a `ResponseError` with a `StatusCode` of 404 in `Is404Error` function ([link](https://github.com/radius-project/radius/pull/6467/files?diff=unified&w=0#diff-9d16b3ee1ba941f7b1f44e52d83f3baf301e00f1ba95a85ddfe48b2db62d1ae1L40-R43)) * Use `fmt.Sprintf` to format log message with proxy name in `checkHTTPProxyStatus` function ([link](https://github.com/radius-project/radius/pull/6467/files?diff=unified&w=0#diff-397d63d65f44b2c85cd035e75632e13cbcd0d89c0610f44e818bd5bd809e1138L140-R140)) * Import `clients` package to use `Is404Error` function in `deleteAzureResource` function ([link](https://github.com/radius-project/radius/pull/6467/files?diff=unified&w=0#diff-ba263c7aa6158e7fdb51e32b1e42473d51fe6dbba4cd83b78bd0291d0465d629R29)) * Add condition to return nil if error is a 404 error in `deleteAzureResource` function ([link](https://github.com/radius-project/radius/pull/6467/files?diff=unified&w=0#diff-ba263c7aa6158e7fdb51e32b1e42473d51fe6dbba4cd83b78bd0291d0465d629R121-R124), [link](https://github.com/radius-project/radius/pull/6467/files?diff=unified&w=0#diff-ba263c7aa6158e7fdb51e32b1e42473d51fe6dbba4cd83b78bd0291d0465d629R130-R134)) * Add subtest to `Test_Delete_ARM` function to test deletion of ARM resource with 404 error ([link](https://github.com/radius-project/radius/pull/6467/files?diff=unified&w=0#diff-d0fbe2ec4dd28b47316f47c86d3a80f36e234b6dd2135cb47394d81cfcb8fe66R129-R155))
- Loading branch information