Struct kube_client::discovery::ApiGroup [−][src]
pub struct ApiGroup { /* fields omitted */ }client only.Expand description
Describes one API groups collected resources and capabilities.
Each ApiGroup contains all data pinned to a each version.
In particular, one data set within the ApiGroup for "apiregistration.k8s.io"
is the subset pinned to "v1"; commonly referred to as "apiregistration.k8s.io/v1".
If you know the version of the discovered group, you can fetch it directly:
use kube::{Client, api::{Api, DynamicObject}, discovery, ResourceExt};
#[tokio::main]
async fn main() -> Result<(), kube::Error> {
let client = Client::try_default().await?;
let apigroup = discovery::group(&client, "apiregistration.k8s.io").await?;
for (apiresource, caps) in apigroup.versioned_resources("v1") {
println!("Found ApiResource {}", apiresource.kind);
}
Ok(())
}But if you do not know this information, you can use ApiGroup::preferred_version_or_latest.
Whichever way you choose the end result is something describing a resource and its abilities:
Vec<(ApiResource,ApiCapabilities)>` :: for all resources in a versioned ApiGroup(ApiResource, ApiCapabilities):: for a single kind under a versioned ApiGroud
These two types: ApiResource, and ApiCapabilities
should contain the information needed to construct an Api and start querying the kubernetes API.
You will likely need to use DynamicObject as the generic type for Api to do this,
as well as the ApiResource for the DynamicType for the Resource trait.
use kube::{Client, api::{Api, DynamicObject}, discovery, ResourceExt};
#[tokio::main]
async fn main() -> Result<(), kube::Error> {
let client = Client::try_default().await?;
let apigroup = discovery::group(&client, "apiregistration.k8s.io").await?;
let (ar, caps) = apigroup.recommended_kind("APIService").unwrap();
let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
for service in api.list(&Default::default()).await? {
println!("Found APIService: {}", service.name());
}
Ok(())
}Implementations
Public ApiGroup interface
Core group name
Returns served versions (e.g. ["v1", "v2beta1"]) of this group.
This list is always non-empty, and sorted in the following order:
- Stable versions (with the last being the first)
- Beta versions (with the last being the first)
- Alpha versions (with the last being the first)
- Other versions, alphabetically
in accordance with kubernetes version priority.
Returns preferred version for working with given group.
Returns the preferred version or latest version for working with given group.
If server does not recommend one, we pick the “most stable and most recent” version in accordance with kubernetes version priority.
Returns the resources in the group at an arbitrary version string.
If the group does not support this version, the returned vector is empty.
If you are looking for the api recommended list of resources, or just on particular kind
consider ApiGroup::recommended_resources or ApiGroup::recommended_kind instead.
Returns the recommended (preferred or latest) versioned resources in the group
use kube::{Client, api::{Api, DynamicObject}, discovery::{self, verbs}, ResourceExt};
#[tokio::main]
async fn main() -> Result<(), kube::Error> {
let client = Client::try_default().await?;
let apigroup = discovery::group(&client, "apiregistration.k8s.io").await?;
for (ar, caps) in apigroup.recommended_resources() {
if !caps.supports_operation(verbs::LIST) {
continue;
}
let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
for inst in api.list(&Default::default()).await? {
println!("Found {}: {}", ar.kind, inst.name());
}
}
Ok(())
}This is equivalent to taking the ApiGroup::versioned_resources at the ApiGroup::preferred_version_or_latest.
Returns the recommended version of the kind in the recommended resources (if found)
use kube::{Client, api::{Api, DynamicObject}, discovery, ResourceExt};
#[tokio::main]
async fn main() -> Result<(), kube::Error> {
let client = Client::try_default().await?;
let apigroup = discovery::group(&client, "apiregistration.k8s.io").await?;
let (ar, caps) = apigroup.recommended_kind("APIService").unwrap();
let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
for service in api.list(&Default::default()).await? {
println!("Found APIService: {}", service.name());
}
Ok(())
}This is equivalent to filtering the ApiGroup::versioned_resources at ApiGroup::preferred_version_or_latest against a chosen kind.
Auto Trait Implementations
impl RefUnwindSafe for ApiGroup
impl UnwindSafe for ApiGroup
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more