From e161079b562620ed1457abbcac3543648fac2d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natalie=20Klestrup=20R=C3=B6ijezon?= Date: Sat, 2 Nov 2024 13:36:05 +0100 Subject: [PATCH 1/2] Fix errors and warnings for the `.reflect_shared()` example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Natalie Klestrup Röijezon --- kube-runtime/src/utils/watch_ext.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kube-runtime/src/utils/watch_ext.rs b/kube-runtime/src/utils/watch_ext.rs index 67ebf0d0a..41a0da1b5 100644 --- a/kube-runtime/src/utils/watch_ext.rs +++ b/kube-runtime/src/utils/watch_ext.rs @@ -214,10 +214,10 @@ pub trait WatchStreamExt: Stream { /// [`ReflectHandle`]: crate::reflector::dispatcher::ReflectHandle /// ## Usage /// ```no_run - /// # use futures::{pin_mut, Stream, StreamExt, TryStreamExt}; + /// # use futures::StreamExt; /// # use std::time::Duration; /// # use tracing::{info, warn}; - /// use kube::{Api, Client, ResourceExt}; + /// use kube::{Api, ResourceExt}; /// use kube_runtime::{watcher, WatchStreamExt, reflector}; /// use k8s_openapi::api::apps::v1::Deployment; /// # async fn wrapper() -> Result<(), Box> { @@ -226,7 +226,7 @@ pub trait WatchStreamExt: Stream { /// let deploys: Api = Api::default_namespaced(client); /// let subscriber_buf_sz = 100; /// let (reader, writer) = reflector::store_shared::(subscriber_buf_sz); - /// let subscriber = &writer.subscribe().unwrap(); + /// let subscriber = writer.subscribe().unwrap(); /// /// tokio::spawn(async move { /// // start polling the store once the reader is ready From 71de1bd8402133353357a993f60a742e5e9da531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natalie=20Klestrup=20R=C3=B6ijezon?= Date: Sat, 2 Nov 2024 13:55:47 +0100 Subject: [PATCH 2/2] Also move the subscriber into a separate task, otherwise it will never run since the reflector looping forever MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Natalie Klestrup Röijezon --- kube-runtime/src/utils/watch_ext.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kube-runtime/src/utils/watch_ext.rs b/kube-runtime/src/utils/watch_ext.rs index 41a0da1b5..7ed636201 100644 --- a/kube-runtime/src/utils/watch_ext.rs +++ b/kube-runtime/src/utils/watch_ext.rs @@ -238,6 +238,13 @@ pub trait WatchStreamExt: Stream { /// } /// }); /// + /// tokio::spawn(async move { + /// // subscriber can be used to receive applied_objects + /// subscriber.for_each(|obj| async move { + /// info!("saw in subscriber {}", &obj.name_any()) + /// }).await; + /// }); + /// /// // configure the watcher stream and populate the store while polling /// watcher(deploys, watcher::Config::default()) /// .reflect_shared(writer) @@ -250,11 +257,6 @@ pub trait WatchStreamExt: Stream { /// }) /// .await; /// - /// // subscriber can be used to receive applied_objects - /// subscriber.for_each(|obj| async move { - /// info!("saw in subscriber {}", &obj.name_any()) - /// }).await; - /// /// # Ok(()) /// # } /// ```