Skip to content

Commit f6edd39

Browse files
committed
update to hyper 1
Signed-off-by: tottoto <[email protected]>
1 parent bc74325 commit f6edd39

22 files changed

+330
-155
lines changed

Cargo.toml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ form_urlencoded = "1.2.0"
2929
futures = "0.3.17"
3030
hashbrown = "0.14.0"
3131
home = "0.5.4"
32-
http = "0.2.9"
33-
http-body = "0.4.2"
34-
hyper = "0.14.27"
35-
hyper-openssl = "0.9.2"
36-
hyper-rustls = "0.24.0"
37-
hyper-socks2 = { version = "0.8.0", default-features = false }
38-
hyper-timeout = "0.4.1"
32+
http = "1.1.0"
33+
http-body = "1.0.0"
34+
http-body-util = "0.1.1"
35+
hyper = "1.2.0"
36+
hyper-util = "0.1.3"
37+
hyper-openssl = "0.10.2"
38+
hyper-rustls = "0.26.0"
39+
hyper-socks2 = { version = "0.9.0", default-features = false }
40+
hyper-timeout = "0.5.1"
3941
json-patch = "1.0.0"
4042
jsonpath-rust = "0.5.0"
4143
k8s-openapi = { version = "0.21.0", default-features = false }
@@ -47,24 +49,24 @@ pin-project = "1.0.4"
4749
proc-macro2 = "1.0.29"
4850
quote = "1.0.10"
4951
rand = "0.8.3"
50-
rustls = "0.21.4"
51-
rustls-pemfile = "1.0.0"
52+
rustls = "0.22.0"
53+
rustls-pemfile = "2.0.0"
5254
schemars = "0.8.6"
5355
secrecy = "0.8.0"
5456
serde = "1.0.130"
5557
serde_json = "1.0.68"
5658
serde_yaml = "0.9.19"
5759
smallvec = "1.7.0"
5860
syn = "2.0.38"
59-
tame-oauth = "0.9.1"
61+
tame-oauth = "0.10.0"
6062
tempfile = "3.1.0"
6163
thiserror = "1.0.29"
6264
tokio = "1.14.0"
6365
tokio-test = "0.4.0"
64-
tokio-tungstenite = "0.20.0"
66+
tokio-tungstenite = "0.21.0"
6567
tokio-util = "0.7.0"
6668
tower = "0.4.13"
67-
tower-http = "0.4.0"
69+
tower-http = "0.5.2"
6870
tower-test = "0.4.0"
6971
tracing = "0.1.36"
7072
tracing-subscriber = "0.3.17"

examples/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ tar = "0.4.37"
4646
tracing.workspace = true
4747
tracing-subscriber.workspace = true
4848
warp = { version = "0.3", default-features = false, features = ["tls"] }
49+
bytes.workspace = true
4950
http.workspace = true
51+
http-body-util.workspace = true
5052
json-patch.workspace = true
5153
tower = { workspace = true, features = ["limit"] }
5254
tower-http = { workspace = true, features = ["trace", "decompression-gzip"] }
53-
hyper = { workspace = true, features = ["client", "http1", "stream", "tcp"] }
55+
hyper = { workspace = true, features = ["client", "http1"] }
56+
hyper-util = { workspace = true, features = ["client-legacy", "http1", "tokio"] }
5457
thiserror.workspace = true
5558
backoff.workspace = true
5659
clap = { version = "4.0", default-features = false, features = ["std", "cargo", "derive"] }

