kube icon indicating copy to clipboard operation
kube copied to clipboard

Move `ApiCapabilities` into `ApiResource` and add `Scope` trait

Open clux opened this issue 3 years ago • 3 comments

Generally simplified code everywhere. The main edge cases worth documenting here is that ApiResource can be constructed in multiple ways, and some of these will not yield all the fields on it.

  • ~~Merged~~Moved ApiCapabilities data into ApiResource
  • Add shortnames to ApiResource for #1002
  • Removed separate ApiCapabilities returns (always constructed together with ApiResource, so now returned as one)
  • Added a Scope trait implemented for all k8s-openapi::ResourceScope + our DynamicResourceScope
  • Refined the Resource trait to require the associated Scope type to implement the new Scope trait
  • Added Resource::is_namespaced using Scope trait or dyn type inspection
  • Extended ApiResource::erase to be able to determine namespaced bool from the Scope trait
  • Reclassified ApiResource ctors (removed ApiResource::from_gvk_with_plural in favour of ApiResource::new)
  • Added setters of properties previously in ApiCapabilities to ApiResource
  • Extended kube-derive to default verbs on its ApiResource
  • LATER: Extend kube-derive to provide subresources on its ApiResource (todo in #1037)
  • Re-documented everything related / fix tests

clux avatar Sep 30 '22 22:09 clux

Codecov Report

Merging #1038 (39f8116) into main (a26e7f3) will decrease coverage by 0.46%. The diff coverage is 66.25%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1038      +/-   ##
==========================================
- Coverage   72.29%   71.82%   -0.47%     
==========================================
  Files          65       66       +1     
  Lines        4681     4699      +18     
==========================================
- Hits         3384     3375       -9     
- Misses       1297     1324      +27     
Impacted Files Coverage Δ
kube-client/src/lib.rs 93.75% <ø> (ø)
kube-core/src/crd.rs 82.92% <ø> (ø)
kube-core/src/dynamic.rs 63.63% <0.00%> (-3.04%) :arrow_down:
kube-core/src/object.rs 77.41% <0.00%> (-2.59%) :arrow_down:
kube-derive/src/custom_resource.rs 13.83% <ø> (ø)
kube-runtime/src/reflector/store.rs 95.16% <ø> (ø)
kube-runtime/src/utils/mod.rs 62.96% <ø> (ø)
kube-core/src/scope.rs 16.66% <16.66%> (ø)
kube-core/src/discovery.rs 86.66% <36.84%> (-11.09%) :arrow_down:
kube-client/src/discovery/parse.rs 93.75% <91.66%> (-0.85%) :arrow_down:
... and 6 more

codecov-commenter avatar Oct 01 '22 08:10 codecov-commenter

Eyes on this would be appreciated @kube-rs/maintainers .

Clarity on how to convert between scope requirement on dynamic and static types is needed for a good way forward on the new client api in #1037, but this should stand well on its own without that (even though it doesn't go all the way with subresources).

clux avatar Oct 03 '22 18:10 clux

Going to put this on hold until 0.77. I have some ideas for it, but it's been a while since a release and will get that out the door first.

clux avatar Oct 27 '22 18:10 clux