message: add ns filter
diff: //! In this example we will implement something similar
  -//! to `kubectl get all --all`.
  +//! to `kubectl get all --all-namespaces`.
  use k8s_openapi::apimachinery::pkg::apis::meta::v1::APIResourceList;
  use kube::{
  @@ -16,6 +16,8 @@ async fn main() -> anyhow::Result<()> {
  let v = client.apiserver_version().await?;
  println!("api version: {:?}", v);
  + let ns_filter = std::env::var("NAMESPACE").ok();
  +
  // The following loops turn the /api or /apis listers into kube::api::Resource
  // objects which can be used to make dynamic api calls.
  // This is slightly awkward because of corev1 types
  @@ -30,44 +32,48 @@ async fn main() -> anyhow::Result<()> {
  .or_else(|| g.versions.first())
  .expect("preferred or versions exists");
  let apis = client.list_api_group_resources(&ver.group_version).await?;
  - dump_group(&client, &ver.group_version, apis).await?;
  + dump_group(&client, &ver.group_version, apis, ns_filter.as_deref()).await?;
  }
  // core/v1 has a legacy endpoint
  let coreapis = client.list_core_api_versions().await?;
  assert_eq!(coreapis.versions.len(), 1);
  let corev1 = client.list_core_api_resources(&coreapis.versions[0]).await?;
  - dump_group(&client, &coreapis.versions[0], corev1).await?;
  + dump_group(&client, &coreapis.versions[0], corev1, ns_filter.as_deref()).await?;
  Ok(())
  }
  -async fn dump_group(client: &Client, group_version: &str, apis: APIResourceList) -> anyhow::Result<()> {
  +async fn dump_group(
  + client: &Client,
  + group_version: &str,
  + apis: APIResourceList,
  + ns_filter: Option<&str>,
  +) -> anyhow::Result<()> {
  println!("{}", group_version);
  for ar in apis.resources {
  if !ar.verbs.contains(&"list".to_string()) {
  continue;
  }
  - if group_version.starts_with("discovery.k8s.io/") && ar.kind == "EndpointSlice" ||
  - group_version.starts_with("metrics.k8s.io/") {
  + if group_version.starts_with("discovery.k8s.io/") && ar.kind == "EndpointSlice"
  + || group_version.starts_with("metrics.k8s.io/")
  + {
  eprintln!("\tFIXME: skipping kind which would be otherwise incorrectly pluralized");
  continue;
  }
  println!("\t{}", ar.kind);
  - let api = DynamicResource::from_api_resource(&ar, &apis.group_version)
  - .into_api::<DynamicObject>(client.clone());
  + let mut resource = DynamicResource::from_api_resource(&ar, &apis.group_version);
  + if ar.namespaced {
  + if let Some(ns) = ns_filter {
  + resource = resource.within(ns);
  + }
  + }
  + let api = resource.into_api::<DynamicObject>(client.clone());
  let list = api.list(&Default::default()).await?;
  for item in list.items {
  let name = item.name();
  - let ns = item.namespace();
  - match ns {
  - Some(ns) => {
  - println!("\t\t{}/{}", ns, name);
  - }
  - None => {
  - println!("\t\t{}", name);
  - }
  - }
  + let ns = item.namespace().map(|s| s + "/").unwrap_or_default();
  + println!("\t\t{}{}", ns, name);
  }
  }
  