-
-
Notifications
You must be signed in to change notification settings - Fork 325
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 WatchStreamExt::modify()
to modify events
#1246
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1246 +/- ##
==========================================
+ Coverage 72.60% 72.82% +0.22%
==========================================
Files 72 73 +1
Lines 5899 5925 +26
==========================================
+ Hits 4283 4315 +32
+ Misses 1616 1610 -6
|
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.
Great work. Thanks a lot for this. One minor test request + have inlined a doc example after verifying locally.
6ca8651
to
85065c9
Compare
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.
Looks great. Tyvm!
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.
Largely looks good to me! One more serious concern, but that's more about the existing Event::modify
than about this PR.
assert!(matches!( | ||
poll!(ev_modify.next()), | ||
Poll::Ready(Some(Ok(Event::Restarted(restart_val)))) | ||
)); |
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.
This looks like a bug in Event::modify
if this passes, this should be vec![11]
.
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.
its not a bug in Event::modify
, its a shortcoming of matches!
. this will always pass, since its not actually using restart_val
(the compiler also complains about restart_val
being unused) (ref: https://stackoverflow.com/questions/68155018/rust-matches-macro-behaves-unexpectedly-in-regards-to-enum)
fixed it by extracting the result and using an if guard to compare instead of directly specifying the desired value.
assert!(matches!( | ||
poll!(ev_modify.next()), | ||
Poll::Ready(Some(Ok(Event::Applied(1)))) | ||
)); |
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.
Nit: No need to use poll!
if you expect it to be Ready
.
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.
as far as i understand, the poll!
here is used to get convert the future returned by ev_modify.next()
into a Poll
object.
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, but since it should already be ready it would be equivalent to ev_modify.next().await
. Then again, on second thought, poll!
does have the advantage of failing faster if it's not ready for whatever reason.
Add `WatchStreamExt::modify()` which returns an `EventModify` stream. This allows for users to directly modify the inner value of an `Event` returned by the watcher stream, thus avoiding the usage of nested maps. Example usage: ```rust let stream = watcher(api, watcher::Config::default()).modify(|pod| { pod.managed_fields_mut().clear(); pod.annotations_mut().clear(); pod.status = None; }); ``` Signed-off-by: Sanskar Jaiswal <[email protected]>
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
That said, please try to avoid rebasing/squashing feature branches if possible, it makes reviews a pain.
Motivation
Atm, we need to resort to nested maps if we want to modify the resource directly present in the
Event
s returned by thewatcher()
stream.Solution
Add
WatchStreamExt::modify()
which returns anEventModify
stream. This allows for users to directly modify the inner value of anEvent
returned by the watcher stream, thus avoiding the usage of nested maps.Example usage:
Fixes #1245