kube icon indicating copy to clipboard operation
kube copied to clipboard

Document potential silent failure when patching resources

Open jmintb opened this issue 1 year ago • 4 comments

Based on experiments performed in #1153 it appears to be possible to submit an invalid patch and not receive an error. This PR documents this behavior and also serves to discuss and verify what is happening. The relevant thread starts here.

Example taking form the updated docs:

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(())
 }

jmintb avatar Jul 22 '23 13:07 jmintb