Skip to main content

Predicate

Trait Predicate 

Source
pub trait Predicate<K> {
    // Required method
    fn hash_property(&self, obj: &K) -> Option<u64>;

    // Provided methods
    fn fallback<F: Predicate<K>>(self, f: F) -> Fallback<Self, F>
       where Self: Sized { ... }
    fn combine<F: Predicate<K>>(self, f: F) -> Combine<Self, F>
       where Self: Sized { ... }
}
Expand description

A predicate is a hasher of Kubernetes objects stream filtering

Required Methods§

Source

fn hash_property(&self, obj: &K) -> Option<u64>

A predicate only needs to implement optional hashing when keys exist

Provided Methods§

Source

fn fallback<F: Predicate<K>>(self, f: F) -> Fallback<Self, F>
where Self: Sized,

Returns a Predicate that falls back to an alternate property if the first does not exist

The alternate predicate is only used when the first returns None, not when its hash is unchanged. In particular, generation.fallback(resource_version) can still suppress deletions for objects with an unchanged generation.

Generation support generally depends on the resource type: Deployments and custom resources normally populate it, while ConfigMaps and Secrets normally do not. Thus, generation.fallback(resource_version) is useful as a shared policy across resource types, but the fallback is redundant for a type known to always provide generation. Generation is not normally a field that appears and disappears over an object’s lifetime, though support can vary by API implementation and version.

Persisted objects returned by ordinary API-server list/watch requests have a resource version, so reversing the order to resource_version.fallback(generation) generally makes the generation fallback redundant. Locally constructed objects and non-persisted API responses need not have a resource version.

§Usage
use kube::runtime::{predicates, Predicate};
let pred = predicates::generation.fallback(predicates::resource_version);
blah::<Pod>(pred);
Source

fn combine<F: Predicate<K>>(self, f: F) -> Combine<Self, F>
where Self: Sized,

Returns a Predicate that combines all available hashes

§Usage
use kube::runtime::{predicates, Predicate};
let pred = predicates::labels.combine(predicates::annotations);
blah::<Pod>(pred);

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<K, F: Fn(&K) -> Option<u64>> Predicate<K> for F