Skip to content

Commit

Permalink
miette test
Browse files Browse the repository at this point in the history
seems like this could be a nice approach in general over anyhow
would be better if kube also implemented Diagnostic on its error though.

Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Jan 28, 2024
1 parent c1a1ab2 commit f105f92
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 13 deletions.
172 changes: 163 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread", "signal"]
elegant-departure = { version = "0.2.1", features = ["tokio"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
anyhow = "1.0.79"
serde = { version = "1.0.195", features = ["derive"] }
k8s-openapi = { version = "0.21.0", features = ["latest"] }
miette = { version = "5.10.0", features = ["fancy"] }

[dependencies.kube]
version = "0.88.0"
Expand Down
8 changes: 5 additions & 3 deletions version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use futures::{future, StreamExt};
use k8s_openapi::api::apps::v1::Deployment;
use kube::runtime::{reflector, watcher, WatchStreamExt};
use kube::{Api, Client, ResourceExt};
use miette::{IntoDiagnostic, Result};
use tracing::{debug, info, warn};

#[derive(serde::Serialize, Clone)]
Expand Down Expand Up @@ -50,19 +51,20 @@ async fn get_versions(State(store): State<Cache>) -> Json<Vec<Entry>> {
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
let client = Client::try_default().await?;
let client = Client::try_default().await.into_diagnostic()?;
let api: Api<Deployment> = Api::all(client);

let (reader, writer) = reflector::store();
let watch = reflector(writer, watcher(api, Default::default()))
.default_backoff()
.touched_objects()
.map(|x| x.into_diagnostic())
.for_each(|r| {
future::ready(match r {
Ok(o) => debug!("Saw {} in {}", o.name_any(), o.namespace().unwrap()),
Err(e) => warn!("watcher error: {e}"),
Err(e) => warn!("{e:?}"),
})
});

Expand Down

0 comments on commit f105f92

Please sign in to comment.