Restart Watcher programmatically after a timeout. #1737
Unanswered
mancioshell
asked this question in
Q&A
Replies: 2 comments 1 reply
-
as it stands, you have to recreate the |
Beta Was this translation helpful? Give feedback.
1 reply
-
I have found a solution (i don't know is the most efficient, but it works): pub fn watch_pods(&self) -> Store<Pod> {
let (store, writer) = reflector::store();
let environment = self.environment.clone();
let client = self.k8s_client.clone();
let pods_stream = futures::stream::unfold((), move |_| {
let environment = environment.clone();
let client: K8SClient = client.clone();
async move {
loop {
let (client, timeout_duration) = client.get_client().await;
let api: Api<Pod> = Api::all(client.clone());
println!("Downloading kubeconfig");
let stream = watcher(api, Default::default())
.modify(|obj| {
obj.managed_fields_mut().clear();
obj.annotations_mut().clear();
})
.filter({
move |obj| match obj {
Ok(event) => _filter_events(event, environment.clone()),
Err(_) => future::ready(false),
}
})
.take_until(tokio::time::sleep(timeout_duration));
println!("Stream: started");
return Some((stream, ()));
}
}
})
.flatten();
let watch = reflector(writer, pods_stream)
.default_backoff()
.touched_objects()
.for_each(|r| {
future::ready(match r {
Ok(o) => debug!(
"Pod with name {} in namespace {}",
o.name().unwrap(),
o.metadata.namespace.as_ref().unwrap()
),
Err(e) => warn!("watcher error: {e}"),
})
});
tokio::spawn(watch);
return store;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have the need to download a new kubeconfig after a certain timeout.
I'm using with success kube.rs, to expose api rest through a reflector with a watcher.
But i need to restart the watcher, with a new client (and a new kubeconfig) after a certain timeout has expired.
Any suggest?
Beta Was this translation helpful? Give feedback.
All reactions