Skip to content

Commit 058307a

Browse files
committed
Prepare for release 0.79.0
Signed-off-by: clux <[email protected]>
1 parent b822ee6 commit 058307a

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

examples/dynamic_watcher.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use futures::{Stream, StreamExt, TryStreamExt};
22
use kube::{
3-
api::{Api, DynamicObject, GroupVersionKind, ListParams, ResourceExt},
4-
discovery::{self, ApiCapabilities, Scope},
5-
runtime::{metadata_watcher, watcher, WatchStreamExt},
6-
Client,
3+
api::{Api, DynamicObject, GroupVersionKind, ListParams, Resource, ResourceExt},
4+
runtime::{metadata_watcher, watcher, watcher::Event, WatchStreamExt},
75
};
86
use serde::de::DeserializeOwned;
97
use tracing::*;
@@ -13,7 +11,7 @@ use std::{env, fmt::Debug};
1311
#[tokio::main]
1412
async fn main() -> anyhow::Result<()> {
1513
tracing_subscriber::fmt::init();
16-
let client = Client::try_default().await?;
14+
let client = kube::Client::try_default().await?;
1715

1816
// If set will receive only the metadata for watched resources
1917
let watch_metadata = env::var("WATCH_METADATA").map(|s| s == "1").unwrap_or(false);
@@ -26,34 +24,31 @@ async fn main() -> anyhow::Result<()> {
2624
// Turn them into a GVK
2725
let gvk = GroupVersionKind::gvk(&group, &version, &kind);
2826
// Use API discovery to identify more information about the type (like its plural)
29-
let (ar, caps) = discovery::pinned_kind(&client, &gvk).await?;
27+
let (ar, _caps) = kube::discovery::pinned_kind(&client, &gvk).await?;
3028

3129
// Use the full resource info to create an Api with the ApiResource as its DynamicType
3230
let api = Api::<DynamicObject>::all_with(client, &ar);
31+
let lp = ListParams::default();
3332

3433
// Start a metadata or a full resource watch
3534
if watch_metadata {
36-
handle_events(metadata_watcher(api, ListParams::default()), caps).await?
35+
handle_events(metadata_watcher(api, lp)).await
3736
} else {
38-
handle_events(watcher(api, ListParams::default()), caps).await?
37+
handle_events(watcher(api, lp)).await
3938
}
40-
41-
Ok(())
4239
}
4340

44-
async fn handle_events<K: kube::Resource + Clone + Debug + Send + DeserializeOwned + 'static>(
45-
stream: impl Stream<Item = watcher::Result<watcher::Event<K>>> + Send + 'static,
46-
api_caps: ApiCapabilities,
41+
async fn handle_events<K: Resource + Clone + Debug + Send + DeserializeOwned + 'static>(
42+
stream: impl Stream<Item = watcher::Result<Event<K>>> + Send + 'static,
4743
) -> anyhow::Result<()> {
48-
// Fully compatible with kube-runtime
4944
let mut items = stream.applied_objects().boxed();
5045
while let Some(p) = items.try_next().await? {
51-
if api_caps.scope == Scope::Cluster {
52-
info!("saw {}", p.name_any());
46+
if let Some(ns) = p.namespace() {
47+
info!("saw {} in {ns}", p.name_any());
5348
} else {
54-
info!("saw {} in {}", p.name_any(), p.namespace().unwrap());
49+
info!("saw {}", p.name_any());
5550
}
51+
trace!("full obj: {p:?}");
5652
}
57-
5853
Ok(())
5954
}

0 commit comments

Comments
 (0)