Skip to content

Commit

Permalink
feat: add labels filter support
Browse files Browse the repository at this point in the history
  • Loading branch information
Bowser1704 authored and davidB committed Sep 1, 2024
1 parent b7c1392 commit 8bdd740
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,15 @@ fn accept_resource(name: &str, resource_filter: &[String]) -> bool {
pub async fn collect_from_nodes(
client: kube::Client,
resources: &mut Vec<Resource>,
selector: &Option<String>,
) -> Result<(), Error> {
let api_nodes: Api<Node> = Api::all(client);
let mut lp = ListParams::default();
if let Some(label) = &selector {
lp = lp.labels(label);
}
let nodes = api_nodes
.list(&ListParams::default())
.list(&lp)
.await
.map_err(|source| Error::KubeError {
context: "list nodes".to_string(),
Expand Down Expand Up @@ -574,6 +579,10 @@ pub struct CliOpts {
#[arg(short, long, value_parser)]
pub namespace: Option<String>,

/// Show only resource match this label selector
#[arg(short = 'l', long, value_parser)]
pub selector: Option<String>,

/// Force to retrieve utilization (for cpu and memory), require to have metrics-server https://github.com/kubernetes-sigs/metrics-server
#[arg(short = 'u', long, value_parser)]
pub utilization: bool,
Expand Down Expand Up @@ -666,7 +675,7 @@ pub async fn new_client(cli_opts: &CliOpts) -> Result<kube::Client, Error> {
pub async fn do_main(cli_opts: &CliOpts) -> Result<(), Error> {
let client = new_client(cli_opts).await?;
let mut resources: Vec<Resource> = vec![];
collect_from_nodes(client.clone(), &mut resources).await?;
collect_from_nodes(client.clone(), &mut resources, &cli_opts.selector).await?;
collect_from_pods(client.clone(), &mut resources, &cli_opts.namespace).await?;

let show_utilization = if cli_opts.utilization {
Expand Down

0 comments on commit 8bdd740

Please sign in to comment.