loft-sh / jspolicy

jsPolicy - Easier & Faster Kubernetes Policies using JavaScript or TypeScript

Home Page:https://www.jspolicy.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mutate object in DELETE operation

AmirRezaSobhdel opened this issue · comments

I have set a finalizer to my resource and this resource will not be deleted before its finalizer is removed in my operator's reconciler.
(I am not using jspolicy controller, Im using go-operator-SDK for this purpose).
For UPDATE and CREATE operations Im using a jspolicy mutation to add request.userInfo.username to the annotations in metadata.
I am then using this annotation in my operator reconciler.

*** But for DELETE operation its not possible to mutate the object. The resource is still not deleted because it has a finalizer set to it.
I want to achieve the same functionality for the delete operation. am I missing something? can you add mutate support for DELETE operation?

@AmirRezaSobhdel thanks for creating this issue! Since DELETE does not modify the object besides setting the metadata.deletionTimestamp, this won't work with a mutating webhook according to my knowledge.

An alternative is to have a jspolicy controller that watches for deleted objects that have a certain finalizer and then remove those finalizers automatically.

@AmirRezaSobhdel did you get to try out the controller solution Fabian suggested above?

Closing this issue due to inactivity atm.
@AmirRezaSobhdel feel free to reach back out with more details in case it pops up again.