Skip to content

Commit

Permalink
getting slightly further..
Browse files Browse the repository at this point in the history
Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Nov 21, 2023
1 parent 4ef65ad commit efcff5e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
3 changes: 2 additions & 1 deletion kube-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ws = ["client", "tokio-tungstenite", "rand", "kube-core/ws", "tokio/macros"]
oauth = ["client", "tame-oauth"]
oidc = ["client", "form_urlencoded"]
gzip = ["client", "tower-http/decompression-gzip"]
client = ["config", "__non_core", "hyper", "http-body", "hyper-tls", "hyper-util", "tower", "tower-http", "hyper-timeout", "pin-project", "chrono", "jsonpath_lib", "bytes", "futures", "tokio", "tokio-util", "either"]
client = ["config", "__non_core", "hyper", "http-body", "hyper-tls", "hyper-util", "http-body-util", "tower", "tower-http", "hyper-timeout", "pin-project", "chrono", "jsonpath_lib", "bytes", "futures", "tokio", "tokio-util", "either"]
jsonpatch = ["kube-core/jsonpatch"]
admission = ["kube-core/admission"]
config = ["__non_core", "pem", "home"]
Expand Down Expand Up @@ -62,6 +62,7 @@ hyper = { version = "1.0.1", optional = true, features = ["client", "http1"] }
hyper-rustls = { version = "0.24.0", optional = true }
hyper-tls = { version = "0.5.0", optional = true }
hyper-util = { version = "0.1.1", optional = true, features = ["client-legacy", "tokio"] }
http-body-util = { version = "0.1.0", optional = true }
hyper-socks2 = { version = "0.8.0", optional = true, default-features = false }
tokio-tungstenite = { version = "0.20.0", optional = true }
tower = { version = "0.4.13", optional = true, features = ["buffer", "filter", "util"] }
Expand Down
19 changes: 11 additions & 8 deletions kube-client/src/client/builder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use bytes::Bytes;
use http::{header::HeaderMap, Request, Response};
use http_body::Body;
use hyper::client::conn::http1::{Builder as HyperBuilder, Connection};
use http_body_util::{combinators::BoxBody, BodyExt, StreamBody};

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

View workflow job for this annotation

GitHub Actions / clippy

unused imports: `StreamBody`, `combinators::BoxBody`

warning: unused imports: `StreamBody`, `combinators::BoxBody` --> kube-client/src/client/builder.rs:3:22 | 3 | use http_body_util::{combinators::BoxBody, BodyExt, StreamBody}; | ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^

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

View workflow job for this annotation

GitHub Actions / msrv

unused imports: `StreamBody`, `combinators::BoxBody`
use hyper::{
body::{Body, Incoming},
client::conn::http1::{Builder as HyperBuilder, Connection},

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

View workflow job for this annotation

GitHub Actions / clippy

unused import: `Connection`

warning: unused import: `Connection` --> kube-client/src/client/builder.rs:6:52 | 6 | client::conn::http1::{Builder as HyperBuilder, Connection}, | ^^^^^^^^^^

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

View workflow job for this annotation

GitHub Actions / msrv

unused import: `Connection`
};
use hyper_timeout::TimeoutConnector;
use hyper_tls::HttpsConnector;

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

View workflow job for this annotation

GitHub Actions / clippy

unused import: `hyper_tls::HttpsConnector`

warning: unused import: `hyper_tls::HttpsConnector` --> kube-client/src/client/builder.rs:9:5 | 9 | use hyper_tls::HttpsConnector; | ^^^^^^^^^^^^^^^^^^^^^^^^^

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

View workflow job for this annotation

GitHub Actions / msrv

unused import: `hyper_tls::HttpsConnector`
use hyper_util::client::legacy::connect::HttpConnector; //uh private?
use hyper_util::client::legacy::connect::HttpConnector;
pub use kube_core::response::Status;

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

View workflow job for this annotation

GitHub Actions / clippy

unused import: `kube_core::response::Status`

warning: unused import: `kube_core::response::Status` --> kube-client/src/client/builder.rs:11:9 | 11 | pub use kube_core::response::Status; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
use std::time::Duration;
use tokio::io::{AsyncRead, AsyncWrite};
Expand All @@ -18,8 +21,8 @@ use crate::{client::ConfigExt, Client, Config, Error, Result};

/// HTTP body of a dynamic backing type.
///
/// The suggested implementation type is [`Body`].
pub type DynBody = dyn http_body::Body<Data = Bytes, Error = BoxError> + Send + Unpin;
/// The suggested implementation type is [`hyper::Incoming`].
pub type DynBody = dyn Body<Data = Bytes, Error = BoxError> + Send + Unpin;

