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

chore(deps): address hyper deprecations in policy controller #13493

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
7 changes: 4 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
dependencies = [
"libc",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]

[[package]]
Expand Down Expand Up @@ -731,9 +731,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"

[[package]]
name = "hyper"
version = "0.14.28"
version = "0.14.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80"
checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7"
dependencies = [
"bytes",
"futures-channel",
Expand Down Expand Up @@ -1415,6 +1415,7 @@ dependencies = [
"clap",
"drain",
"futures",
"http-body",
"hyper",
"ipnet",
"k8s-openapi",
Expand Down
2 changes: 1 addition & 1 deletion policy-controller/grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async-trait = "0.1"
http = "0.2"
drain = "0.1"
futures = { version = "0.3", default-features = false }
hyper = { version = "0.14", features = ["http2", "server", "tcp"] }
hyper = { version = "0.14", features = ["backports", "deprecated", "http2", "server", "tcp"] }
linkerd-policy-controller-core = { path = "../core" }
maplit = "1"
prost-types = "0.12.6"
Expand Down
3 changes: 2 additions & 1 deletion policy-controller/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ async-trait = "0.1"
drain = "0.1"
futures = { version = "0.3", default-features = false }
k8s-openapi = { workspace = true }
hyper = { version = "0.14", features = ["http1", "http2", "runtime", "server"] }
http-body = "0.4"
hyper = { version = "0.14", features = ["backports", "deprecated", "http1", "http2", "runtime", "server"] }
ipnet = { version = "2", default-features = false }
openssl = { version = "0.10.68", optional = true }
parking_lot = "0.12"
Expand Down
3 changes: 2 additions & 1 deletion policy-controller/runtime/src/admission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ impl hyper::service::Service<Request<Body>> for Admission {

let admission = self.clone();
Box::pin(async move {
let bytes = hyper::body::aggregate(req.into_body()).await?;
use http_body::Body as _;
let bytes = req.into_body().collect().await?.aggregate();
let review: Review = match serde_json::from_reader(bytes.reader()) {
Ok(review) => review,
Err(error) => {
Expand Down
2 changes: 1 addition & 1 deletion policy-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false

[dependencies]
anyhow = "1"
hyper = { version = "0.14", features = ["client", "http2"] }
hyper = { version = "0.14", features = ["backports", "deprecated", "client", "http2", "runtime"] }
futures = { version = "0.3", default-features = false }
ipnet = "2"
k8s-gateway-api = "0.16"
Expand Down
17 changes: 11 additions & 6 deletions policy-test/src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
//! forwarding to connect to a running instance.

use anyhow::Result;
pub use linkerd2_proxy_api::*;
use linkerd2_proxy_api::{
inbound::inbound_server_policies_client::InboundServerPoliciesClient,
outbound::outbound_policies_client::OutboundPoliciesClient,
};
use linkerd_policy_controller_grpc::workload;
use linkerd_policy_controller_k8s_api::{self as k8s, ResourceExt};
use std::{future::Future, pin::Pin};
use tokio::io;

pub use linkerd2_proxy_api::*;

#[macro_export]
macro_rules! assert_is_default_all_unauthenticated {
($config:expr) => {
Expand Down Expand Up @@ -105,7 +107,7 @@ pub struct OutboundPolicyClient {

#[derive(Debug)]
struct GrpcHttp {
tx: hyper::client::conn::SendRequest<tonic::body::BoxBody>,
tx: hyper::client::conn::http2::SendRequest<tonic::body::BoxBody>,
}

async fn get_policy_controller_pod(client: &kube::Client) -> Result<String> {
Expand Down Expand Up @@ -338,8 +340,7 @@ impl GrpcHttp {
where
I: io::AsyncRead + io::AsyncWrite + Unpin + Send + 'static,
{
let (tx, conn) = hyper::client::conn::Builder::new()
.http2_only(true)
let (tx, conn) = hyper::client::conn::http2::Builder::new(crate::rt::TokioExecutor)
.handshake(io)
.await?;
tokio::spawn(conn);
Expand All @@ -350,7 +351,7 @@ impl GrpcHttp {
impl hyper::service::Service<hyper::Request<tonic::body::BoxBody>> for GrpcHttp {
type Response = hyper::Response<hyper::Body>;
type Error = hyper::Error;
type Future = hyper::client::conn::ResponseFuture;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;

fn poll_ready(
&mut self,
Expand All @@ -360,6 +361,8 @@ impl hyper::service::Service<hyper::Request<tonic::body::BoxBody>> for GrpcHttp
}

fn call(&mut self, req: hyper::Request<tonic::body::BoxBody>) -> Self::Future {
use futures::FutureExt;

let (mut parts, body) = req.into_parts();

let mut uri = parts.uri.into_parts();
Expand All @@ -371,7 +374,9 @@ impl hyper::service::Service<hyper::Request<tonic::body::BoxBody>> for GrpcHttp
);
parts.uri = hyper::Uri::from_parts(uri).unwrap();

self.tx.call(hyper::Request::from_parts(parts, body))
self.tx
.send_request(hyper::Request::from_parts(parts, body))
.boxed()
}
}

Expand Down
2 changes: 2 additions & 0 deletions policy-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub mod grpc;
pub mod outbound_api;
pub mod web;

mod rt;

use kube::runtime::wait::Condition;
use linkerd_policy_controller_k8s_api::{
self as k8s,
Expand Down
18 changes: 18 additions & 0 deletions policy-test/src/rt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! HTTP runtime components for Linkerd.

use hyper::rt::Executor;
use std::future::Future;

#[derive(Clone, Debug, Default)]
pub struct TokioExecutor;

impl<F> Executor<F> for TokioExecutor
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
#[inline]
fn execute(&self, f: F) {
tokio::spawn(f);
}
}
Loading