Skip to content

Commit 0106fe8

Browse files
committed
small docs
1 parent 038818d commit 0106fe8

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@ The main feature of `Informer<T, U>` is that after calling `.poll()` you handle
6262
inf.poll()?; // watches + queues events
6363

6464
while let Some(event) = inf.pop() {
65-
reconcile(&client, event)?;
65+
handle_event(&client, event)?;
6666
}
6767
```
6868

6969
How you handle them is up to you, you could build your own state, you can call a kube client, or you can simply print events. Here's a sketch of how such a handler would look:
7070

7171
```rust
72-
fn reconcile(c: &APIClient, event: WatchEvent<PodSpec, PodStatus>) -> Result<(), failure::Error> {
73-
// use the kube api client here..
72+
fn handle_event(c: &APIClient, event: WatchEvent<PodSpec, PodStatus>) -> Result<(), failure::Error> {
7473
match ev {
7574
WatchEvent::Added(o) => {
7675
let containers = o.spec.containers.into_iter().map(|c| c.name).collect::<Vec<_>>();

examples/node_informer.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ use kube::{
44
client::APIClient,
55
config,
66
};
7-
use k8s_openapi::api::core::v1::{NodeSpec, NodeStatus};
8-
use k8s_openapi::api::core::v1::{Event, ListEventForAllNamespacesOptional};
7+
use k8s_openapi::api::core::v1::{
8+
NodeSpec, NodeStatus,
9+
Event, ListEventForAllNamespacesOptional,
10+
};
911

1012
fn main() -> Result<(), failure::Error> {
1113
std::env::set_var("RUST_LOG", "info,kube=trace");
@@ -59,7 +61,7 @@ fn handle_nodes(client: &APIClient, ev: WatchEvent<NodeSpec, NodeStatus>) -> Res
5961
);
6062
},
6163
WatchEvent::Error(e) => {
62-
warn!("Error event: {:?}", e); // ought to refresh here
64+
warn!("Error event: {:?}", e);
6365
}
6466
}
6567
Ok(())

examples/pod_informer.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ fn main() -> Result<(), failure::Error> {
2424

2525
// Handle events one by one, draining the informer
2626
while let Some(event) = inf.pop() {
27-
reconcile(&client, event)?;
27+
handle_node(&client, event)?;
2828
}
2929
}
3030
}
3131

3232
// This function lets the app handle an event from kube
33-
fn reconcile(_c: &APIClient, ev: WatchEvent<PodSpec, PodStatus>) -> Result<(), failure::Error> {
34-
// TODO: Use the kube api client here..
33+
fn handle_node(_c: &APIClient, ev: WatchEvent<PodSpec, PodStatus>) -> Result<(), failure::Error> {
3534
match ev {
3635
WatchEvent::Added(o) => {
3736
let containers = o.spec.containers.into_iter().map(|c| c.name).collect::<Vec<_>>();
@@ -45,7 +44,7 @@ fn reconcile(_c: &APIClient, ev: WatchEvent<PodSpec, PodStatus>) -> Result<(), f
4544
info!("Deleted Pod: {}", o.metadata.name);
4645
},
4746
WatchEvent::Error(e) => {
48-
warn!("Error event: {:?}", e); // ought to refresh here
47+
warn!("Error event: {:?}", e);
4948
}
5049
}
5150
Ok(())

examples/pod_reflector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn main() -> Result<(), failure::Error> {
1515
let resource = ResourceType::Pods(Some("kube-system".into()));
1616
let rf : Reflector<PodSpec, PodStatus> = Reflector::new(client.clone(), resource.into())?;
1717

18+
// Can read initial state now:
1819
rf.read()?.into_iter().for_each(|(name, p)| {
1920
info!("Found pod {} ({}) with {:?}",
2021
name,
@@ -23,12 +24,11 @@ fn main() -> Result<(), failure::Error> {
2324
);
2425
});
2526

26-
// Here we both poll and reconcile based on events from the main thread
27-
// If you run this next to actix-web (say), spawn a thread and pass `rf` as app state
27+
// Poll to keep data up to date:
2828
loop {
2929
rf.poll()?;
3030

31-
// Can also print internal state
31+
// up to date state:
3232
let pods = rf.read()?.into_iter().map(|(name, _)| name).collect::<Vec<_>>();
3333
info!("Current pods: {:?}", pods);
3434
}

src/client/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ impl APIClient {
106106
xs.push(r);
107107
}
108108
Ok(xs)
109-
110109
}
111110
}
112111
}

0 commit comments

Comments
 (0)