Skip to content

Commit

Permalink
add fn resources to return all resources in apigroup
Browse files Browse the repository at this point in the history
  • Loading branch information
imuxin committed Sep 23, 2022
1 parent 2821378 commit d74e585
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 1 addition & 6 deletions examples/kubectl.rs
Expand Up @@ -62,12 +62,7 @@ fn resolve_api_resource(discovery: &Discovery, name: &str) -> Option<(ApiResourc
// this is equivalent to kubectl's api group preference
discovery
.groups()
.flat_map(|group| {
group
.recommended_resources()
.into_iter()
.map(move |res| (group, res))
})
.flat_map(|group| group.resources().into_iter().map(move |res| (group, res)))
.filter(|(_, (res, _))| {
// match on both resource name and kind name
// ideally we should allow shortname matches as well
Expand Down
10 changes: 9 additions & 1 deletion kube-client/src/discovery/apigroup.rs
Expand Up @@ -8,7 +8,6 @@ use kube_core::{
};
use std::cmp::Reverse;


/// Describes one API groups collected resources and capabilities.
///
/// Each `ApiGroup` contains all data pinned to a each version.
Expand Down Expand Up @@ -217,6 +216,15 @@ impl ApiGroup {
.unwrap_or_default()
}

/// Returns all the resources in the group.
pub fn resources(&self) -> Vec<(ApiResource, ApiCapabilities)> {
let mut r: Vec<(ApiResource, ApiCapabilities)> = vec![];
for item in self.data.iter() {
r.append(&mut item.resources.clone());
}
return r;
}

/// Returns the recommended (preferred or latest) versioned resources in the group
///
/// ```no_run
Expand Down

0 comments on commit d74e585

Please sign in to comment.