message: Add functions for runtime API discovery
diff: @@ -16,7 +16,7 @@ use crate::{
  use bytes::Bytes;
  use either::{Either, Left, Right};
  use futures::{self, Stream, TryStream, TryStreamExt};
  -use http::{self, StatusCode};
  +use http::{self, Request, StatusCode};
  use serde::{de::DeserializeOwned, Deserialize};
  use serde_json::{self, Value};
  @@ -268,6 +268,45 @@ impl Client {
  Ok(stream.map_ok(futures::stream::iter).try_flatten())
  }
  +
  + /// Returns apiserver version.
  + async fn apiserver_version(&self) -> Result<k8s_openapi::apimachinery::pkg::version::Info> {
  + self.request(Request::builder().uri("/version").body(Vec::new())?)
  + .await
  + }
  +
  + /// Lists api groups that apiserver serves.
  + async fn list_api_groups(&self) -> Result<k8s_openapi::apimachinery::pkg::apis::meta::v1::APIGroupList> {
  + self.request(Request::builder().uri("/apis").body(Vec::new())?)
  + .await
  + }
  +
  + /// Lists resources served in gived API group.
  + async fn list_api_group_resources(
  + &self,
  + group: &str,
  + version: &str,
  + ) -> Result<k8s_openapi::apimachinery::pkg::apis::meta::v1::APIResourceList> {
  + let url = format!("/apis/{}/{}", group, version);
  + self.request(Request::builder().uri(url).body(Vec::new())?).await
  + }
  +
  + /// Lists versions of `core` a.k.a. `""` API group.
  + async fn list_core_api_versions(
  + &self,
  + ) -> Result<k8s_openapi::apimachinery::pkg::apis::meta::v1::APIVersions> {
  + self.request(Request::builder().uri("/api").body(Vec::new())?)
  + .await
  + }
  +
  + /// Lists resources served in particular `core` group version.
  + async fn list_core_api_resources(
  + &self,
  + version: &str,
  + ) -> Result<k8s_openapi::apimachinery::pkg::apis::meta::v1::APIResourceList> {
  + let url = format!("/api/{}", version);
  + self.request(Request::builder().uri(url).body(Vec::new())?).await
  + }
  }
  /// Kubernetes returned error handling
  