create_or_apply

Function create_or_apply 

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

Create or update a resource using server-side apply strategy.

This function checks if the resource exists. If it does, it patches using server-side apply (SSA). Otherwise, it creates the resource.

Server-side apply is the recommended approach for managing resources in modern Kubernetes as it provides better conflict resolution and field ownership tracking.

§Arguments

  • client - Kubernetes API client
  • namespace - Namespace where the resource should be created/updated
  • resource - The resource to create or update
  • field_manager - Field manager name for server-side apply (e.g., “bindy-controller”)

§Returns

Returns Ok(()) if the operation succeeded.

§Errors

Returns an error if:

  • The resource has no name in its metadata
  • API operations fail

§Example

create_or_apply(client, namespace, &sa, "bindy-controller").await.unwrap();