Skip to content

hyper/http 1.0 bumps #1352

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

Closed
wants to merge 21 commits into from
Closed
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 examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ tar = "0.4.37"
tracing = "0.1.36"
tracing-subscriber = "0.3.3"
warp = { version = "0.3", default-features = false, features = ["tls"] }
http = "0.2.5"
http = "1.0.0"
json-patch = "1.0.0"
tower = { version = "0.4.13", features = ["limit"] }
tower-http = { version = "0.4.0", features = ["trace", "decompression-gzip"] }
hyper = { version = "0.14.13", features = ["client", "http1", "stream", "tcp"] }
tower-http = { version = "0.5.1", features = ["trace", "decompression-gzip"] }
hyper = { version = "1.1.0", features = ["client", "http1"] }
thiserror = "1.0.29"
backoff = "0.4.0"
clap = { version = "4.0", default-features = false, features = ["std", "cargo", "derive"] }
Expand Down
34 changes: 22 additions & 12 deletions 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", "tower", "tower-http", "hyper-timeout", "pin-project", "chrono", "jsonpath-rust", "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-rust", "bytes", "futures", "tokio", "tokio-util", "either"]
jsonpatch = ["kube-core/jsonpatch"]
admission = ["kube-core/admission"]
config = ["__non_core", "pem", "home"]
Expand All @@ -44,35 +44,45 @@ home = { version = "0.5.4", optional = true }
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.68"
serde_yaml = { version = "0.9.19", optional = true }
http = "0.2.5"
http-body = { version = "0.4.2", optional = true }
http = "1.0.0"
http-body = { version = "1.0.0", optional = true }
either = { version = "1.6.1", optional = true }
thiserror = "1.0.29"
futures = { version = "0.3.17", optional = true }
pem = { version = "3.0.1", optional = true }
openssl = { version = "0.10.36", optional = true }
rustls = { version = "0.21.4", features = ["dangerous_configuration"], optional = true }
rustls-pemfile = { version = "1.0.0", optional = true }
rustls = { version = "0.22.2", optional = true }
rustls-pemfile = { version = "2.0.0", optional = true }
bytes = { version = "1.1.0", optional = true }
tokio = { version = "1.14.0", features = ["time", "signal", "sync"], optional = true }
kube-core = { path = "../kube-core", version = "=0.88.0" }
jsonpath-rust = { version = "0.4.0", optional = true }
tokio-util = { version = "0.7.0", optional = true, features = ["io", "codec"] }
hyper = { version = "0.14.13", optional = true, features = ["client", "http1", "stream", "tcp"] }
hyper-rustls = { version = "0.24.0", optional = true }
hyper-socks2 = { version = "0.8.0", optional = true, default-features = false }
tokio-tungstenite = { version = "0.20.0", optional = true }
hyper = { version = "1.1.0", optional = true, features = ["client", "http1"] }
hyper-rustls = { version = "0.26.0", optional = true }
hyper-tls = { version = "0.6.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 } # using fork below
tokio-tungstenite = { version = "0.21.0", optional = true }
tower = { version = "0.4.13", optional = true, features = ["buffer", "filter", "util"] }
tower-http = { version = "0.4.0", optional = true, features = ["auth", "map-response-body", "trace"] }
hyper-timeout = {version = "0.4.1", optional = true }
tower-http = { version = "0.5.1", optional = true, features = ["auth", "map-response-body", "trace"] }
hyper-timeout = {version = "0.5.1", optional = true }
tame-oauth = { version = "0.9.1", features = ["gcp"], optional = true }
pin-project = { version = "1.0.4", optional = true }
rand = { version = "0.8.3", optional = true }
secrecy = { version = "0.8.0", features = ["alloc", "serde"] }
tracing = { version = "0.1.36", features = ["log"], optional = true }
hyper-openssl = { version = "0.9.2", optional = true }
hyper-openssl = { version = "0.10.1", optional = true }
form_urlencoded = { version = "1.2.0", optional = true }

[dependencies.hyper-socks2]
git = "https://github.com/aviramha/hyper-socks2.git"
#branch = "hyper1"
rev = "947387f377ed441e42cc61a3397333a20932f28f"
optional = true
default-features = false

[dependencies.k8s-openapi]
version = "0.21.0"
default-features = false
Expand Down
27 changes: 14 additions & 13 deletions kube-client/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
//! API helpers for structured interaction with the Kubernetes API

mod core_methods;
#[cfg(feature = "ws")] mod remote_command;
// TODO: reinstate..
//mod core_methods;
//#[cfg(feature = "ws")] mod remote_command;
use std::fmt::Debug;

#[cfg(feature = "ws")] pub use remote_command::{AttachedProcess, TerminalSize};
#[cfg(feature = "ws")] mod portforward;
#[cfg(feature = "ws")] pub use portforward::Portforwarder;
//#[cfg(feature = "ws")] pub use remote_command::{AttachedProcess, TerminalSize};
//#[cfg(feature = "ws")] mod portforward;
//#[cfg(feature = "ws")] pub use portforward::Portforwarder;

mod subresource;
#[cfg(feature = "ws")]
//mod subresource;
/*#[cfg(feature = "ws")]
#[cfg_attr(docsrs, doc(cfg(feature = "ws")))]
pub use subresource::{Attach, AttachParams, Execute, Portforward};
pub use subresource::{Evict, EvictParams, Log, LogParams, ScaleSpec, ScaleStatus};

*/
// Ephemeral containers were stabilized in Kubernetes 1.25.
k8s_openapi::k8s_if_ge_1_25! {
pub use subresource::Ephemeral;
}
//k8s_openapi::k8s_if_ge_1_25! {
// pub use subresource::Ephemeral;
//}

mod util;
//mod util;

pub mod entry;
//pub mod entry;

// Re-exports from kube-core
#[cfg(feature = "admission")]
Expand Down
8 changes: 4 additions & 4 deletions kube-client/src/client/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use tower::{filter::AsyncPredicate, BoxError};

use crate::config::{AuthInfo, AuthProviderConfig, ExecAuthCluster, ExecConfig, ExecInteractiveMode};

#[cfg(feature = "oauth")] mod oauth;
#[cfg(feature = "oauth")] pub use oauth::Error as OAuthError;
#[cfg(feature = "oidc")] mod oidc;
#[cfg(feature = "oidc")] pub use oidc::errors as oidc_errors;
//#[cfg(feature = "oauth")] mod oauth;
//#[cfg(feature = "oauth")] pub use oauth::Error as OAuthError;
//#[cfg(feature = "oidc")] mod oidc;
//#[cfg(feature = "oidc")] pub use oidc::errors as oidc_errors;
#[cfg(target_os = "windows")] use std::os::windows::process::CommandExt;

#[derive(Error, Debug)]
Expand Down
39 changes: 21 additions & 18 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_util::{combinators::BoxBody, BodyExt, StreamBody};
use hyper::{
self,
client::{connect::Connection, HttpConnector},
body::{Body, Incoming},
client::conn::http1::Connection,
};
use hyper_timeout::TimeoutConnector;
use hyper_tls::HttpsConnector;
use hyper_util::client::legacy::{connect::HttpConnector, Builder as HyperBuilder};
pub use kube_core::response::Status;
use std::time::Duration;
use tokio::io::{AsyncRead, AsyncWrite};
Expand All @@ -17,9 +20,7 @@ use tracing::Span;
use crate::{client::ConfigExt, Client, Config, Error, Result};

/// HTTP body of a dynamic backing type.
///
/// The suggested implementation type is [`hyper::Body`].
pub type DynBody = dyn http_body::Body<Data = Bytes, Error = BoxError> + Send + Unpin;
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 +35,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<hyper::Body>>,
Svc: Service<Request<Bytes>>,
{
Self {
service,
Expand All @@ -57,7 +58,7 @@ impl<Svc> ClientBuilder<Svc> {
/// Build a [`Client`] instance with the current [`Service`] stack.
pub fn build<B>(self) -> Client
where
Svc: Service<Request<hyper::Body>, Response = Response<B>> + Send + 'static,
Svc: Service<Request<Bytes>, 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 +68,7 @@ impl<Svc> ClientBuilder<Svc> {
}
}

pub type GenericService = BoxService<Request<hyper::Body>, Response<Box<DynBody>>, BoxError>;
pub type GenericService = BoxService<Request<Bytes>, Response<BoxBody<Bytes, BoxError>>, BoxError>;

impl TryFrom<Config> for ClientBuilder<GenericService> {
type Error = Error;
Expand Down Expand Up @@ -97,14 +98,14 @@ impl TryFrom<Config> for ClientBuilder<GenericService> {
fn make_generic_builder<H>(connector: H, config: Config) -> Result<ClientBuilder<GenericService>, Error>
where
H: 'static + Clone + Send + Sync + Service<http::Uri>,
H::Response: 'static + Connection + AsyncRead + AsyncWrite + Send + Unpin,
H::Response: 'static + AsyncRead + AsyncWrite + Send + Unpin,
H::Future: 'static + Send,
H::Error: 'static + Send + Sync + std::error::Error,
{
let default_ns = config.default_namespace.clone();
let auth_layer = config.auth_layer()?;

let client: hyper::Client<_, hyper::Body> = {
let client = {
// Current TLS feature precedence when more than one are set:
// 1. rustls-tls
// 2. openssl-tls
Expand All @@ -120,14 +121,16 @@ where
return Err(Error::TlsRequired);
}

let mut connector = TimeoutConnector::new(connector);
//TODO: fix bound
//let mut connector = TimeoutConnector::new(connector);

// Set the timeouts for the client
connector.set_connect_timeout(config.connect_timeout);
connector.set_read_timeout(config.read_timeout);
connector.set_write_timeout(config.write_timeout);
// connector.set_connect_timeout(config.connect_timeout);
// connector.set_read_timeout(config.read_timeout);
// connector.set_write_timeout(config.write_timeout);

hyper::Client::builder().build(connector)
use hyper_util::rt::TokioExecutor; // seems necessary now
HyperBuilder::new(TokioExecutor::new()).build(connector)
};

let stack = ServiceBuilder::new().layer(config.base_uri_layer()).into_inner();
Expand All @@ -145,7 +148,7 @@ where
// Attribute names follow [Semantic Conventions].
// [Semantic Conventions]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md
TraceLayer::new_for_http()
.make_span_with(|req: &Request<hyper::Body>| {
.make_span_with(|req: &Request<Incoming>| {
tracing::debug_span!(
"HTTP",
http.method = %req.method(),
Expand All @@ -156,10 +159,10 @@ where
otel.status_code = tracing::field::Empty,
)
})
.on_request(|_req: &Request<hyper::Body>, _span: &Span| {
.on_request(|_req: &Request<Incoming>, _span: &Span| {
tracing::debug!("requesting");
})
.on_response(|res: &Response<hyper::Body>, _latency: Duration, span: &Span| {
.on_response(|res: &Response<Incoming>, _latency: Duration, span: &Span| {
let status = res.status();
span.record("http.status_code", status.as_u16());
if status.is_client_error() || status.is_server_error() {
Expand Down
34 changes: 16 additions & 18 deletions kube-client/src/client/config_ext.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use http::{header::HeaderName, HeaderValue};
use hyper_util::client::legacy::connect::HttpConnector;
use secrecy::ExposeSecret;
use tower::{filter::AsyncFilterLayer, util::Either};

Expand All @@ -26,7 +27,7 @@ pub trait ConfigExt: private::Sealed {
/// Layer to add non-authn HTTP headers depending on the config.
fn extra_headers_layer(&self) -> Result<ExtraHeadersLayer>;

/// Create [`hyper_rustls::HttpsConnector`] based on config.
/// Create [`HttpsConnector`] based on config.
///
/// # Example
///
Expand All @@ -41,16 +42,16 @@ pub trait ConfigExt: private::Sealed {
/// ```
#[cfg_attr(docsrs, doc(cfg(feature = "rustls-tls")))]
#[cfg(feature = "rustls-tls")]
fn rustls_https_connector(&self) -> Result<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>>;
fn rustls_https_connector(&self) -> Result<hyper_rustls::HttpsConnector<HttpConnector>>;

/// Create [`hyper_rustls::HttpsConnector`] based on config and `connector`.
/// Create [`HttpsConnector`] based on config and `connector`.
///
/// # Example
///
/// ```rust
/// # async fn doc() -> Result<(), Box<dyn std::error::Error>> {
/// # use kube::{client::ConfigExt, Config};
/// # use hyper::client::HttpConnector;
/// # use hyper_util::client::legacy::connect::HttpConnector;
/// let config = Config::infer().await?;
/// let mut connector = HttpConnector::new();
/// connector.enforce_http(false);
Expand All @@ -71,7 +72,7 @@ pub trait ConfigExt: private::Sealed {
///
/// ```rust
/// # async fn doc() -> Result<(), Box<dyn std::error::Error>> {
/// # use hyper::client::HttpConnector;
/// # use hyper_util::client::legacy::connect::HttpConnector;
/// # use kube::{client::ConfigExt, Config};
/// let config = Config::infer().await?;
/// let https = {
Expand All @@ -87,7 +88,7 @@ pub trait ConfigExt: private::Sealed {
#[cfg(feature = "rustls-tls")]
fn rustls_client_config(&self) -> Result<rustls::ClientConfig>;

/// Create [`hyper_openssl::HttpsConnector`] based on config.
/// Create [`HttpsConnector`] based on config.
/// # Example
///
/// ```rust
Expand All @@ -100,14 +101,14 @@ pub trait ConfigExt: private::Sealed {
/// ```
#[cfg_attr(docsrs, doc(cfg(feature = "openssl-tls")))]
#[cfg(feature = "openssl-tls")]
fn openssl_https_connector(&self) -> Result<hyper_openssl::HttpsConnector<hyper::client::HttpConnector>>;
fn openssl_https_connector(&self) -> Result<HttpsConnector<HttpConnector>>;

/// Create [`hyper_openssl::HttpsConnector`] based on config and `connector`.
/// Create [`HttpsConnector`] based on config and `connector`.
/// # Example
///
/// ```rust
/// # async fn doc() -> Result<(), Box<dyn std::error::Error>> {
/// # use hyper::client::HttpConnector;
/// # use hyper_util::client::legacy::connect::HttpConnector;
/// # use kube::{client::ConfigExt, Config};
/// let mut http = HttpConnector::new();
/// http.enforce_http(false);
Expand All @@ -134,7 +135,7 @@ pub trait ConfigExt: private::Sealed {
///
/// ```rust
/// # async fn doc() -> Result<(), Box<dyn std::error::Error>> {
/// # use hyper::client::HttpConnector;
/// # use hyper_util::client::legacy::connect::HttpConnector;
/// # use kube::{client::ConfigExt, Client, Config};
/// let config = Config::infer().await?;
/// let https = {
Expand Down Expand Up @@ -214,8 +215,8 @@ impl ConfigExt for Config {
}

#[cfg(feature = "rustls-tls")]
fn rustls_https_connector(&self) -> Result<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>> {
let mut connector = hyper::client::HttpConnector::new();
fn rustls_https_connector(&self) -> Result<hyper_rustls::HttpsConnector<HttpConnector>> {
let mut connector = HttpConnector::new();
connector.enforce_http(false);
self.rustls_https_connector_with_connector(connector)
}
Expand Down Expand Up @@ -244,17 +245,14 @@ impl ConfigExt for Config {
}

#[cfg(feature = "openssl-tls")]
fn openssl_https_connector(&self) -> Result<hyper_openssl::HttpsConnector<hyper::client::HttpConnector>> {
let mut connector = hyper::client::HttpConnector::new();
fn openssl_https_connector(&self) -> Result<HttpsConnector<HttpConnector>> {
let mut connector = HttpConnector::new();
connector.enforce_http(false);
self.openssl_https_connector_with_connector(connector)
}

#[cfg(feature = "openssl-tls")]
fn openssl_https_connector_with_connector<H>(
&self,
connector: H,
) -> Result<hyper_openssl::HttpsConnector<H>>
fn openssl_https_connector_with_connector<H>(&self, connector: H) -> Result<HttpsConnector<H>>
where
H: tower::Service<http::Uri> + Send,
H::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
Expand Down
Loading