Expand description
Generic resource creation and update helpers for Kubernetes resources.
This module provides reusable functions for creating and updating Kubernetes resources with different strategies (Apply, Replace, or JSON Patch). It eliminates duplicate create/update code across reconcilers.
§Strategies
- Apply: Uses server-side apply (SSA) for idempotent updates
- Replace: Uses replace operation (suitable for resources like Deployments)
- Create with JSON Patch: Try create, fallback to JSON patch on
AlreadyExists
§Example
use bindy::reconcilers::resources::{create_or_apply, create_or_replace};
use k8s_openapi::api::core::v1::ServiceAccount;
use kube::Client;
use anyhow::Result;
async fn example(client: &Client, namespace: &str, sa: ServiceAccount) -> Result<()> {
// Using Apply strategy (server-side apply)
create_or_apply(
client,
namespace,
&sa,
"bindy-controller"
).await?;
Ok(())
}Functions§
- create_
or_ apply - Create or update a resource using server-side apply strategy.
- create_
or_ patch_ json - Create or update a resource using JSON patch on conflict.
- create_
or_ replace - Create or update a resource using replace strategy.