pub async fn ensure_cluster_finalizer<T>(
client: &Client,
resource: &T,
finalizer: &str,
) -> Result<()>where
T: Resource<DynamicType = (), Scope = ClusterResourceScope> + ResourceExt + Clone + Debug + Serialize + for<'de> Deserialize<'de>,Expand description
Add a finalizer to a cluster-scoped resource if not already present.
This function is similar to ensure_finalizer() but works with cluster-scoped
resources that don’t have a namespace. It checks if the specified finalizer is
present on the resource, and adds it if missing.
§Arguments
client- Kubernetes client for accessing the APIresource- The cluster-scoped resource to add the finalizer tofinalizer- The finalizer string to add
§Returns
Returns Ok(()) if the finalizer was added or already present.
§Concurrency
The patch is a JSON Patch guarded by a test operation (mirroring
kube-runtime’s finalizer helper), so a racing writer’s finalizer edits are
never clobbered. On a conflict the API call fails and the returned error
triggers a requeue; the next reconciliation retries with fresh state.
§Errors
Returns an error if the API patch operation fails, including when a
concurrent writer modified metadata.finalizers and the guarded patch
was rejected.
§Example
const FINALIZER: &str = "bind9globalcluster.dns.firestoned.io/finalizer";
ensure_cluster_finalizer(&client, &cluster, FINALIZER).await.unwrap();