kube
kube copied to clipboard
add general conditions::is_met helper to runtime::wait
would like to have a generic helper to the conditions module so we don't have to special case every condition matching thing in there. something like:
pub fn is_met<K: Resource>(condition: &str, required_value: &str) -> impl Condition<K> {
todo!()
}
unfortunately, the only way we can do it atm AFAIKT is to require Serialize + Deserialize, then use the serde derives to parse the object as yaml/json, then safely try to check if the path .spec.conditions path exists and contains an object with cont[r#type] == condition and return true if condition + path exists and cond[r#type].status == required_value.
long term though, i think we could do a trait from codegen like HasConditions: HasSpec (we already have HasSpec and HasStatus) that lets you reach into that path and get a vector of maps because then we could use that trait and not have to do a pointless serialize+deserialize.
we could do the simple hack as a stop-gap, but we could also do a trait for it already in kube-core. wdyt?
Agreed with the general idea.. A few points though:
- Can't we just use
DynamicObjectinternally, rather than going through the reserialization dance? - IIRC
valueis a bool, not a string? - Starting to think we might want to have a way to combine conditions…
- ooh, yeah, good call. we should implement this for
DynamicObjectinitially :-) - value is a strinigfied bool or tri-bool (possibly more), see https://docs.rs/k8s-openapi/0.13.1/k8s_openapi/api/apiserverinternal/v1alpha1/struct.StorageVersionCondition.html#structfield.status
- yeah, a combinator there shouldn't be too hard!
Ahh, fair enough.