Created
November 27, 2023 14:15
-
-
Save alpeb/d7d7a2f50e57267d3782ee13e23d0a4f to your computer and use it in GitHub Desktop.
linkerd-reinitialize-pods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use anyhow::{bail, Result}; | |
use clap::Parser; | |
use futures_util::StreamExt; | |
use kube::runtime::watcher; | |
use k8s_openapi::api::core::v1::Pod; | |
#[derive(Parser)] | |
#[command(version)] | |
struct Args { | |
#[arg( | |
long, | |
env = "LINKERD_REINITIALIZE_PODS_LOG_LEVEL", | |
default_value = "linkerd=info,warn" | |
)] | |
log_level: kubert::LogFilter, | |
#[arg(long, default_value = "plain")] | |
log_format: kubert::LogFormat, | |
#[command(flatten)] | |
client: kubert::ClientArgs, | |
#[command(flatten)] | |
admin: kubert::AdminArgs, | |
} | |
#[tokio::main] | |
async fn main() -> Result<()> { | |
let Args { | |
log_level, | |
log_format, | |
client, | |
admin, | |
} = Args::parse(); | |
let mut runtime = kubert::Runtime::builder() | |
.with_log(log_level, log_format) | |
.with_admin(admin) | |
.with_client(client) | |
.build() | |
.await?; | |
let pod_evts = runtime.watch_all::<Pod>(watcher::Config::default().labels("linkerd.io/control-plane-ns")); | |
tokio::spawn(async { | |
tokio::pin!(pod_evts); | |
while let Some(watcher::Event::Applied(pod)) = pod_evts.next().await { | |
//while let Some(pod) = pod_evts.next().await { | |
tracing::info!(?pod); | |
} | |
}); | |
// Block the main thread on the shutdown signal. Once it fires, wait for the background tasks to | |
// complete before exiting. | |
if runtime.run().await.is_err() { | |
bail!("aborted"); | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment