Skip to content

Commit

Permalink
chore(bors): merge pull request openebs#685
Browse files Browse the repository at this point in the history
685: refactor(kube-forward): remove local work-around r=tiagolobocastro a=tiagolobocastro

Upstream fix has been merged, so we can remove the WA to distinguish between the type of received error.

Co-authored-by: Tiago Castro <[email protected]>
  • Loading branch information
mayastor-bors and tiagolobocastro committed Nov 2, 2023
2 parents 36afc8a + 3087cd3 commit d7ea534
Showing 1 changed file with 1 addition and 30 deletions.
31 changes: 1 addition & 30 deletions k8s/forward/src/http_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,7 @@ impl hyper::service::Service<hyper::Request<body::Body>> for HttpProxy {

fn call(&mut self, request: hyper::Request<body::Body>) -> Self::Future {
let client = self.client.clone();
Box::pin(async move {
let (parts, body) = request.into_parts();

let body_bytes = body::to_bytes(body).await;
let bytes = body_bytes.map_err(kube::Error::HyperError)?.to_vec();

let request = hyper::Request::from_parts(parts, bytes);
match client.request_text(request).await {
Ok(r) => Ok(Response::new(body::Body::from(r))),
Err(error) => match error {
// without https://github.com/kube-rs/kube-rs/pull/972 all errors get translated
// to a kube-api error type `ErrorResponse` so it's not possible to distinguish
// where the error came from, i.e. kubeapi proxy or the target service.
kube::Error::Api(response) => {
let message =
match serde_json::from_str::<serde_json::Value>(&response.message) {
// undo the debug print which created response.message
Ok(message) => message.as_str().unwrap_or("").to_string(),
Err(_) => response.message,
};

Response::builder()
.status(response.code)
.body(body::Body::from(message))
.map_err(kube::Error::HttpError)
}
_ => Err(error),
},
}
})
Box::pin(async move { client.send(request).await })
}
}

Expand Down

0 comments on commit d7ea534

Please sign in to comment.