Skip to content

Commit b9ca591

Browse files
committed
Document silent failure when patching resources
Signed-off-by: Jessie Chatham Spencer <[email protected]>
1 parent a9f1a4f commit b9ca591

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

kube-core/src/params.rs

+40
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ impl PostParams {
444444
///
445445
/// 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.
446446
///
447+
/// Note that applying an invalid patch will **not** always return an error. See an example of such a case below.
448+
///
447449
/// Note that patches have different effects on different fields depending on their merge strategies.
448450
/// These strategies are configurable when deriving your [`CustomResource`](https://docs.rs/kube-derive/*/kube_derive/derive.CustomResource.html#customizing-schemas).
449451
///
@@ -473,6 +475,44 @@ impl PostParams {
473475
/// };
474476
/// let patch = Patch::Apply(&r);
475477
/// ```
478+
/// # Invalid Patches
479+
///
480+
/// In this example patch contains a `PodSpec` and **not** a complete or partial `Pod`.
481+
/// This patch is invalid as the full structure of a resource is required.
482+
/// The invalid patch will be accepted by the cluster, but no changes will be made.
483+
///
484+
/// Using serve-side style [`Apply`](Patch::Apply) patches mitigates this issue.
485+
///
486+
/// ```no_run
487+
/// use k8s_openapi::api::core::v1::{Pod, PodSpec};
488+
/// use kube::{Api, api::{PatchParams, Patch}};
489+
///
490+
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
491+
/// # let client = kube::Client::try_default().await?;
492+
/// let pods: Api<Pod> = Api::namespaced(client, "apps");
493+
/// let pp = PatchParams::default();
494+
///
495+
/// let invalid_patch: PodSpec = serde_json::from_value(serde_json::json!({
496+
/// "activeDeadlineSeconds": 5
497+
/// }))?;
498+
///
499+
/// // This will have no effect on mypod.
500+
/// pods.patch("mypod", &pp, &Patch::Strategic(invalid_patch)).await?;
501+
///
502+
/// let valid_patch: Pod = serde_json::from_value(serde_json::json!({
503+
/// "spec": {
504+
/// "activeDeadlineSeconds": 5
505+
/// }
506+
/// }))?;
507+
///
508+
/// // This will set activeDeadlineSeconds to 5.
509+
/// pods.patch("mypod", &pp, &Patch::Strategic(valid_patch)).await?;
510+
///
511+
/// # Ok(())
512+
/// # }
513+
/// ```
514+
///
515+
///
476516
#[non_exhaustive]
477517
#[derive(Debug, PartialEq, Clone)]
478518
pub enum Patch<T: Serialize> {

0 commit comments

Comments
 (0)