Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add labels filter support #243

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading