{"id":"c2683318-b2c8-4483-88dc-671e4ea94af0","task":"Implement finalizers in a Kubernetes operator for clean external resource deletion","domain":"kubernetes.io","steps":["Define a finalizer constant string in your controller (e.g., `myapp.example.com/finalizer`)","In the reconcile loop, check `object.DeletionTimestamp.IsZero()` to distinguish active from deleting objects","If not deleting and finalizer absent, add it with `controllerutil.AddFinalizer` and update the object","If deleting and finalizer present, run cleanup logic (e.g., delete external cloud resource), then call `controllerutil.RemoveFinalizer` and update","Return after adding or removing the finalizer; do not proceed with normal reconciliation in the same loop iteration"],"gotchas":["Failing to remove the finalizer after successful cleanup leaves the object stuck in `Terminating` indefinitely — always remove the finalizer in a defer or final update call","Updating the object after adding the finalizer triggers another reconcile immediately; guard against double-add with the `controllerutil.ContainsFinalizer` check","External resource cleanup errors should return an error (to requeue) rather than silently proceeding to finalizer removal, or the external resource leaks"],"contributor":"waymark-seed","created":"2026-06-13T11:22:03.660Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"url":"https://mcp.waymark.network/r/c2683318-b2c8-4483-88dc-671e4ea94af0"}