-
-
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
client_ext for Client::get
and Client::list
#1375
Conversation
AKA Api calls without `Api`. To avoid overreaching in this PR we only deal with `.get` and `.list` for cluster and namespace scoped resources. An example node_watcher uses this (to show we can avoid the clone and api construction) for `.list_all`. Signed-off-by: clux <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1375 +/- ##
=======================================
+ Coverage 72.2% 72.3% +0.2%
=======================================
Files 75 76 +1
Lines 6485 6527 +42
=======================================
+ Hits 4680 4717 +37
- Misses 1805 1810 +5
|
Signed-off-by: clux <[email protected]>
This is in a state that could benefit from a review to see that we are at least on the same page. Not bothering with full details on docs/tests here yet until we agree (just did one basic one), and MSRV failures due to |
Client
ExtensionsApi
style Client
Extensions (.get and .list)
Api
style Client
Extensions (.get and .list)Client::get
and Client::list
Extensions
Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
Have added tests and docs for the new public interfaces now so am not planning on changing this PR more without feedback. It's only doing |
Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
Updated and edited post body. Incorporated a bunch of suggestions from @nightkr with renames and tweaks. Have tried to make the docs look nice (which is a slight challenge when the methods merge with the normal client ctors). I'll mention this tomorrow in the meet. |
I spent an houlr playing around with async traits as an investigation for whether it would make docs better, and am now under the impression that they are not significantly more helpful for what we are trying to accomplish. If we convert the pub trait ClientExt {
async fn get<K>(&self, name: &str, scope: &impl ObjectUrl<K>) -> Result<K>
where
K: Resource + DeserializeOwned + Clone + Debug,
<K as Resource>::DynamicType: Default;
async fn list<K>(&self, lp: &ListParams, scope: &impl CollectionUrl<K>) -> Result<ObjectList<K>>
where
K: Resource + DeserializeOwned + Clone + Debug,
<K as Resource>::DynamicType: Default;
} and then blanket impl later: impl ClientExt for Client {
async fn get<K>(&self, name: &str, scope: &impl ObjectUrl<K>) -> Result<K>
where
K: Resource + DeserializeOwned + Clone + Debug,
<K as Resource>::DynamicType: Default,
{
let mut req = Request::new(scope.url_path())
.get(name, &GetParams::default())
.map_err(Error::BuildRequest)?;
req.extensions_mut().insert("get");
self.request::<K>(req).await
}
// ...
} then we can indeed export but it has a couple of downsides:
so am not hugely enthusiastic about the trait approach either. leaving this comment as a justification and linking to it above. ultimately this stuff can be changed down the line later since it's under an unstable flag. |
was originally afraid to remove this since it's a pub re-export but it's only pub for this module, the root `mod.rs` does not re-export so have moved the only import to where it is needed Signed-off-by: clux <[email protected]>
Client::get
and Client::list
ExtensionsClient::get
and Client::list
these tests should run if the parent module is included Signed-off-by: clux <[email protected]>
- docsrs feature limiters, for best effort help - plus a couple of broken links Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
AKA Api calls without
Api
for #1032This is a smaller scope variant of #1037 that solves the basic
Api
like functionality onClient
directly (opt-in feature) without getting bogged down in other requirements around apicaps and scope dependencies by using indirection traits instead.This PR primarily adds:
Client::get
andClient::list
that can be used by all resources that allow for a scoped operationNamespace
newtype haveFrom
impls from&str
,String
andk8s_openapi::...::Namespace
.Cluster
empty marker typeWhere you have to supply the scope as either
&Cluster
or&Namespace(String)
:There are also some trait magic underneath the hood to ensure you can only do cluster level listing on a cluster scoped object, and only namespace level listing on namespaced objects, but we still retain compatibility with dynamic objects thanks to a bit of magic from @nightkr. Most of this is private. Maybe it can be made public later, but feels early now.
The
node_watcher
shows how this can be used (showing we can avoid the clone and api construction) for a.list
.Choices
kube::client::scope
for scope markersCurrently
kube::client::scope
is exported. In the future we will likely move this intokube_core
once we stabilise it.naming
We need to avoid clashes with similar names:
Api
ctorskube::core
Current is slightly awkward, and am open to suggestions, but i think we can start with this and eventually make this easier later.
impl Client
over asynctrait
impl Client
methods that are pulled in via a module feature. Allows for better default visibility, less imports needed, puts less constraints on our code), but it does mean that all the docs get inlined along with the constructors and raw, low-level methods on Client.exploration
As you can see, you can document each
impl Client
block ^ (and the blocks do appear in order in the main body), but on the left you see theClient::get
andClient::list
methods get sorted in with the full list of low-level client methods, which is not great. Maybe that is more of a rust-doc bug, but it makes the docs look a bit cluttered.Investigated the alternative in in #1375 (comment) and we talked about this in the meet and none of us seemed particularly keen on the trait.