Function kube_runtime::wait::await_condition

source ·
pub async fn await_condition<K>(
    api: Api<K>,
    name: &str,
    cond: impl Condition<K>,
) -> Result<Option<K>, Error>
where K: Clone + Debug + Send + DeserializeOwned + Resource + 'static,
Expand description

Watch an object, and wait for some condition cond to return true.

cond is passed Some if the object is found, otherwise None.

The object is returned when the condition is fulfilled.

§Caveats

Keep in mind that the condition is typically fulfilled by an external service, which might not even be available. await_condition does not automatically add a timeout. If this is desired, wrap it in tokio::time::timeout.

§Errors

Fails if the type is not known to the Kubernetes API, or if the Api does not have permission to watch and list it.

Does not fail if the object is not found.

§Usage

use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition;
use kube::{Api, runtime::wait::{await_condition, conditions}};

let crds: Api<CustomResourceDefinition> = Api::all(client);
// .. create or apply a crd here ..
let establish = await_condition(crds, "foos.clux.dev", conditions::is_crd_established());
let _ = tokio::time::timeout(std::time::Duration::from_secs(10), establish).await?;