Skip to content
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

Upgrades Tower to 0.5.1 #1589

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ http = "1.1.0"
http-body = "1.0.0"
http-body-util = "0.1.2"
hyper = "1.2.0"
hyper-util = "0.1.3"
hyper-util = "0.1.9"
hyper-openssl = "0.10.2"
hyper-rustls = { version = "0.27.1", default-features = false }
hyper-socks2 = { version = "0.9.0", default-features = false }
Expand Down Expand Up @@ -84,8 +84,8 @@ tokio = "1.14.0"
tokio-test = "0.4.0"
tokio-tungstenite = "0.24.0"
tokio-util = "0.7.0"
tower = "0.4.13"
tower-http = "0.5.2"
tower = "0.5.1"
tower-http = "0.6.1"
tower-test = "0.4.0"
tracing = "0.1.36"
tracing-subscriber = "0.3.17"
Expand Down
2 changes: 2 additions & 0 deletions examples/custom_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use hyper_util::rt::TokioExecutor;
// Minimal custom client example.
use k8s_openapi::api::core::v1::Pod;
use tower::BoxError;
use tracing::*;

use kube::{client::ConfigExt, Api, Client, Config, ResourceExt};
Expand All @@ -15,6 +16,7 @@ async fn main() -> anyhow::Result<()> {
let service = tower::ServiceBuilder::new()
.layer(config.base_uri_layer())
.option_layer(config.auth_layer()?)
.map_err(BoxError::from)
.service(hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build(https));
let client = Client::new(service, config.default_namespace);

Expand Down
3 changes: 2 additions & 1 deletion examples/custom_client_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use hyper::body::Incoming;
use hyper_util::rt::TokioExecutor;
use k8s_openapi::api::core::v1::Pod;
use std::time::Duration;
use tower::ServiceBuilder;
use tower::{BoxError, ServiceBuilder};
use tower_http::{decompression::DecompressionLayer, trace::TraceLayer};
use tracing::{Span, *};

Expand Down Expand Up @@ -54,6 +54,7 @@ async fn main() -> anyhow::Result<()> {
tracing::debug!("finished in {}ms", latency.as_millis())
}),
)
.map_err(BoxError::from)
.service(hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build(https));

let client = Client::new(service, config.default_namespace);
Expand Down
1 change: 1 addition & 0 deletions kube-client/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
}
}),
)
.map_err(BoxError::from)

Check warning on line 216 in kube-client/src/client/builder.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/builder.rs#L216

Added line #L216 was not covered by tests
.service(client);

Ok(ClientBuilder::new(
Expand Down
6 changes: 3 additions & 3 deletions kube-client/src/client/config_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@
fn auth_layer(&self) -> Result<Option<AuthLayer>> {
Ok(match Auth::try_from(&self.auth_info).map_err(Error::Auth)? {
Auth::None => None,
Auth::Basic(user, pass) => Some(AuthLayer(Either::A(
Auth::Basic(user, pass) => Some(AuthLayer(Either::Left(

Check warning on line 170 in kube-client/src/client/config_ext.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/config_ext.rs#L170

Added line #L170 was not covered by tests
AddAuthorizationLayer::basic(&user, pass.expose_secret()).as_sensitive(true),
))),
Auth::Bearer(token) => Some(AuthLayer(Either::A(
Auth::Bearer(token) => Some(AuthLayer(Either::Left(

Check warning on line 173 in kube-client/src/client/config_ext.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/config_ext.rs#L173

Added line #L173 was not covered by tests
AddAuthorizationLayer::bearer(token.expose_secret()).as_sensitive(true),
))),
Auth::RefreshableToken(refreshable) => {
Some(AuthLayer(Either::B(AsyncFilterLayer::new(refreshable))))
Some(AuthLayer(Either::Right(AsyncFilterLayer::new(refreshable))))

Check warning on line 177 in kube-client/src/client/config_ext.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/config_ext.rs#L177

Added line #L177 was not covered by tests
}
Auth::Certificate(_client_certificate_data, _client_key_data) => None,
})
Expand Down
9 changes: 5 additions & 4 deletions kube-client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! The [`Client`] can also be used with [`Discovery`](crate::Discovery) to dynamically
//! retrieve the resources served by the kubernetes API.
use either::{Either, Left, Right};
use futures::{AsyncBufRead, StreamExt, TryStream, TryStreamExt};
use futures::{future::BoxFuture, AsyncBufRead, StreamExt, TryStream, TryStreamExt};
use http::{self, Request, Response};
use http_body_util::BodyExt;
#[cfg(feature = "ws")] use hyper_util::rt::TokioIo;
Expand Down Expand Up @@ -75,8 +75,8 @@ pub use builder::{ClientBuilder, DynBody};
#[derive(Clone)]
pub struct Client {
// - `Buffer` for cheap clone
// - `BoxService` for dynamic response future type
inner: Buffer<BoxService<Request<Body>, Response<Body>, BoxError>, Request<Body>>,
// - `BoxFuture` for dynamic response future type
inner: Buffer<Request<Body>, BoxFuture<'static, Result<Response<Body>, BoxError>>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does seem like a nicer signature split. Interesting that it has to be 'static though. Is that a problem you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BoxServicecan only be created by moving the underlying Service - https://docs.rs/tower/latest/tower/util/struct.BoxService.html#impl-BoxService%3CT,+U,+E%3E whereas a BoxFuture can be created from a ref, hence generic over lifetime.

The kube::Client design owns the Buffer and to make Buffer Clone the Future needs to be 'static - https://tower-rs.github.io/tower/tower/buffer/struct.Buffer.html#impl-Clone-for-Buffer%3CReq,+F%3E

So 'static here is both unavoidable & fine (IMO!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar in the Tonic upgrade PR - https://github.com/hyperium/tonic/pull/1892/files

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thanks for explaining!

default_ns: String,
}

Expand All @@ -102,13 +102,14 @@ impl Client {
/// ```rust
/// # async fn doc() -> Result<(), Box<dyn std::error::Error>> {
/// use kube::{client::ConfigExt, Client, Config};
/// use tower::ServiceBuilder;
/// use tower::{BoxError, ServiceBuilder};
/// use hyper_util::rt::TokioExecutor;
///
/// let config = Config::infer().await?;
/// let service = ServiceBuilder::new()
/// .layer(config.base_uri_layer())
/// .option_layer(config.auth_layer()?)
/// .map_err(BoxError::from)
/// .service(hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build_http());
/// let client = Client::new(service, config.default_namespace);
/// # Ok(())
Expand Down
Loading