-
Notifications
You must be signed in to change notification settings - Fork 332
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
Using patch to set finalizers might lead to having reconciled resources that are never finalized #2828
Comments
cc @dprotaso |
What events appeared on the informer watch in this instance? |
I don't exactly know but every event goes through the same generated reconciler: https://github.com/knative-extensions/eventing-kafka-broker/blob/5c4461d0a616401a983136602d09a95fbff4e514/control-plane/pkg/reconciler/consumer/controller.go#L71C2-L71C81 consumerInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) |
Can't really recommend anything if we don't know what the API watch is reporting |
but even if the informer sees the delete event, we cannot rely on that since it's not guaranteed to be observed if controllers are down in that time period, right? |
I think the problem here is that the way we set |
I'm wondering if the informer even gets an event after the finalizer is added
That's a good point - we can add the resourceVersion to the patch to ensure optimistic concurrency |
Is that possible? From https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/
|
I think we can just emit an update, I can't see a reason to use Patch there, I've tried on one generated reconciler index ffc2b022..9df5a804 100644
--- a/client/injection/apiextensions/reconciler/apiextensions/v1/customresourcedefinition/reconciler.go
+++ b/client/injection/apiextensions/reconciler/apiextensions/v1/customresourcedefinition/reconciler.go
@@ -20,7 +20,6 @@ package customresourcedefinition
import (
context "context"
- json "encoding/json"
fmt "fmt"
zap "go.uber.org/zap"
@@ -364,25 +363,14 @@ func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource
finalizers = existingFinalizers.List()
}
- mergePatch := map[string]interface{}{
- "metadata": map[string]interface{}{
- "finalizers": finalizers,
- "resourceVersion": existing.ResourceVersion,
- },
- }
-
- patch, err := json.Marshal(mergePatch)
- if err != nil {
- return resource, err
- }
+ existing.Finalizers = finalizers
- patcher := r.Client.ApiextensionsV1().CustomResourceDefinitions()
+ updater := r.Client.ApiextensionsV1().CustomResourceDefinitions()
- resourceName := resource.Name
- updated, err := patcher.Patch(ctx, resourceName, types.MergePatchType, patch, metav1.PatchOptions{})
+ updated, err := updater.Update(ctx, existing, metav1.UpdateOptions{})
if err != nil {
r.Recorder.Eventf(existing, corev1.EventTypeWarning, "FinalizerUpdateFailed",
- "Failed to update finalizers for %q: %v", resourceName, err)
+ "Failed to update finalizers for %q: %v", existing.Name, err)
} else {
r.Recorder.Eventf(updated, corev1.EventTypeNormal, "FinalizerUpdate",
"Updated %q finalizers", resource.GetName()) |
Yup - we had it in serving but dropped it because we didn't need the guarantees ref: knative/serving#6211 You can also add a |
hmm, we use the same idea here in pkg
|
You can test it out - it was working beforehand - hence the update conflicts and markus wanting to remove it |
In that case, I can't really explain why the finalization wasn't done and the object was deleted without being properly finalized |
But as you see from the logs, while we were reconciling the object, it was deleted without finalization and that's why the status update failed with "resource not found" |
I think I need more data to know what the right approach is - given what you said then I don't think your solution of doing an update will solve this problem. I'd reach out to the sig-api-machinery on the Kubernetes slack for input. |
This issue is stale because it has been open for 90 days with no |
Expected Behavior
Once
ReconcileKind
is called, it should be guaranteed thatFinalizeKind
will be calledActual Behavior
When a resource is created and very quickly deleted while is being reconciled, the
FinalizeKind
method is never called even though theReconcileKind
method was called once.Here are the logs relevant to the issue:
Reconcile(key string)
method)PATCH
FinalizeKind
is never called (I think) because the finalizer at the time of the deletion wasn't present, so the object is goneController logs:
Webhook logs deleted action on resource twice:
Note: the timestamps are coming from different pods, so clock skew might be present
Steps to Reproduce the Problem
This is generally hard to reproduce consistently but you would need to:
Additional Info
/kind bug
The text was updated successfully, but these errors were encountered: