Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add predicates::resource_version #1221

Merged
merged 3 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions kube-runtime/src/utils/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ pub mod predicates {
obj.meta().generation.map(|g| hash(&g))
}

/// Hash the resource version of a Resource K
pub fn resource_version<K: Resource>(obj: &K) -> Option<u64> {
obj.meta().resource_version.as_ref().map(hash)
}

/// Hash the labels of a Resource K
pub fn labels<K: Resource>(obj: &K) -> Option<u64> {
Some(hash(obj.labels()))
Expand Down
12 changes: 6 additions & 6 deletions kube-runtime/src/utils/watch_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ pub trait WatchStreamExt: Stream {
/// # use futures::{pin_mut, Stream, StreamExt, TryStreamExt};
/// use kube::{Api, Client, ResourceExt};
/// use kube_runtime::{watcher, WatchStreamExt, predicates};
/// use k8s_openapi::api::core::v1::Pod;
/// use k8s_openapi::api::apps::v1::Deployment;
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client: kube::Client = todo!();
/// let pods: Api<Pod> = Api::default_namespaced(client);
/// let changed_pods = watcher(pods, watcher::Config::default())
/// let deploys: Api<Deployment> = Api::default_namespaced(client);
/// let changed_deploys = watcher(deploys, watcher::Config::default())
/// .applied_objects()
/// .predicate_filter(predicates::generation);
/// pin_mut!(changed_pods);
/// pin_mut!(changed_deploys);
///
/// while let Some(pod) = changed_pods.try_next().await? {
/// println!("saw Pod '{} with hitherto unseen generation", pod.name_any());
/// while let Some(d) = changed_deploys.try_next().await? {
/// println!("saw Deployment '{} with hitherto unseen generation", d.name_any());
/// }
/// # Ok(())
/// # }
Expand Down