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.

§Errors

Returns an error if:

  • The resource has no namespace (for namespaced resources)
  • The API patch operation fails

§Example

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