Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document potential silent failure when patching resources #1262

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions kube-core/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ impl PostParams {
///
/// See [kubernetes patch docs](https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment) for the older patch types.
///
/// Note that applying an invalid patch will **not** always return an error. See an example of such a case below.
///
/// Note that patches have different effects on different fields depending on their merge strategies.
/// These strategies are configurable when deriving your [`CustomResource`](https://docs.rs/kube-derive/*/kube_derive/derive.CustomResource.html#customizing-schemas).
///
Expand Down Expand Up @@ -473,6 +475,44 @@ impl PostParams {
/// };
/// let patch = Patch::Apply(&r);
/// ```
/// # Invalid Patches
///
/// In this example patch contains a `PodSpec` and **not** a complete or partial `Pod`.
/// This patch is invalid as the full structure of a resource is required.
/// The invalid patch will be accepted by the cluster, but no changes will be made.
///
/// Using serve-side style [`Apply`](Patch::Apply) patches mitigates this issue.
///
/// ```no_run
/// use k8s_openapi::api::core::v1::{Pod, PodSpec};
/// use kube::{Api, api::{PatchParams, Patch}};
///
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client = kube::Client::try_default().await?;
/// let pods: Api<Pod> = Api::namespaced(client, "apps");
/// let pp = PatchParams::default();
///
/// let invalid_patch: PodSpec = serde_json::from_value(serde_json::json!({
/// "activeDeadlineSeconds": 5
/// }))?;
///
/// // This will have no effect on mypod.
/// pods.patch("mypod", &pp, &Patch::Strategic(invalid_patch)).await?;
///
/// let valid_patch: Pod = serde_json::from_value(serde_json::json!({
/// "spec": {
/// "activeDeadlineSeconds": 5
/// }
/// }))?;
///
/// // This will set activeDeadlineSeconds to 5.
/// pods.patch("mypod", &pp, &Patch::Strategic(valid_patch)).await?;
///
/// # Ok(())
/// # }
/// ```
///
///
#[non_exhaustive]
#[derive(Debug, PartialEq, Clone)]
pub enum Patch<T: Serialize> {
Expand Down
Loading