-
Notifications
You must be signed in to change notification settings - Fork 191
Verify resource deletion before removing finalizer #229
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1129,13 +1129,36 @@ func (r *resourceReconciler) deleteResource( | |
| latest, _ = r.patchResourceMetadataAndSpec(ctx, rm, current, latest) | ||
| } | ||
| if err != nil { | ||
| // NOTE: Delete() implementations that have asynchronously-completing | ||
| // deletions should return a RequeueNeededAfter. | ||
| return latest, err | ||
| } | ||
|
|
||
| // Now that external AWS service resources have been appropriately cleaned | ||
| // up, we remove the finalizer representing the CR is managed by ACK, | ||
| // Verify the AWS resource is actually deleted before removing the | ||
| // finalizer. Some AWS APIs return success immediately while the resource | ||
| // transitions through a "deleting" state. We need to ensure the resource | ||
| // is fully gone (ReadOne returns NotFound) before allowing the CR to be | ||
| // deleted from Kubernetes. | ||
| rlog.Enter("rm.ReadOne (verify deletion)") | ||
| _, verifyErr := rm.ReadOne(ctx, current) | ||
| rlog.Exit("rm.ReadOne (verify deletion)", verifyErr) | ||
| if verifyErr == nil { | ||
| // Resource still exists, requeue to wait for deletion to complete | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the second reconcile we may need to protect against sdkDelete returning an error if the AWS API returns a validation error when called on a deleting resource.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we'll probably need a both a |
||
| resForCondition := latest | ||
| if !ackcompare.IsNotNil(resForCondition) { | ||
| resForCondition = current | ||
| } | ||
| ackcondition.SetSynced(resForCondition, corev1.ConditionFalse, &condition.DeletingMessage, &condition.DeletingReason) | ||
| return resForCondition, requeue.NeededAfter( | ||
| errors.New(condition.DeletingMessage), | ||
| 15*time.Second, | ||
| ) | ||
| } | ||
| if verifyErr != ackerr.NotFound { | ||
| // Some other error occurred during verification, return it | ||
| return latest, verifyErr | ||
| } | ||
|
|
||
| // Now that external AWS service resources have been confirmed deleted, | ||
| // we remove the finalizer representing the CR is managed by ACK, | ||
| // allowing the CR to be deleted by the Kubernetes API server | ||
| if ackcompare.IsNotNil(latest) { | ||
| err = r.setResourceUnmanaged(ctx, rm, latest) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be good enough for most resources, but there could be cases where the AWS resource is still returned by ReadOne, but with a state indicating that deletion was successful. One example that comes to mind is JobRuns from emr-containers. We likely need to added a check for a "deleted" state similar to our
sycned:whencheck.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll also need to consider how this is rolled out since we'll need to have those checks in place before applying this to avoid these kinds of resources becoming stuck during deletion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware of those edge cases and willing to make a code-gen patch to support that. I just wanted to get a feel on this change, and alignment that this is something we want to support in ACK.