Skip to content

Commit

Permalink
Change event watcher example to retry the connection
Browse files Browse the repository at this point in the history
Fixes kube-rs#1615

Signed-off-by: Natalie Klestrup Röijezon <[email protected]>
  • Loading branch information
nightkr committed Oct 24, 2024
1 parent ecbdafc commit a2fe71e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions examples/event_watcher.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::pin::pin;

use futures::TryStreamExt;
use futures::StreamExt;
use k8s_openapi::{
api::{core::v1::ObjectReference, events::v1::Event},
apimachinery::pkg::apis::meta::v1::Time,
Expand Down Expand Up @@ -45,12 +45,17 @@ async fn main() -> anyhow::Result<()> {
{
println!("{0:<6} {1:<15} {2:<55} {3}", "AGE", "REASON", "OBJECT", "MESSAGE");
}
while let Some(ev) = event_stream.try_next().await? {
let age = ev.creation_timestamp().map(format_creation).unwrap_or_default();
let reason = ev.reason.unwrap_or_default();
let obj = ev.regarding.and_then(format_objref).unwrap_or_default();
let note = ev.note.unwrap_or_default();
println!("{0:<6} {1:<15} {2:<55} {3}", age, reason, obj, note);
while let Some(ev) = event_stream.next().await {
match ev {
Ok(ev) => {
let age = ev.creation_timestamp().map(format_creation).unwrap_or_default();
let reason = ev.reason.unwrap_or_default();
let obj = ev.regarding.and_then(format_objref).unwrap_or_default();
let note = ev.note.unwrap_or_default();
println!("{0:<6} {1:<15} {2:<55} {3}", age, reason, obj, note);
}
Err(err) => eprintln!("{:?}", anyhow::Error::new(err)),
}
}
Ok(())
}
Expand Down

0 comments on commit a2fe71e

Please sign in to comment.