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

Tolerate 404 errors during resource deletion to handle already delete… #2590

Closed
wants to merge 1 commit into from

Conversation

JaylonmcShan03
Copy link
Contributor

@JaylonmcShan03 JaylonmcShan03 commented Sep 23, 2024

Description

Fixes #2188
This PR introduces changes to handle "404 Not Found" errors during the deletion of Kubernetes resources, particularly in cases where the resource may have already been deleted by an operator managing the CRD before Terraform attempts to delete it.

Changes Introduced:

Added logic to check for IsNotFound(err) when calling Delete on resources.

If a "404 Not Found" error is encountered, it is now treated as a successful deletion and logged as "Resource
already deleted, ignoring 404 error".
Other errors during deletion will continue to be handled as before.

Acceptance tests

  • Have you added an acceptance test for the functionality being added?
  • Have you run the acceptance tests on this branch?
  • Tested via the issue config supplied by the user.

Output from acceptance testing:
Warning: Resource "elasticsearch" was already deleted

│ The resource "elasticsearch" was not found in the Kubernetes API. This may be due to the resource being already deleted.


│ Warning: Resource "elasticsearch-es-elastic-user" was already deleted

│ The resource "elasticsearch-es-elastic-user" was not found in the Kubernetes API. This may be due to the resource being already deleted.

Destroy complete! Resources: 3 destroyed.

$ make testacc TESTARGS='-run=TestAccXXX'

...

Release Note

Release note for CHANGELOG:

...

References

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Copy link
Member

@alexsomesan alexsomesan left a comment

Choose a reason for hiding this comment

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

Looks good overall, but the changes to the waiting logic might not have the effect you want. See my comment over there.

Also, we need a new acceptance test that confirms this change.

@@ -564,16 +575,24 @@ func (s *RawProviderServer) ApplyResourceChange(ctx context.Context, req *tfprot
_, err := rs.Get(ctxDeadline, rname, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
s.logger.Trace("[ApplyResourceChange][Delete]", "Resource is deleted")
s.logger.Trace("[ApplyResourceChange][Delete]", "Resource is already deleted")
Copy link
Member

Choose a reason for hiding this comment

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

We actually don't need the change over here.

I this case, receiving a 404 while waiting for a resource to actually be deleted is a confirmation of the actual deletion, not an indication that the resource was not actually present to begin with (in that case the 404 will have shown up as response to the original .Delete() call).

Summary: fmt.Sprintf("Resource %q was already deleted", rname),
Detail: fmt.Sprintf("The resource %q was not found in the Kubernetes API. This may be due to the resource being already deleted.", rname),
})
return resp, nil
Copy link
Member

Choose a reason for hiding this comment

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

Since this return statement is identical in both branches of the if statement, you can actually move it right after it to de-duplicate.

@alexsomesan
Copy link
Member

Also, please add a CHANGELOG entry (see workflow checks failure).

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

Successfully merging this pull request may close these issues.

An option ignore deletion of a resource
2 participants