-
-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clean up api::discovery module - for #523 #538
Conversation
A bit of a pattern is emerging here in terms of what people might want to discover:
We should probably have a uniform interface for these if we want to support all 3. E.g. the second might be The last one is interesting. It is possible we can do this so that you get a vector of options, or the first matching kind (with perhaps a preference for core?). |
- moves the modules from kube::client to kube::api - introduces easier way to get recommended_resources and recommended_kind from an `ApiGroup` - restructures file for readability (internal Version sorting quirks documented and tested) - renamed `ApiResourceExtras` to `ApiCapabilities` - renamed `ApiGroup::group` to `ApiGroup::get` - added support for `Discovery::single` which avoids having to deal with the `HashMap` and returns a straight `ApiGroup` (making the recommended doc examples more compelling) - documents the version sorting a bit better - renamed `ApiGroup::preferred_version_or_guess` to `ApiGroup::preferred_version_or_latest` and referred to the version policy - separated querying to helpers on `ApiGroup` - moved sorting to `ApiGroup` construction part
`resources_by_version` -> `versioned_resources` to match `recommended_resources`. few more doc links
Have cleaned up some more. Found out that the new module actually was less efficient w.r.t. api calls (needlessly calling list_api_groups even if people knew the group and version). This is now mitigated and there are currently two solutions:
let apps = client.list_api_group_resources("apiregistration.k8s.io").await?;
let apiservice = apps.iter().find(|ar| ar.kind == "APIService").unwrap();
let resource = ApiResource::from_apiresource(&apiservice, &apps.group_version);
let api: Api<DynamicObject> = Api::all_with(client.clone(), "default", &resource); vs
let gvk = GroupVersionKind::gvk("apiregistration.k8s.io", "v1", "APIService");
let (ar, caps) = Discovery::gvk(&client, &gvk).await?.unwrap();
let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar); Think this should let me privatize There are all sorts of efficient (to less efficient) ways we can discover now:
The last one I can only see being useful in a At any rate, going to mull this over some more tomorrow, then probably make the old apis private, then merge. |
actually many legit use cases here, so made it kind of nice. finally, this allows us to deprecate old ApiResource from_apiresource as well as old Client listers (which we use internally). possibly some more cleanups incoming.
ok, this is turning into a pretty big yak... have:
a few small things left to look over / think about:
|
examples/dynamic_watcher.rs
Outdated
@@ -19,19 +19,11 @@ async fn main() -> anyhow::Result<()> { | |||
|
|||
// Turn them into a GVK | |||
let gvk = GroupVersionKind::gvk(&group, &version, &kind); | |||
let mut api_resource = ApiResource::from_gvk(&gvk); | |||
// Use API discovery to identify more information about the type (like its plural) | |||
let (ar, _caps) = discovery::Oneshot::gvk(&client, &gvk).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Stopped recommending people construct ApiResource
s manually when using DynamicObject
s and recommended doing the basic oneshot discovery to find the plural.
Did put Have left them untouched for now (but with a note in docs). However, the changes made to some of the more confusion-inducing parsers (for Think I am mostly done with this now (finally). Have only two outstanding questions to mull over:
|
* clean up api::discovery module - for kube-rs#523 - moves the modules from kube::client to kube::api - introduces easier way to get recommended_resources and recommended_kind from an `ApiGroup` - restructures file for readability (internal Version sorting quirks documented and tested) - renamed `ApiResourceExtras` to `ApiCapabilities` - renamed `ApiGroup::group` to `ApiGroup::get` - added support for `Discovery::single` which avoids having to deal with the `HashMap` and returns a straight `ApiGroup` (making the recommended doc examples more compelling) - documents the version sorting a bit better - renamed `ApiGroup::preferred_version_or_guess` to `ApiGroup::preferred_version_or_latest` and referred to the version policy - separated querying to helpers on `ApiGroup` - moved sorting to `ApiGroup` construction part * clippy * changelog * promote discovery to its own module * factor out version logic into own private module * add some docs + small renames `resources_by_version` -> `versioned_resources` to match `recommended_resources`. few more doc links * remove stray todo and add back kube::client::Status * add better entry point for the cheaper single case * fix tests * restructure completely again for cache/oneshot distinction actually many legit use cases here, so made it kind of nice. finally, this allows us to deprecate old ApiResource from_apiresource as well as old Client listers (which we use internally). possibly some more cleanups incoming. * clippy * split discovery into 3 files * discovery error type * fix tests * rename openapi mod to parse mod * revert premature deprecation * document changes * make DiscoveryError work on config only feat + fix rustfmt makefile * resolve last questions
released in 0.56 |
kube::client::discovery
totop levelkube::api::discovery
kube::discovery
ApiGroup
Version
sorting implementation documented and tested better (and moved to its own module underkube::discovery
)ApiResourceExtras
toApiCapabilities
ApiGroup::group
toApiGroup::get
Discovery::single
which avoids having to deal with theHashMap
and returns a straightApiGroup
(making the recommended doc examples more compelling)ApiGroup::preferred_version_or_guess
toApiGroup::preferred_version_or_latest
and referred to the version policyApiGroup
ApiGroup
construction part (as it's an operation internal to each group)Fundamentally leaves the behaviour from @MikailBag 's original PRs unchanged, still a bit unsure about some of the algorithms used and the various converters from
k8s_openapi
types to our types, but that's generally internal.