Skip to content

Commit

Permalink
Merge pull request #66 from kube-rs/unflatten
Browse files Browse the repository at this point in the history
Rename references flattened/unflattened streams
  • Loading branch information
clux authored Oct 9, 2024
2 parents 48acd7c + ca47556 commit eba16de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions docs/controllers/streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ But note this changes the stream signature slightly; returning a wrapped [Partia
### Terminology

- **watcher stream** :: a stream that is started by one of the watcher [[#stream-entrypoints]]
- **flattened stream** :: a stream that's been through [EventFlatten] via one of `WatchStreamExt::touched_objects`, `WatchStreamExt::applied_objects`
- **event stream** :: a raw [watcher] stream producing un-flattened [watcher::Event] objects
- **decoded stream** :: a stream that's been through [EventDecode] via one of `WatchStreamExt::touched_objects`, `WatchStreamExt::applied_objects`
- **event stream** :: a raw [watcher] stream producing [watcher::Event] objects

The significant difference between them is that the **user** and the [Controller] generally wants to interact with a **flattened stream**, but a [reflector] needs an **event stream** to be able to safely replace its contents.
The significant difference between them is that the **user** and the [Controller] generally wants to interact with a **decoded stream**, but a [reflector] needs an **event stream** to be able to safely replace its contents.

### WatchStreamExt
The [WatchStreamExt] trait is a `Stream` extension trait (ala [StreamExt]) with Kubernetes specific helper methods that can be chained onto a watcher stream;
Expand All @@ -82,15 +82,15 @@ watcher(api, watcher::Config::default())
These methods can require one of:

- **event stream** (where the input stream `Item = Result<Event<K>, ...>`
- **flattened stream** (where `Item = Result<K, ...>`, the last ones in the chain)
- **decoded stream** (where `Item = Result<K, ...>`, the last ones in the chain)

It is impossible to apply them in an incompatible configuration.

## Stream Mutation
It is possible to modify or filter the input streams before passing them on. This can usually either done to limit data in memory by pruning, or to filter events to a downstream controller so that it either triggers less frequently.

### Predicates
Using [predicates], we can **filter out** events from a stream where the **last value** of a particular property is **unchanged**. This is done internally by storing hashes of the given property(ies), and can be chained onto a **flattened** stream:
Using [predicates], we can **filter out** events from a stream where the **last value** of a particular property is **unchanged**. This is done internally by storing hashes of the given property(ies), and can be chained onto an **decoded** stream:

```rust
let api: Api<Deployment> = Api::all(client);
Expand Down Expand Up @@ -138,7 +138,7 @@ Controller::for_stream(main_stream, reader)
.watches_stream(watched_custom_stream, cfg)
```

where the various stream variables would be created from either [watcher], or [metadata_watcher] with some filters/flatteners applied.
where the various stream variables would be created from either [watcher], or [metadata_watcher] with a decoder applied.

!!! warning "The controller streams interface is unstable"

Expand Down Expand Up @@ -168,7 +168,7 @@ Controller::new(api, Config::default())
To configure one of the input streams manually you need to:

1. create a watcher stream with backoff
2. flatten the stream
2. decode the stream
3. call the stream-equivalent `Controller` interface

Note that the `Controller` will poll all the passed (or implicitly created) watcher streams as a whole when you poll the output stream from the controller.
Expand Down Expand Up @@ -284,4 +284,4 @@ Controller::for_stream(cr_stream, reader)
[optimization#pruning-fields]: optimization "Optimization"
[relations]: relations "Related Objects"
[#Metadata-Watcher]: streams "Streams"
[//end]: # "Autogenerated link references"
[//end]: # "Autogenerated link references"
2 changes: 1 addition & 1 deletion includes/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
[watcher]: https://docs.rs/kube/latest/kube/runtime/fn.watcher.html
[metadata_watcher]: https://docs.rs/kube/latest/kube/runtime/fn.metadata_watcher.html
[watcher::Event]: https://docs.rs/kube/latest/kube/runtime/watcher/enum.Event.html
[EventFlatten]: https://docs.rs/kube/latest/kube/runtime/utils/struct.EventFlatten.html
[EventDecode]: https://docs.rs/kube/latest/kube/runtime/utils/struct.EventDecode.html
[Recorder]: https://docs.rs/kube/latest/kube/runtime/events/struct.Recorder.html
[Event::modify]: https://docs.rs/kube/latest/kube/runtime/watcher/enum.Event.html#method.modify
[StreamExt]: https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html
Expand Down

0 comments on commit eba16de

Please sign in to comment.