<p>My <a href="https://sdk.operatorframework.io/docs/building-operators/golang/" rel="nofollow noreferrer">Go-based</a> custom resource operator needs some cleanup operations before it is deleted. It has to delete a specific znode from the ZooKeeper.</p>
<p>These operations must not be executed before regenerating resource. They have to be executed with the user's deletion command only. Thus, I can't use an ordinary prestop-hook.</p>
<p>Can I execute a prestop hook only before deletion? Or is there any other way for the operator to execute cleanup logic before the resource is deleted?</p>

Park Beomsu
<p><strong>Can I execute a prestop hook only before deletion?</strong></p>
<p>This is the whole purpose of the <code>preStop</code> hook. A pre-stop hook is executed immediately before the container is terminated. Once there as terminatino signal from API, Kubelet runs the pre-stop hook and afterwards sends the SIGTERM signal to the process.</p>
<p>Its design was to perform arbitrary operations before shutdown without having to implement those operations in the application itself. This is especially useful if you run some 3rd party app which code you can't modify.</p>
<p>Now the call the to terminate pod and invoke the hook can be due to API request, probes failed, resource contention and others.</p>
<p>For more reading please visit: <a href="https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/" rel="nofollow noreferrer">Container Lifecycle Hooks</a></p>
