kube icon indicating copy to clipboard operation
kube copied to clipboard

add general conditions::is_met helper to runtime::wait

Open clux opened this issue 4 years ago • 3 comments

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?

clux avatar Oct 24 '21 11:10 clux

Agreed with the general idea.. A few points though:

  1. Can't we just use DynamicObject internally, rather than going through the reserialization dance?
  2. IIRC value is a bool, not a string?
  3. Starting to think we might want to have a way to combine conditions…

nightkr avatar Oct 24 '21 11:10 nightkr

  1. ooh, yeah, good call. we should implement this for DynamicObject initially :-)
  2. 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
  3. yeah, a combinator there shouldn't be too hard!

clux avatar Oct 24 '21 11:10 clux

Ahh, fair enough.

nightkr avatar Oct 26 '21 11:10 nightkr