-
-
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
Add Event::modify + reflector::store helpers #907
Conversation
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #907 +/- ##
==========================================
- Coverage 70.56% 70.44% -0.12%
==========================================
Files 64 64
Lines 4331 4341 +10
==========================================
+ Hits 3056 3058 +2
- Misses 1275 1283 +8
|
Hm.. personally I'd be more inclined to put this into the reflector, or to have this be a map step in between the watcher and reflector. It feels pretty weird to have the Something along the lines of.. watcher(...)
.map_ok(|event| event.map_objects(|mut obj| {
obj.metadata.managed_fields = None;
obj
}))
.reflector(...) Now that we have On the other hand, 👍 on |
Yeah, that makes perfect sense. I will get back to this and try something with CustomResourceExt later if i have time. Might put this on hold before 0.72.0. |
Signed-off-by: clux <sszynrae@gmail.com>
Actually not too bad to get working. This is only the |
kube-runtime/src/watcher.rs
Outdated
/// pod.status = None; | ||
/// }); | ||
/// ``` | ||
pub fn map_event(mut self, f: impl Fn(&mut K)) -> Self { |
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.
mutate_objects
, perhaps? map
implies that it operates on a fn(T) -> T
rather than fn(&mut T) -> ()
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.
I believe this could also be FnMut
rather than Fn
since we apply them sequentially (unless you plan on introducing parallelism later?)
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.
AFAIKT the benefit to having it be FnMut
is that it can capture mutable variables from a closure?
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.
Yes. Or rather, it can capture closure variables mutably. You could still capture mutable variables immutably since they just get downgraded to immutable during the borrow.
Signed-off-by: clux <sszynrae@gmail.com>
remove generally pointless configmap_reflector very similar to secret_reflector and we already have 4 basic ones. Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
reflector::store
fn that creates a(reader,writer)
pair in default casesEvent::modify
fn that can be used to downsize the memory use of a watcher streamorginal idea - scrapped
An extension written into `Writer` to take a mutator (defaults to the identity)
The first part is the most substantial, and it required tweaking the Default + Debug implementations (which were done via Derivative before). There might be some ways to get around this with less trait restrictions on
F
but it always complained without this, and it seems to work well in a real word setting in example with a straight closure.The use case for the mutator is memory improvements. Currently you can customize structs with partially typed resources, but you cannot drop the significant contributions from
ObjectMeta
via its managed fields. Additionally, it feels a bit wrong to me to recommend rewriting structs when what we really want is just to drop what parts of it we store, and that can be done with a mutator. By the time we use it we have already extracted the key parts for the keys in the state so it should be pretty user-safe as well.