/// Builder for [`Client`] instances with customized [tower](`Service`) middleware.
pub struct ClientBuilder<Svc> {
Expand All @@ -34,7 +37,7 @@ impl<Svc> ClientBuilder<Svc> {
/// which provides a default stack as a starting point.
pub fn new(service: Svc, default_namespace: impl Into<String>) -> Self
where
Svc: Service<Request<dyn Body>>,
Svc: Service<Request<Incoming>>,
{
Self {
service,
Expand All @@ -57,7 +60,7 @@ impl<Svc> ClientBuilder<Svc> {
/// Build a [`Client`] instance with the current [`Service`] stack.
pub fn build<B>(self) -> Client
where
Svc: Service<Request<dyn Body>, Response = Response<B>> + Send + 'static,
Svc: Service<Request<Incoming>, Response = Response<B>> + Send + 'static,
Svc::Future: Send + 'static,
Svc::Error: Into<BoxError>,
B: http_body::Body<Data = bytes::Bytes> + Send + 'static,
Expand All @@ -67,7 +70,7 @@ impl<Svc> ClientBuilder<Svc> {
}
}

pub type GenericService = BoxService<Request<dyn Body>, Response<Box<DynBody>>, BoxError>;
pub type GenericService = BoxService<Request<Incoming>, Response<Box<DynBody>>, BoxError>;

impl TryFrom<Config> for ClientBuilder<GenericService> {
type Error = Error;
Expand Down
3 changes: 1 addition & 2 deletions kube-client/src/client/config_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use hyper_util::client::legacy::connect::HttpConnector;
use secrecy::ExposeSecret;
use tower::{filter::AsyncFilterLayer, util::Either};

#[cfg(any(feature = "rustls-tls", feature = "openssl-tls"))]
use super::tls;
#[cfg(any(feature = "rustls-tls", feature = "openssl-tls"))] use super::tls;
use super::{
auth::Auth,
middleware::{AddAuthorizationLayer, AuthLayer, BaseUriLayer, ExtraHeadersLayer},
Expand Down
12 changes: 7 additions & 5 deletions kube-client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use either::{Either, Left, Right};
use futures::{self, AsyncBufRead, StreamExt, TryStream, TryStreamExt};

Check warning on line 11 in kube-client/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `TryStreamExt`

warning: unused import: `TryStreamExt` --> kube-client/src/client/mod.rs:11:57 | 11 | use futures::{self, AsyncBufRead, StreamExt, TryStream, TryStreamExt}; | ^^^^^^^^^^^^

Check warning on line 11 in kube-client/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `StreamExt`

warning: unused import: `StreamExt` --> kube-client/src/client/mod.rs:11:35 | 11 | use futures::{self, AsyncBufRead, StreamExt, TryStream, TryStreamExt}; | ^^^^^^^^^

Check warning on line 11 in kube-client/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / msrv

unused import: `TryStreamExt`
use http::{self, Request, Response, StatusCode};
use hyper::Body;
use http_body::Body;
use http_body_util::BodyStream;
use hyper::body::Incoming;
use k8s_openapi::apimachinery::pkg::apis::meta::v1 as k8s_meta_v1;
pub use kube_core::response::Status;
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -65,7 +67,7 @@ pub use builder::{ClientBuilder, DynBody};
pub struct Client {
// - `Buffer` for cheap clone
// - `BoxService` for dynamic response future type
inner: Buffer<BoxService<Request<Body>, Response<Body>, BoxError>, Request<Body>>,
inner: Buffer<BoxService<Request<Incoming>, Response<Incoming>, BoxError>, Request<Incoming>>,
default_ns: String,
}

Expand Down Expand Up @@ -99,15 +101,15 @@ impl Client {
/// ```
pub fn new<S, B, T>(service: S, default_namespace: T) -> Self
where
S: Service<Request<Body>, Response = Response<B>> + Send + 'static,
S: Service<Request<Incoming>, Response = Response<B>> + Send + 'static,
S::Future: Send + 'static,
S::Error: Into<BoxError>,
B: http_body::Body<Data = bytes::Bytes> + Send + 'static,
B::Error: Into<BoxError>,
T: Into<String>,
{
// Transform response body to `hyper::Body` and use type erased error to avoid type parameters.
let service = MapResponseBodyLayer::new(|b: B| Body::wrap_stream(b.into_stream()))
let service = MapResponseBodyLayer::new(|b: B| BodyStream::new(b.into_stream()))
.layer(service)
.map_err(|e| e.into());

Check failure on line 114 in kube-client/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

the method `map_err` exists for struct `MapResponseBody<S, {[email protected]:112:49}>`, but its trait bounds were not satisfied

error[E0599]: the method `map_err` exists for struct `MapResponseBody<S, {[email protected]:112:49}>`, but its trait bounds were not satisfied --> kube-client/src/client/mod.rs:114:14 | 112 | let service = MapResponseBodyLayer::new(|b: B| BodyStream::new(b.into_stream())) | _______________________- 113 | | .layer(service) 114 | | .map_err(|e| e.into()); | | -^^^^^^^ method cannot be called on `MapResponseBody<S, {[email protected]:112:49}>` due to unsatisfied trait bounds | |_____________| | | ::: /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-http-0.4.4/src/map_response_body.rs:130:1 | 130 | pub struct MapResponseBody<S, F> { | -------------------------------- | | | doesn't satisfy `_: Service<_>` | doesn't satisfy `_: ServiceExt<_>` | doesn't satisfy `_: TryStreamExt` | doesn't satisfy `_: TryStream` | = note: the following trait bounds were not satisfied: `tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: futures::TryStream` which is required by `tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: futures::TryStreamExt` `tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: tower::Service<_>` which is required by `tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: tower::ServiceExt<_>` `&tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: futures::TryStream` which is required by `&tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: futures::TryStreamExt` `&tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: tower::Service<_>` which is required by `&tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: tower::ServiceExt<_>` `&mut tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: futures::TryStream` which is required by `&mut tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: futures::TryStreamExt` `&mut tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: tower::Service<_>` which is required by `&mut tower_http::map_response_body::MapResponseBody<S, {closure@kube-client/src/client/mod.rs:112:49: 112:55}>: tower::ServiceExt<_>`
Self {
Expand Down Expand Up @@ -141,7 +143,7 @@ impl Client {
/// Perform a raw HTTP request against the API and return the raw response back.
/// This method can be used to get raw access to the API which may be used to, for example,
/// create a proxy server or application-level gateway between localhost and the API server.
pub async fn send(&self, request: Request<Body>) -> Result<Response<Body>> {
pub async fn send(&self, request: Request<Incoming>) -> Result<Response<Incoming>> {
let mut svc = self.inner.clone();
let res = svc
.ready()
Expand Down

0 comments on commit efcff5e

Please sign in to comment.