Skip to content

Commit b808406

Browse files
committed
supports optional namespace filtering
1 parent f66591b commit b808406

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

‎src/main.rs‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,26 @@ struct Args {
251251
only: Vec<String>,
252252
#[arg(long)]
253253
exclude: Vec<String>,
254+
#[arg(short = 'n', long)]
255+
namespace: Vec<String>,
254256
output_dir: String,
255257
}
256258

257259
#[tokio::main]
258260
async fn main() -> anyhow::Result<()> {
259261
let args = Args::parse();
260262

263+
if args.namespace.iter().any(|n| n.is_empty()) {
264+
anyhow::bail!("--namespace must not be empty");
265+
}
266+
261267
let client = Client::try_default().await?;
262268
let discovery = Discovery::new(client.clone()).run().await?;
263-
let namespaces = get_namespaces(&client, &discovery).await?;
269+
let namespaces = if args.namespace.is_empty() {
270+
get_namespaces(&client, &discovery).await?
271+
} else {
272+
args.namespace.clone()
273+
};
264274

265275
let metadata = Metadata {
266276
kube_version: get_version(&client).await?,
@@ -310,6 +320,20 @@ async fn main() -> anyhow::Result<()> {
310320
}
311321
}
312322

323+
if items.is_empty()
324+
&& ar.plural == "namespaces"
325+
&& ar.group.is_empty()
326+
&& !args.namespace.is_empty()
327+
{
328+
let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
329+
for ns in &args.namespace {
330+
match api.get(ns).await {
331+
Ok(obj) => items.push(obj),
332+
Err(e) => println!("\tFailed to get namespace {}: {}", ns, e),
333+
}
334+
}
335+
}
336+
313337
if items.is_empty() {
314338
continue;
315339
}

0 commit comments

Comments
 (0)