message: Rewrite dynamic api example
  This example now shows how one can use kube to inspect arbitrary
  resources.
diff: -#[macro_use] extern crate log;
  -use kube::{api::DynamicResource, Client};
  +//! In this example we will implement something similar
  +//! to `kubectl get all --all`.
  +
  +use k8s_openapi::apimachinery::pkg::apis::meta::v1::APIResourceList;
  +use kube::{
  + api::{DynamicObject, DynamicResource, Meta},
  + Client,
  +};
  #[tokio::main]
  async fn main() -> anyhow::Result<()> {
  @@ -8,7 +14,7 @@ async fn main() -> anyhow::Result<()> {
  let client = Client::try_default().await?;
  let v = client.apiserver_version().await?;
  - info!("api version: {:?}", v);
  + println!("api version: {:?}", v);
  // The following loops turn the /api or /apis listers into kube::api::Resource
  // objects which can be used to make dynamic api calls.
  @@ -18,31 +24,50 @@ async fn main() -> anyhow::Result<()> {
  // loop over all api groups (except core v1)
  let apigroups = client.list_api_groups().await?;
  for g in apigroups.groups {
  - info!("group: {}", g.name);
  - debug!("group: {:?}", g);
  let ver = g
  .preferred_version
  .as_ref()
  .or_else(|| g.versions.first())
  .expect("preferred or versions exists");
  - info!("polling: {} at {:?}", g.name, ver);
  let apis = client.list_api_group_resources(&ver.group_version).await?;
  - dbg!(&apis);
  - for ar in apis.resources {
  - let r = DynamicResource::from_api_resource(&ar, &apis.group_version).into_resource();
  - dbg!(r);
  - }
  + dump_group(&client, &ver.group_version, apis).await?;
  }
  // core/v1 has a legacy endpoint
  let coreapis = client.list_core_api_versions().await?;
  - for corever in coreapis.versions {
  - dbg!(&corever);
  - let apis = client.list_core_api_resources(&corever).await?;
  - debug!("Got {:?}", apis);
  - for cr in apis.resources {
  - dbg!(&cr);
  - let r = DynamicResource::from_api_resource(&cr, &apis.group_version).into_resource();
  - dbg!(r);
  +
  + 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?;
  +
  + Ok(())
  +}
  +
  +async fn dump_group(client: &Client, group_version: &str, apis: APIResourceList) -> 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/") {
  + 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 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);
  + }
  + }
  }
  }
  