examples/custom_client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use hyper_util::rt::TokioExecutor;
12
// Minimal custom client example.
23
use k8s_openapi::api::core::v1::Pod;
34
use tracing::*;
@@ -14,7 +15,7 @@ async fn main() -> anyhow::Result<()> {
1415
let service = tower::ServiceBuilder::new()
1516
.layer(config.base_uri_layer())
1617
.option_layer(config.auth_layer()?)
17-
.service(hyper::Client::builder().build(https));
18+
.service(hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build(https));
1819
let client = Client::new(service, config.default_namespace);
1920

2021
let pods: Api<Pod> = Api::default_namespaced(client);

examples/custom_client_tls.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use hyper_util::rt::TokioExecutor;
12
// Custom client supporting both openssl-tls and rustls-tls
23
// Must enable `rustls-tls` feature to run this.
34
// Run with `USE_RUSTLS=1` to pick rustls.
@@ -19,13 +20,13 @@ async fn main() -> anyhow::Result<()> {
1920
let https = config.openssl_https_connector()?;
2021
let service = ServiceBuilder::new()
2122
.layer(config.base_uri_layer())
22-
.service(hyper::Client::builder().build(https));
23+
.service(hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build(https));
2324
Client::new(service, config.default_namespace)
2425
} else {
2526
let https = config.rustls_https_connector()?;
2627
let service = ServiceBuilder::new()
2728
.layer(config.base_uri_layer())
28-
.service(hyper::Client::builder().build(https));
29+
.service(hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build(https));
2930
Client::new(service, config.default_namespace)
3031
};
3132

examples/custom_client_trace.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// Custom client example with TraceLayer.
22
use http::{Request, Response};
3-
use hyper::Body;
3+
use hyper::body::Incoming;
4+
use hyper_util::rt::TokioExecutor;
45
use k8s_openapi::api::core::v1::Pod;
56
use std::time::Duration;
67
use tower::ServiceBuilder;
78
use tower_http::{decompression::DecompressionLayer, trace::TraceLayer};
89
use tracing::{Span, *};
910

10-
use kube::{client::ConfigExt, Api, Client, Config, ResourceExt};
11+
use kube::{
12+
client::{Body, ConfigExt},
13+
Api, Client, Config, ResourceExt,
14+
};
1115

1216
#[tokio::main]
1317
async fn main() -> anyhow::Result<()> {
@@ -40,7 +44,7 @@ async fn main() -> anyhow::Result<()> {
4044
.on_request(|request: &Request<Body>, _span: &Span| {
4145
tracing::debug!("payload: {:?} headers: {:?}", request.body(), request.headers())
4246
})
43-
.on_response(|response: &Response<Body>, latency: Duration, span: &Span| {
47+
.on_response(|response: &Response<Incoming>, latency: Duration, span: &Span| {
4448
let status = response.status();
4549
span.record("http.status_code", status.as_u16());
4650
if status.is_client_error() || status.is_server_error() {
@@ -49,7 +53,7 @@ async fn main() -> anyhow::Result<()> {
4953
tracing::debug!("finished in {}ms", latency.as_millis())
5054
}),
5155
)
52-
.service(hyper::Client::builder().build(https));
56+
.service(hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build(https));
5357

5458
let client = Client::new(service, config.default_namespace);
5559

examples/pod_portforward_hyper_http.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use bytes::Bytes;
2+
use hyper_util::rt::TokioIo;
13
use k8s_openapi::api::core::v1::Pod;
24
use kube::{
35
api::{Api, DeleteParams, PostParams},
@@ -6,7 +8,8 @@ use kube::{
68
};
79
use tracing::*;
810

9-
use hyper::{body, Body, Request};
11+
use http::Request;
12+
use http_body_util::BodyExt;
1013

1114
#[tokio::main]
1215
async fn main() -> anyhow::Result<()> {
@@ -37,7 +40,7 @@ async fn main() -> anyhow::Result<()> {
3740
let port = pf.take_stream(80).unwrap();
3841

3942
// let hyper drive the HTTP state in our DuplexStream via a task
40-
let (mut sender, connection) = hyper::client::conn::handshake(port).await?;
43+
let (mut sender, connection) = hyper::client::conn::http1::handshake(TokioIo::new(port)).await?;
4144
tokio::spawn(async move {
4245
if let Err(e) = connection.await {
4346
warn!("Error in connection: {}", e);
@@ -49,13 +52,13 @@ async fn main() -> anyhow::Result<()> {
4952
.header("Connection", "close")
5053
.header("Host", "127.0.0.1")
5154
.method("GET")
52-
.body(Body::from(""))
55+
.body(http_body_util::Empty::<Bytes>::new())
5356
.unwrap();
5457

5558
let (parts, body) = sender.send_request(http_req).await?.into_parts();
5659
assert!(parts.status == 200);
5760

58-
let body_bytes = body::to_bytes(body).await?;
61+
let body_bytes = body.collect().await?.to_bytes();
5962
let body_str = std::str::from_utf8(&body_bytes)?;
6063
assert!(body_str.contains("Welcome to nginx!"));
6164

examples/request_raw.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use k8s_openapi::{api::core::v1::Node, apimachinery::pkg::api::resource::Quantit
1010
use kube::{api::ListParams, Api, ResourceExt};
1111
use serde::Deserialize;
1212

13-
1413
#[tokio::main]
1514
async fn main() -> anyhow::Result<()> {
1615
let client = kube::Client::try_default().await?;
@@ -89,7 +88,6 @@ enum Metric {
8988
Memory { usage_bytes: usize },
9089
}
9190

92-
9391
fn print_table(summaries: Vec<NodeSummary>) {
9492
use headers::*;
9593

@@ -142,7 +140,6 @@ fn print_table(summaries: Vec<NodeSummary>) {
142140
}
143141
}
144142

145-
146143
// === impl Metric ===
147144

148145
impl Metric {

kube-client/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ kubelet-debug = ["ws", "kube-core/kubelet-debug"]
2424
oauth = ["client", "tame-oauth"]
2525
oidc = ["client", "form_urlencoded"]
2626
gzip = ["client", "tower-http/decompression-gzip"]
27-
client = ["config", "__non_core", "hyper", "http-body", "tower", "tower-http", "hyper-timeout", "pin-project", "chrono", "jsonpath-rust", "bytes", "futures", "tokio", "tokio-util", "either"]
27+
client = ["config", "__non_core", "hyper", "hyper-util", "http-body", "http-body-util", "tower", "tower-http", "hyper-timeout", "pin-project", "chrono", "jsonpath-rust", "bytes", "futures", "tokio", "tokio-util", "either"]
2828
jsonpatch = ["kube-core/jsonpatch"]
2929
admission = ["kube-core/admission"]
3030
config = ["__non_core", "pem", "home"]
@@ -48,19 +48,21 @@ serde_json.workspace = true
4848
serde_yaml = { workspace = true, optional = true }
4949
http.workspace = true
5050
http-body = { workspace = true, optional = true }
51+
http-body-util = { workspace = true, optional = true }
5152
either = { workspace = true, optional = true }
5253
thiserror.workspace = true
5354
futures = { workspace = true, optional = true }
5455
pem = { workspace = true, optional = true }
5556
openssl = { workspace = true, optional = true }
56-
rustls = { workspace = true, features = ["dangerous_configuration"], optional = true }
57+
rustls = { workspace = true, optional = true }
5758
rustls-pemfile = { workspace = true, optional = true }
5859
bytes = { workspace = true, optional = true }
5960
tokio = { workspace = true, features = ["time", "signal", "sync"], optional = true }
6061
kube-core = { path = "../kube-core", version = "=0.88.1" }
6162
jsonpath-rust = { workspace = true, optional = true }
6263
tokio-util = { workspace = true, features = ["io", "codec"], optional = true }
63-
hyper = { workspace = true, features = ["client", "http1", "stream", "tcp"], optional = true }
64+
hyper = { workspace = true, features = ["client", "http1"], optional = true }
65+
hyper-util = { workspace = true, features = ["client", "client-legacy", "http1", "tokio"], optional = true }
6466
hyper-rustls = { workspace = true, optional = true }
6567
hyper-socks2 = { workspace = true, optional = true }
6668
tokio-tungstenite = { workspace = true, optional = true }
@@ -72,7 +74,7 @@ pin-project = { workspace = true, optional = true }
7274
rand = { workspace = true, optional = true }
7375
secrecy = { workspace = true, features = ["alloc", "serde"] }
7476
tracing = { workspace = true, features = ["log"], optional = true }
75-
hyper-openssl = { workspace = true, optional = true }
77+
hyper-openssl = { workspace = true, features = ["client-legacy"], optional = true }
7678
form_urlencoded = { workspace = true, optional = true }
7779
k8s-openapi= { workspace = true, features = [] }
7880

kube-client/src/api/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,10 @@ impl<K> Debug for Api<K> {
252252
/// Sanity test on scope restrictions
253253
#[cfg(test)]
254254
mod test {
255-
use crate::{Api, Client};
255+
use crate::{client::Body, Api, Client};
256256
use k8s_openapi::api::core::v1 as corev1;
257257

258258
use http::{Request, Response};
259-
use hyper::Body;
260259
use tower_test::mock;
261260

262261
#[tokio::test]

kube-client/src/client/auth/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ pub enum Error {
102102
/// cluster spec missing while `provideClusterInfo` is true
103103
#[error("Cluster spec must be populated when `provideClusterInfo` is true")]
104104
ExecMissingClusterInfo,
105+
106+
/// No valid native root CA certificates found
107+
#[error("No valid native root CA certificates found")]
108+
NoValidNativeRootCA(#[source] std::io::Error),
105109
}
106110

107111
#[derive(Debug, Clone)]

kube-client/src/client/auth/oauth.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
use http_body_util::BodyExt;
2+
use hyper_util::rt::TokioExecutor;
13
use tame_oauth::{
24
gcp::{TokenOrRequest, TokenProvider, TokenProviderWrapper},
35
Token,
46
};
57
use thiserror::Error;
68

9+
use crate::client::Body;
10+
711
#[derive(Error, Debug)]
812
/// Possible errors when requesting token with OAuth
913
pub enum Error {
@@ -33,7 +37,7 @@ pub enum Error {
3337

3438
/// Failed to request token
3539
#[error("failed to request token: {0}")]
36-
RequestToken(#[source] hyper::Error),
40+
RequestToken(#[source] hyper_util::client::legacy::Error),
3741

3842
/// Failed to retrieve new credential
3943
#[error("failed to retrieve new credential {0:?}")]
@@ -51,6 +55,10 @@ pub enum Error {
5155
#[error("failed to build request: {0}")]
5256
BuildRequest(#[source] http::Error),
5357

58+
/// No valid native root CA certificates found
59+
#[error("No valid native root CA certificates found")]
60+
NoValidNativeRootCA(#[source] std::io::Error),
61+
5462
/// OAuth failed with unknown reason
5563
#[error("unknown OAuth error: {0}")]
5664
Unknown(String),
@@ -113,22 +121,23 @@ impl Gcp {
113121
#[cfg(feature = "rustls-tls")]
114122
let https = hyper_rustls::HttpsConnectorBuilder::new()
115123
.with_native_roots()
124+
.map_err(Error::NoValidNativeRootCA)?
116125
.https_only()
117126
.enable_http1()
118127
.build();
119128
#[cfg(all(not(feature = "rustls-tls"), feature = "openssl-tls"))]
120129
let https =
121130
hyper_openssl::HttpsConnector::new().map_err(Error::CreateOpensslHttpsConnector)?;
122131

123-
let client = hyper::Client::builder().build::<_, hyper::Body>(https);
132+
let client = hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build(https);
124133

125134
let res = client
126-
.request(request.map(hyper::Body::from))
135+
.request(request.map(Body::from))
127136
.await
128137
.map_err(Error::RequestToken)?;
129138
// Convert response body to `Vec<u8>` for parsing.
130139
let (parts, body) = res.into_parts();
131-
let bytes = hyper::body::to_bytes(body).await.map_err(Error::ConcatBuffers)?;
140+
let bytes = body.collect().await.map_err(Error::ConcatBuffers)?.to_bytes();
132141
let response = http::Response::from_parts(parts, bytes.to_vec());
133142
match self.provider.parse_token_response(scope_hash, response) {
134143
Ok(token) => Ok(token),

0 commit comments

Comments
 (0)