ensure_finalizer

Function ensure_finalizer 

Source
pub async fn ensure_finalizer<T>(
    client: &Client,
    resource: &T,
    finalizer: &str,
) -> Result<()>
where T: Resource<DynamicType = (), Scope = NamespaceResourceScope> + ResourceExt + Clone + Debug + Serialize + for<'de> Deserialize<'de>,
Expand description

Add a finalizer to a resource if not already present.

This function checks if the specified finalizer is present on the resource, and adds it if missing. The operation is idempotent - calling it multiple times has no effect if the finalizer is already present.

§Arguments

  • client - Kubernetes client for accessing the API
  • resource - The resource to add the finalizer to
  • finalizer - 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 resource has no namespace (for namespaced resources)
  • The API patch operation fails, including when a concurrent writer modified metadata.finalizers and the guarded patch was rejected

§Example

const FINALIZER: &str = "bind9cluster.dns.firestoned.io/finalizer";
ensure_finalizer(&client, &cluster, FINALIZER).await.unwrap();