Incorrect version specified in apply patch #1087
Replies: 4 comments 3 replies
-
Looks like your |
Beta Was this translation helpful? Give feedback.
-
I think it's #[derive(Clone, Serialize, Deserialize)]
pub struct MinimalManifest {
pub name: String,
pub version: String,
}
type MinimalMfCrd = Object<MinimalManifest, ManifestStatus>;
...
/// Status object for shipcatmanifests crd
///
/// All fields optional, but we try to ensure all fields exist.
#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct ManifestStatus {
/// Detailed individual conditions, emitted as they happen during apply
#[serde(default)]
pub conditions: Conditions,
/// A more easily readable summary of why the conditions are what they are
#[serde(default)]
pub summary: Option<ConditionSummary>,
} Where does |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hmmmmmmmm I think after banging my head against the walls I figured it out, and I think I've been a bit thick... @clux you have experience with this codebase, I believe you actually wrote the lines I'm debugging haha. But that was years ago and things improved since then. Years ago, this was the state of the code: use kube::{
api::{Api, DeleteParams, ListParams, LogParams, Object, ObjectList, PatchParams, Resource},
client::APIClient,
};
pub struct ShipKube {
mfs: Resource,
client: APIClient,
pub(crate) applier: Applier,
api: Api<ShipcatManifest>,
name: String,
namespace: String,
}
impl ShipKube {
// helper to send a merge patch
pub async fn patch(&self, data: &serde_json::Value) -> Result<()> {
let pp = PatchParams::default();
// Run this patch with a smaller deserialization surface via kube::Resource
// kube::Api would force ShipcatManifest fully valid here
// and this would prevent status updates during schema changes.
let req = self
.mfs
.patch_status(&self.name, &pp, serde_json::to_vec(data)?)
.map_err(ErrorKind::KubeError)?;
let o = self
.client
.request::<MinimalMfCrd>(req) // <- difference from using Api::patch_status
.await
.map_err(ErrorKind::KubeError)?;
debug!("Patched status: {:?}", o.status);
Ok(())
}
}
But when I ported the code to a more recent api of the /// Interface for dealing with kubernetes shipcatmanifests
pub struct ShipKube {
mfs: Request,
client: Client,
pub(crate) applier: Applier,
api: Api<ShipcatManifest>,
name: String,
namespace: String,
}
/// Entry points for shipcat::apply, and shipcat::status
impl ShipKube {
pub async fn new_within(svc: &str, ns: &str) -> Result<Self> {
// hide the client in here -> Api resource for now (not needed elsewhere)
let client = make_client().await?;
// https://github.com/kube-rs/kube/pull/474/files
let url = ShipcatManifest::url_path(&(), Some(ns));
let mfs = Request::new(url);
let api = Api::namespaced(client.clone(), ns);
Ok(Self {
name: svc.to_string(),
namespace: ns.to_string(),
applier: Applier::infer(),
api,
client,
mfs,
})
}
}
// helper to send a merge patch
pub async fn patch(&self, data: &serde_json::Value) -> Result<()> {
let mut pp = PatchParams::default();
pp.field_manager = Some(String::from("application/apply-patch+json"));
println!("DATA: {:?}", data);
self.mfs.patch_subresource("status", &self.name, &pp, &Patch::Apply(data)).map_err(ErrorKind::KubeApi)?;
Ok(())
} I tried it and it seems to work. This is specific to my company but in the console output I can see: DATA: Object {"status": Object {"conditions": Object {"rolledout": Object {"status": Bool(true), "reason": Null, "message": Null, "lastTransitionTime": String("2022-11-20T17:01:30Z"), "source": Object {"name": String("jean-patrickfrancoia"), "url": Null}}}, "summary": Object {"lastRollout": String("2022-11-20T17:01:30Z"), "lastSuccessfulRollout": String("2022-11-20T17:01:30Z"), "lastFailureReason": Null, "lastAction": String("Rollout"), "lastSuccessfulRolloutVersion": String("0.171.12")}}} Does that seem tangible to you? |
Beta Was this translation helpful? Give feedback.
-
Current and expected behavior
I have a function that is supposed to patch a resource:
But whenever this function is called, I'm getting this error:
It looks like my patch doesn't provide a version? To be honest I'm really confused about what's happening here.
Possible solution
No response
Additional context
The content of
data
:Environment
Configuration and features
Affected crates
No response
Would you like to work on fixing this bug?
No response
Beta Was this translation helpful? Give feedback.
All reactions