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 deletion not found handling in the delete operation and adding related tests #2592

Merged
merged 4 commits into from
Oct 1, 2024

Conversation

JaylonmcShan03
Copy link
Contributor

@JaylonmcShan03 JaylonmcShan03 commented Sep 25, 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?

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'
jaylon.mcshan@jaylon terraform-provider-kubernetes % go test -v -tags=acceptance ./manifest/test/acceptance -run TestKubernetesManifest_DeletionNotFound

2024/09/25 09:53:50 Testing against Kubernetes API version: v1.30.0
=== RUN   TestKubernetesManifest_DeletionNotFound
    delete_not_found_test.go:35: Verifying if namespace tf-acc-test-vkxthtphka exists
    delete_not_found_test.go:54: Applying Terraform configuration to create ConfigMap
    delete_not_found_test.go:64: Terraform state: &{false 1.0 1.8.3 0x14000b787d0 []}
    delete_not_found_test.go:68: Checking if ConfigMap tf-acc-test-bypcuockzy in namespace tf-acc-test-vkxthtphka was created
2024-09-25T09:53:52.894-0500 [WARN]  sdk.proto: Response contains warning diagnostic: tf_rpc=ApplyResourceChange diagnostic_detail="The resource \"tf-acc-test-bypcuockzy\" was not found in the Kubernetes API. This may be due to the resource being already deleted." diagnostic_severity=WARNING diagnostic_summary="Resource \"tf-acc-test-bypcuockzy\" was already deleted" tf_resource_type=kubernetes_manifest tf_proto_version=5.6 tf_provider_addr=registry.terraform.io/hashicorp/kubernetes tf_req_id=1b6b3752-6308-e766-046e-1e392d2e3bcf
--- PASS: TestKubernetesManifest_DeletionNotFound (2.63s)
PASS
ok      github.com/hashicorp/terraform-provider-kubernetes/manifest/test/acceptance     3.421s
...

Release Note

Release note for CHANGELOG:

...
handling "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.

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

@BBBmau BBBmau added this to the v2.33.0 milestone Sep 25, 2024
@@ -0,0 +1,3 @@
```release-note:enhancement
handling "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.
Copy link
Member

Choose a reason for hiding this comment

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

I would add a reference to the manifest resource here, to make it clear this change only affects its behaviour.

Suggested change
handling "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.
`kubernetes_manifest` - handling "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.

Summary: fmt.Sprintf("Error deleting resource %s: %s", rname, err),
Detail: err.Error(),
})
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.

I think this return line needs to go outside of the else block.

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, only a couple of small tidy-ups needed. See my comments above.

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 great, @JaylonmcShan03!
Thanks for taking care of this issue!

@JaylonmcShan03 JaylonmcShan03 merged commit c6c0a76 into main Oct 1, 2024
64 checks passed
@JaylonmcShan03 JaylonmcShan03 deleted the tolerating-404-errors-on-the-delete-operation branch October 1, 2024 14:46
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
3 participants