Skip to content

Commit 7920fc3

Browse files
cluxmateiidavid
andauthored
runtime: rename references from Flatten to Decode (#1520)
* runtime: rename references from Flatten to Filter where necessary closes #1517 Signed-off-by: clux <sszynrae@gmail.com> * file rename and rename refs to EventFlatten Signed-off-by: clux <sszynrae@gmail.com> * forgot to add missing deprecation target version Signed-off-by: clux <sszynrae@gmail.com> * make it non-breaking Signed-off-by: clux <sszynrae@gmail.com> * Update kube-runtime/src/utils/mod.rs Co-authored-by: Matei David <matei.david.35@gmail.com> Signed-off-by: Eirik A <sszynrae@gmail.com> * rename to event decode Signed-off-by: clux <sszynrae@gmail.com> * rename everywhere from filter to decode Signed-off-by: clux <sszynrae@gmail.com> * fix deny.. Signed-off-by: clux <sszynrae@gmail.com> --------- Signed-off-by: clux <sszynrae@gmail.com> Signed-off-by: Eirik A <sszynrae@gmail.com> Co-authored-by: Matei David <matei.david.35@gmail.com>
1 parent 27a2129 commit 7920fc3

6 files changed

Lines changed: 41 additions & 24 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ For real world projects see [ADOPTERS](https://kube.rs/adopters/).
4343

4444
## Api
4545

46-
The [`Api`](https://docs.rs/kube/*/kube/struct.Api.html) is what interacts with Kubernetes resources, and is generic over [`Resource`](https://docs.rs/kube/*/kube/trait.Resource.html):
46+
The [`Api`](https://docs.rs/kube/latest/kube/struct.Api.html) is what interacts with Kubernetes resources, and is generic over [`Resource`](https://docs.rs/kube/latest/kube/trait.Resource.html):
4747

4848
```rust
4949
use k8s_openapi::api::core::v1::Pod;
@@ -102,7 +102,7 @@ A streaming interface (similar to informers) that presents [`watcher::Event`](ht
102102

103103
```rust
104104
let api = Api::<Pod>::default_namespaced(client);
105-
let stream = watcher(api, Config::default()).applied_objects();
105+
let stream = watcher(api, Config::default()).default_backoff().applied_objects();
106106
```
107107

108108
This now gives a continual stream of events and you do not need to care about the watch having to restart, or connections dropping.
@@ -113,6 +113,7 @@ while let Some(event) = stream.try_next().await? {
113113
}
114114
```
115115

116+
116117
Note the base items from a `watcher` stream are an abstraction above the native `WatchEvent` to allow for store buffering. If you are following along to "see what changed", you can use utilities from [`WatchStreamExt`](https://docs.rs/kube/latest/kube/runtime/trait.WatchStreamExt.html), such as `applied_objects` to get a more conventional stream.
117118

118119
## Reflectors

deny.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ multiple-versions = "deny"
6464
[[bans.skip]]
6565
name = "rustls-native-certs"
6666

67+
[[bans.skip]]
68+
# blocked on us swapping out serde_yaml
69+
name = "hashbrown"
70+
6771
[[bans.skip]]
6872
# base64 did some annoying breaking changes
6973
name = "base64"
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ use pin_project::pin_project;
99
#[pin_project]
1010
/// Stream returned by the [`applied_objects`](super::WatchStreamExt::applied_objects) and [`touched_objects`](super::WatchStreamExt::touched_objects) method.
1111
#[must_use = "streams do nothing unless polled"]
12-
pub struct EventFlatten<St> {
12+
pub struct EventDecode<St> {
1313
#[pin]
1414
stream: St,
1515
emit_deleted: bool,
1616
}
17-
impl<St: TryStream<Ok = Event<K>>, K> EventFlatten<St> {
17+
impl<St: TryStream<Ok = Event<K>>, K> EventDecode<St> {
1818
pub(super) fn new(stream: St, emit_deleted: bool) -> Self {
1919
Self { stream, emit_deleted }
2020
}
2121
}
22-
impl<St, K> Stream for EventFlatten<St>
22+
impl<St, K> Stream for EventDecode<St>
2323
where
2424
St: Stream<Item = Result<Event<K>, Error>>,
2525
{
@@ -50,11 +50,11 @@ where
5050
pub(crate) mod tests {
5151
use std::{pin::pin, task::Poll};
5252

53-
use super::{Error, Event, EventFlatten};
53+
use super::{Error, Event, EventDecode};
5454
use futures::{poll, stream, StreamExt};
5555

5656
#[tokio::test]
57-
async fn watches_applies_uses_correct_eventflattened_stream() {
57+
async fn watches_applies_uses_correct_stream() {
5858
let data = stream::iter([
5959
Ok(Event::Apply(0)),
6060
Ok(Event::Apply(1)),
@@ -65,7 +65,7 @@ pub(crate) mod tests {
6565
Err(Error::NoResourceVersion),
6666
Ok(Event::Apply(2)),
6767
]);
68-
let mut rx = pin!(EventFlatten::new(data, false));
68+
let mut rx = pin!(EventDecode::new(data, false));
6969
assert!(matches!(poll!(rx.next()), Poll::Ready(Some(Ok(0)))));
7070
assert!(matches!(poll!(rx.next()), Poll::Ready(Some(Ok(1)))));
7171
// NB: no Deleted events here

kube-runtime/src/utils/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@
22
33
mod backoff_reset_timer;
44
pub(crate) mod delayed_init;
5-
mod event_flatten;
5+
mod event_decode;
66
mod event_modify;
77
#[cfg(feature = "unstable-runtime-predicates")] mod predicate;
88
mod reflect;
99
mod stream_backoff;
1010
mod watch_ext;
1111

1212
pub use backoff_reset_timer::ResetTimerBackoff;
13-
pub use event_flatten::EventFlatten;
13+
pub use event_decode::EventDecode;
1414
pub use event_modify::EventModify;
1515
#[cfg(feature = "unstable-runtime-predicates")]
1616
pub use predicate::{predicates, Predicate, PredicateFilter};
1717
pub use reflect::Reflect;
1818
pub use stream_backoff::StreamBackoff;
1919
pub use watch_ext::WatchStreamExt;
20+
/// Deprecated type alias for `EventDecode`
21+
#[deprecated(
22+
since = "0.96.0",
23+
note = "renamed to by `EventDecode`. This alias will be removed in 0.100.0."
24+
)]
25+
pub use EventDecode as EventFlatten;
2026

2127
use futures::{
2228
stream::{self, Peekable},

kube-runtime/src/utils/watch_ext.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "unstable-runtime-predicates")]
22
use crate::utils::predicate::{Predicate, PredicateFilter};
33
use crate::{
4-
utils::{event_flatten::EventFlatten, event_modify::EventModify, stream_backoff::StreamBackoff},
4+
utils::{event_decode::EventDecode, event_modify::EventModify, stream_backoff::StreamBackoff},
55
watcher,
66
};
77
use kube_client::Resource;
@@ -33,24 +33,24 @@ pub trait WatchStreamExt: Stream {
3333
StreamBackoff::new(self, b)
3434
}
3535

36-
/// Flatten a [`watcher()`] stream into a stream of applied objects
36+
/// Decode a [`watcher()`] stream into a stream of applied objects
3737
///
3838
/// All Added/Modified events are passed through, and critical errors bubble up.
39-
fn applied_objects<K>(self) -> EventFlatten<Self>
39+
fn applied_objects<K>(self) -> EventDecode<Self>
4040
where
4141
Self: Stream<Item = Result<watcher::Event<K>, watcher::Error>> + Sized,
4242
{
43-
EventFlatten::new(self, false)
43+
EventDecode::new(self, false)
4444
}
4545

46-
/// Flatten a [`watcher()`] stream into a stream of touched objects
46+
/// Decode a [`watcher()`] stream into a stream of touched objects
4747
///
4848
/// All Added/Modified/Deleted events are passed through, and critical errors bubble up.
49-
fn touched_objects<K>(self) -> EventFlatten<Self>
49+
fn touched_objects<K>(self) -> EventDecode<Self>
5050
where
5151
Self: Stream<Item = Result<watcher::Event<K>, watcher::Error>> + Sized,
5252
{
53-
EventFlatten::new(self, true)
53+
EventDecode::new(self, true)
5454
}
5555

5656
/// Modify elements of a [`watcher()`] stream.
@@ -88,7 +88,7 @@ pub trait WatchStreamExt: Stream {
8888
EventModify::new(self, f)
8989
}
9090

91-
/// Filter out a flattened stream on [`predicates`](crate::predicates).
91+
/// Filter a stream based on on [`predicates`](crate::predicates).
9292
///
9393
/// This will filter out repeat calls where the predicate returns the same result.
9494
/// Common use case for this is to avoid repeat events for status updates

kube-runtime/src/watcher.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ impl<K> Event<K> {
7171
///
7272
/// `Deleted` objects are ignored, all objects mentioned by `Restarted` events are
7373
/// emitted individually.
74-
#[deprecated(since = "0.92.0", note = "unnecessary to flatten a single object")]
74+
#[deprecated(
75+
since = "0.92.0",
76+
note = "unnecessary to flatten a single object. This fn will be removed in 0.96.0."
77+
)]
7578
pub fn into_iter_applied(self) -> impl Iterator<Item = K> {
7679
match self {
7780
Self::Apply(obj) | Self::InitApply(obj) => Some(obj),
@@ -85,7 +88,10 @@ impl<K> Event<K> {
8588
/// Note that `Deleted` events may be missed when restarting the stream. Use finalizers
8689
/// or owner references instead if you care about cleaning up external resources after
8790
/// deleted objects.
88-
#[deprecated(since = "0.92.0", note = "unnecessary to flatten a single object")]
91+
#[deprecated(
92+
since = "0.92.0",
93+
note = "unnecessary to flatten a single object. This fn will be removed in 0.96.0."
94+
)]
8995
pub fn into_iter_touched(self) -> impl Iterator<Item = K> {
9096
match self {
9197
Self::Apply(obj) | Self::Delete(obj) | Self::InitApply(obj) => Some(obj),
@@ -710,8 +716,8 @@ where
710716
/// [`try_for_each`](futures::TryStreamExt::try_for_each) and [`try_concat`](futures::TryStreamExt::try_concat))
711717
/// will terminate eagerly as soon as they receive an [`Err`].
712718
///
713-
/// This is intended to provide a safe and atomic input interface for a state store like a [`reflector`].
714-
/// Direct users may want to flatten composite events via [`WatchStreamExt`]:
719+
/// The events are intended to provide a safe input interface for a state store like a [`reflector`].
720+
/// Direct users may want to use [`WatchStreamExt`] for higher-level constructs.
715721
///
716722
/// ```no_run
717723
/// use kube::{
@@ -773,8 +779,8 @@ pub fn watcher<K: Resource + Clone + DeserializeOwned + Debug + Send + 'static>(
773779
/// [`try_for_each`](futures::TryStreamExt::try_for_each) and [`try_concat`](futures::TryStreamExt::try_concat))
774780
/// will terminate eagerly as soon as they receive an [`Err`].
775781
///
776-
/// This is intended to provide a safe and atomic input interface for a state store like a [`reflector`].
777-
/// Direct users may want to flatten composite events via [`WatchStreamExt`]:
782+
/// The events are intended to provide a safe input interface for a state store like a [`reflector`].
783+
/// Direct users may want to use [`WatchStreamExt`] for higher-level constructs.
778784
///
779785
/// ```no_run
780786
/// use kube::{

0 commit comments

Comments
 (0)