pub async fn handle_deletion<T>(
client: &Client,
resource: &T,
finalizer: &str,
) -> Result<()>where
T: Resource<DynamicType = (), Scope = NamespaceResourceScope> + ResourceExt + FinalizerCleanup + Clone + Debug + Serialize + for<'de> Deserialize<'de>,Expand description
Handle resource deletion with cleanup and finalizer removal.
This function orchestrates the complete deletion process:
- Logs that the resource is being deleted
- Calls the resource’s
cleanup()method to perform cleanup operations - Removes the finalizer to allow Kubernetes to delete the resource
This function should be called when a resource has a deletion timestamp and the finalizer is still present.
§Arguments
client- Kubernetes client for accessing the APIresource- The resource being deletedfinalizer- The finalizer string to check and remove
§Returns
Returns Ok(()) if cleanup and finalizer removal succeeded.
§Errors
Returns an error if:
- The cleanup operation fails
- The finalizer removal fails
If an error occurs, the finalizer will remain on the resource and deletion will be blocked until the operation succeeds on a subsequent reconciliation.
§Example
use bindy::reconcilers::finalizers::{handle_deletion, FinalizerCleanup};
use bindy::crd::Bind9Cluster;
use kube::Client;
use anyhow::Result;
const FINALIZER: &str = "bind9cluster.dns.firestoned.io/finalizer";
async fn reconcile(client: Client, cluster: Bind9Cluster) -> Result<()> {
if cluster.metadata.deletion_timestamp.is_some() {
return handle_deletion(&client, &cluster, FINALIZER).await;
}
// Normal reconciliation...
Ok(())
}