-
-
Notifications
You must be signed in to change notification settings - Fork 331
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
Document tokio dependency #849
Comments
What was the error? Note that examples depends on more crates and features. So, if you had copied a code out from there, you need to add any dependencies yourself.
tokio = { version = "1.14.0", features = ["macros"] } is necessary for This is not necessary to use |
I think there is some merit to calling this out explicitly, since tokio is currently the only async runtime we support. |
Good point. I probably misunderstood the original issue. |
@kazk From the examples/pod_api.rs example I had copied this code:
Because of the |
Sorry, I'm probably just confusing you. |
A bit. :)
(I remember something about |
You need to set up a runtime to call an async function in (using I think we should call out Tokio dependency and improve our docs, but I don't think it's necessary to, or should, include it in the top For example, hyper doesn't mention They add it on creating an example server guide before they show a code block with |
You can use #[tokio::main]
async fn main() {
...
} is basically syntax sugar for: fn main() {
tokio::runtime::Runtime::new().unwrap().block_on(async {
..
});
} |
- internals factor out hard stuff - relations factor out complexity from reconciler - info on associated crates for kube-rs/kube#849 Signed-off-by: clux <[email protected]>
If you want to see details on this you can look at tokio's runtime docs. But TL;DR: As a side-note, there's not been a lot of contest on the executor side recently, async-std basically stopped making releases for like a year, so not sure we need to elaborate on it a lot. I am writing a couple of lines on this in kube-rs/website#13 as it makes sense to recommend a runtime for a controller. Not sure we need it in the main README. Here's what I am considering going with: cutout from pr abovekube = { version = "0.69.1", features = ["runtime", "client", "derive"] }
k8s-openapi = { version = "0.14.0", features = ["v1_22"]}
tokio = { version = "1", features = ["macros", "rt-multi-thread"] } The `k8s-openapi` dependency is not always necessary, but we will be using [Pod] as our controlled [[object]], so we will need it here.
The `tokio` runtime dependency is necessary to use async rust features, and is the supported way to use futures created by kube.
!!! warning "Alternate async runtimes"
We depend on `tokio` for its `time`, `signal` and `sync` features, and while it is in theory possible to swap out a runtime, you would be sacrificing the most actively supported and most advanced runtime available. Avoid going down this alternate path unless you have a good reason. |
This is gold because as it turns out in a |
Runtime documented in the application part of the controller guide now: https://kube.rs/controllers/application/#main-dependencies |
Current and expected behavior
Currently the README says:
But these don't seem to be enough. To be able to run code from the examples I also had to add
It seems to work but my choice of runtime, version and features was pretty much arbitrary.
Possible solution
No response
Additional context
No response
Environment
Documentation bug
Configuration and features
No response
Affected crates
No response
Would you like to work on fixing this bug?
maybe
The text was updated successfully, but these errors were encountered: