-
-
Notifications
You must be signed in to change notification settings - Fork 308
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
Genericize PartialObjectMeta
over the underlying Resource
#1152
Conversation
Allows doing static dispatch using the root type, and avoids having to do stringly typed oob signalling in generic code. Signed-off-by: clux <sszynrae@gmail.com>
PartialObjectMeta
over the underlying Resource
Signed-off-by: clux <sszynrae@gmail.com>
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1152 +/- ##
==========================================
+ Coverage 72.26% 72.57% +0.30%
==========================================
Files 67 67
Lines 5106 5123 +17
==========================================
+ Hits 3690 3718 +28
+ Misses 1416 1405 -11
|
Signed-off-by: clux <sszynrae@gmail.com>
cc @mateiidavid |
conversion the other way avoids users having to write: ```rust let pom = PartialObjectMeta::<Pod> { types: Some(TypeMeta{ ...constant }), metadata: actual_test_data, ..Default::default(), }; ``` Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
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.
LGTM overall. I'm starting to wonder if this would let us remove the dedicated Api::*_metadata
methods and just infer that based on K, but that's probably a question for another time.
kube-core/src/metadata.rs
Outdated
type DynamicType = ApiResource; | ||
type Scope = DynamicResourceScope; | ||
// Unit tests often convert the other way | ||
impl<K> From<ObjectMeta> for PartialObjectMeta<K> { |
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.
Is this a valid thing in general, or do we want to make it a dedicated associated function where we can call out any caveats? Should we take the TypeMeta
from K
instead of making up our own?
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.
Ugh, this was a really good call. Thank you. The From
is way too simplistic here because how we want to use PartialObjectMeta
depends on whether it is a request object or a response object (the apiserver erases the type, but the root type is needed for patch).
Have removed the From
and instead created a sealed PartialObjectMetaExt
trait that contains two converter functions, and have used it in the main test case.
Need to have two different ways to convert from ObjectMeta depending on how we are going to use it. Have created a sealed trait with converters for it, and updated docs, tests to use it. Signed-off-by: clux <sszynrae@gmail.com>
avoids unstable associated trait bounds + lints showing that the default really had to be the empty type. Signed-off-by: clux <sszynrae@gmail.com>
bunch of new bugs in https://github.com/rust-lang/rust-clippy/issues?q=is%3Aissue+let_underscore_untyped our use seems perfectly fine, what clippy wanted was nonsense: ``` error: non-binding `let` without a type annotation --> kube-runtime/src/reflector/store.rs:87:12 | 87 | pub struct Store<K: 'static + Resource> | ^^^^^ | = help: consider adding a type annotation or removing the `let` keyword = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_untyped error: non-binding `let` without a type annotation --> kube-runtime/src/watcher.rs:123:5 | 123 | InitListed { resource_version: String }, | ^^^^^^^^^^ | = help: consider adding a type annotation or removing the `let` keyword = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_untyped ``` Signed-off-by: clux <sszynrae@gmail.com>
Allows doing static dispatch using the root type, and avoids having to do stringly typed oob signalling in generic code.
Fixes #1151, in particular:
PhantomType<K>
toPartialObjectMeta
Resource
impl forPartialObjectMeta
by instead proxying toK: Resource
PartialObjectMeta
has changed toPartialObjectMeta<K>
PartialObjectMeta<DynamicObject>
(which it is inferred to indynamic_watcher
)PartialObjectMetaExt
fromObjectMeta
intoPartialObjectMeta<K>
Example generic code:
This now gives us a way to get type info in generic code without extra
ApiResource
args and lambdas, while also maintaining all the static type safety we have around scopes.