kube
kube copied to clipboard
Consider adding a `RuntimeApiExt` trait to `kube-runtime`
I.e. add a trait that allows (after importing) the following changes (as an MVP):
-let stream = watcher(api, lp).applied_objects();
+let stream = api.watcher(lp).applied_objects();
-let cond = await_condition(api, "mycm", my_condition_fn);
+let cond = api.condition("mycm", my_condition_fn);
It should be fairly innocuous to do; it's unlikely we are ever going to kill off Api (unless we want to re-open any bigger discussions on neokubism) so we should make them as nice to work with as possible.
Having chaining here is simpler, allows simpler fn names, easier LTR scannability, and reduces the chance of passing in the wrong api (although unlikely if given further constraints but still possible).
Other potentials for inclusion in such an ext trait would be; delete_and_finalize, finalizer.
Well, turns out this is incredibly complicated to do as a trait. Was trying something along the lines of:
pub trait RuntimeApiExt
{
type R: Resource + Clone + Debug + DeserializeOwned + Send + 'static;
fn watcher(&self, lp: &ListParams) -> impl Stream<Item = Result<Event<Self::R>>> + Send
{
watcher(self.clone(), lp)
}
async fn condition(&self, name: &str, cond: impl Condition<Self::R>) -> Result<Option<Self::R>, WaitErr> {
await_condition(self, name, cond).await
}
}
impl<K: ?Sized> RuntimeApiExt for Api<K>
where K: Resource + Clone + DeserializeOwned + Debug + Send + 'static
{
type R = K;
}
but that has so many complications:
- pulls in
async_traitcrate - can't use
impl Streamin return of trait signatures (so have to convertwatcherinto a concreteStreamtype) - cannot make this generic over
Kbecause there's no trait forApi<K>so the signatures doesn't actually match anyway
we also cannot make this an impl Api<K> where K:... because it would have to be a cross-crate impl.
...maybe this isn't a good idea with the current async rust setup.