kube::runtime::wait

Trait Condition

Source
pub trait Condition<K> {
    // Required method
    fn matches_object(&self, obj: Option<&K>) -> bool;

    // Provided methods
    fn not(self) -> Not<Self>
       where Self: Sized { ... }
    fn and<Other>(self, other: Other) -> And<Self, Other>
       where Other: Condition<K>,
             Self: Sized { ... }
    fn or<Other>(self, other: Other) -> Or<Self, Other>
       where Other: Condition<K>,
             Self: Sized { ... }
}
Available on crate feature runtime only.
Expand description

A trait for condition functions to be used by await_condition

Note that this is auto-implemented for functions of type fn(Option<&K>) -> bool.

§Usage

use kube::runtime::wait::Condition;
use k8s_openapi::api::core::v1::Pod;
fn my_custom_condition(my_cond: &str) -> impl Condition<Pod> + '_ {
    move |obj: Option<&Pod>| {
        if let Some(pod) = &obj {
            if let Some(status) = &pod.status {
                if let Some(conds) = &status.conditions {
                    if let Some(pcond) = conds.iter().find(|c| c.type_ == my_cond) {
                        return pcond.status == "True";
                    }
                }
            }
        }
        false
    }
}

Required Methods§

Source

fn matches_object(&self, obj: Option<&K>) -> bool

Provided Methods§

Source

fn not(self) -> Not<Self>
where Self: Sized,

Returns a Condition that holds if self does not

§Usage
let condition: fn(Option<&()>) -> bool = |_| true;
assert!(condition.matches_object(None));
assert!(!condition.not().matches_object(None));
Source

fn and<Other>(self, other: Other) -> And<Self, Other>
where Other: Condition<K>, Self: Sized,

Returns a Condition that holds if self and other both do

§Usage
let cond_false: fn(Option<&()>) -> bool = |_| false;
let cond_true: fn(Option<&()>) -> bool = |_| true;
assert!(!cond_false.and(cond_false).matches_object(None));
assert!(!cond_false.and(cond_true).matches_object(None));
assert!(!cond_true.and(cond_false).matches_object(None));
assert!(cond_true.and(cond_true).matches_object(None));
Source

fn or<Other>(self, other: Other) -> Or<Self, Other>
where Other: Condition<K>, Self: Sized,

Returns a Condition that holds if either self or other does

§Usage
let cond_false: fn(Option<&()>) -> bool = |_| false;
let cond_true: fn(Option<&()>) -> bool = |_| true;
assert!(!cond_false.or(cond_false).matches_object(None));
assert!(cond_false.or(cond_true).matches_object(None));
assert!(cond_true.or(cond_false).matches_object(None));
assert!(cond_true.or(cond_true).matches_object(None));

Implementors§

Source§

impl<A, B, K> Condition<K> for And<A, B>
where A: Condition<K>, B: Condition<K>,

Source§

impl<A, B, K> Condition<K> for Or<A, B>
where A: Condition<K>, B: Condition<K>,

Source§

impl<A, K> Condition<K> for Not<A>
where A: Condition<K>,

Source§

impl<K, F> Condition<K> for F
where F: Fn(Option<&K>) -> bool,