Skip to content
This repository has been archived by the owner on Oct 31, 2022. It is now read-only.

Commit

Permalink
simplify trait bounds on client methods
Browse files Browse the repository at this point in the history
These bounds work, but will result in some broken code once we switch to
a proper sockets-based transport.

I've opened an issue upstream, since it would be nice to keep the more
generic code, while somehow avoiding boilerplate.

hyperium/tonic#110
  • Loading branch information
daniel5151 committed Nov 4, 2019
1 parent 5a05795 commit 950725a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 deletions.
54 changes: 13 additions & 41 deletions shellrt/shellrt-containerd/src/handler/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use containerd_grpc::containerd::{
use shellrt_api::v0::{request, response};

use crate::error::*;
use crate::util::TonicRequestExt;
use crate::util::*;

pub struct PullHandler {
grpc_uri: String,
Expand Down Expand Up @@ -151,17 +151,10 @@ impl PullHandler {
}

/// Check if a blob already exists in containerd's content store
async fn already_in_containerd<C>(
async fn already_in_containerd(
digest: &Digest,
mut content_client: ContentClient<C>,
) -> Result<bool>
where
C: tonic::client::GrpcService<tonic::body::BoxBody>,
C::ResponseBody: tonic::codegen::Body + tonic::codegen::HttpBody + Send + 'static,
C::Error: Into<tonic::codegen::StdError>,
<C::ResponseBody as tonic::codegen::HttpBody>::Error: Into<tonic::codegen::StdError> + Send,
<C::ResponseBody as tonic::codegen::HttpBody>::Data: Into<bytes::Bytes> + Send,
{
mut content_client: ContentClient<tonic::transport::Channel>,
) -> Result<bool> {
let req = tonic::Request::new_namespaced(InfoRequest {
digest: digest.to_string(),
});
Expand Down Expand Up @@ -191,17 +184,10 @@ where

/// Check if a blob has been partially downloaded to containerd, returning the
/// downloaded offset if applicable.
async fn partially_in_containerd<C>(
async fn partially_in_containerd(
digest: &Digest,
mut content_client: ContentClient<C>,
) -> Result<Option<u64>>
where
C: tonic::client::GrpcService<tonic::body::BoxBody>,
C::ResponseBody: tonic::codegen::Body + tonic::codegen::HttpBody + Send + 'static,
C::Error: Into<tonic::codegen::StdError>,
<C::ResponseBody as tonic::codegen::HttpBody>::Error: Into<tonic::codegen::StdError> + Send,
<C::ResponseBody as tonic::codegen::HttpBody>::Data: Into<bytes::Bytes> + Send,
{
mut content_client: ContentClient<tonic::transport::Channel>,
) -> Result<Option<u64>> {
let req = tonic::Request::new_namespaced(StatusRequest {
r#ref: digest.to_string(),
});
Expand Down Expand Up @@ -229,19 +215,12 @@ where
Ok(offset)
}

async fn stream_to_containerd<C>(
async fn stream_to_containerd(
blob: Blob,
offset: u64,
labels: HashMap<String, String>,
mut content_client: ContentClient<C>,
) -> Result<()>
where
C: tonic::client::GrpcService<tonic::body::BoxBody>,
C::ResponseBody: tonic::codegen::Body + tonic::codegen::HttpBody + Send + 'static,
C::Error: Into<tonic::codegen::StdError>,
<C::ResponseBody as tonic::codegen::HttpBody>::Error: Into<tonic::codegen::StdError> + Send,
<C::ResponseBody as tonic::codegen::HttpBody>::Data: Into<bytes::Bytes> + Send,
{
mut content_client: ContentClient<tonic::transport::Channel>,
) -> Result<()> {
// why two digests? combinators.
let digest = blob.descriptor().digest.clone();
let digest_2 = digest.clone();
Expand Down Expand Up @@ -342,18 +321,11 @@ where
}
}

async fn register_image_with_containerd<C>(
async fn register_image_with_containerd(
image: &Reference,
manifest_descriptor: &Descriptor,
mut images_client: ImagesClient<C>,
) -> Result<()>
where
C: tonic::client::GrpcService<tonic::body::BoxBody>,
C::ResponseBody: tonic::codegen::Body + tonic::codegen::HttpBody + Send + 'static,
C::Error: Into<tonic::codegen::StdError>,
<C::ResponseBody as tonic::codegen::HttpBody>::Error: Into<tonic::codegen::StdError> + Send,
<C::ResponseBody as tonic::codegen::HttpBody>::Data: Into<bytes::Bytes> + Send,
{
mut images_client: ImagesClient<tonic::transport::Channel>,
) -> Result<()> {
let now = std::time::SystemTime::now();
let image = || {
let manifest_descriptor = manifest_descriptor.clone();
Expand Down
2 changes: 1 addition & 1 deletion shellrt/shellrt-containerd/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<T> TonicRequestExt<T> for Request<T> {
/// Create a new gRPC request with metadata
/// {"containerd-namespace":"<shellrt-containerd-namespace>"}
fn new_namespaced(msg: T) -> Request<T> {
let mut req = tonic::Request::new(msg);
let mut req = Request::new(msg);
req.metadata_mut()
.insert("containerd-namespace", NAMESPACE.clone());
req
Expand Down

0 comments on commit 950725a

Please sign in to comment.