Update docs

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko 2021-12-10 15:06:55 -08:00
parent 8a3233f248
commit e5fd8c76ae
5 changed files with 46 additions and 1 deletions

View File

@ -1,5 +1,8 @@
//! A GRPC client to query containerd's API.
pub use tonic;
/// Generated `containerd.types` types.
pub mod types {
tonic::include_proto!("containerd.types");
@ -8,12 +11,14 @@ pub mod types {
}
}
/// Generated `google.rpc` types, containerd services typically use some of these types.
pub mod google {
pub mod rpc {
tonic::include_proto!("google.rpc");
}
}
/// Generated `containerd.services.*` services.
pub mod services {
pub mod v1 {
tonic::include_proto!("containerd.services.containers.v1");
@ -34,12 +39,14 @@ pub mod services {
}
}
/// Generated event types.
pub mod events {
tonic::include_proto!("containerd.events");
}
/// Connect creates a unix channel to containerd GRPC socket.
/// This helper inteded to be used in conjuction with Tokio runtime.
///
/// This helper inteded to be used in conjuction with [Tokio](https://tokio.rs) runtime.
#[cfg(feature = "connect")]
pub async fn connect(
path: impl AsRef<std::path::Path>,

View File

@ -1,3 +1,5 @@
//! Helper library to implement custom shim loggers for containerd.
use std::env;
use std::fmt;
use std::fs;

View File

@ -1,3 +1,28 @@
//! `containerd-shim-client` contains TTRPC bindings and client/server code to interact with
//! containerd's runtime v2 shims.
//!
//! This crate relies on [ttrpc-rust](https://github.com/containerd/ttrpc-rust) crate to generate
//! protobuf definitions and re-exports the TTRPC client for convenience.
//!
//! Here is a quick example:
//! ```rust
//! use containerd_shim_client as client;
//!
//! use client::api;
//! use client::ttrpc::context::Context;
//!
//! // Create TTRPC client
//! let client = client::Client::connect("unix:///socket.sock")?;
//!
//! // Get task client
//! let task_client = client::TaskClient::new(client);
//! let context = Context::default();
//!
//! // Send request and receive response
//! let request = api::ConnectRequest::default();
//! let response = task_client.connect(Context::default(), &request);
//! ```
// Supress warning: redundant field names in struct initialization
#![allow(clippy::redundant_field_names)]
@ -9,11 +34,14 @@ pub mod events;
#[rustfmt::skip]
pub mod shim;
/// Includes event names shims can publish to containerd.
pub mod topics;
/// TTRPC client reexport for easier access.
pub use ttrpc::Client;
pub use shim::shim as api;
pub use shim::shim_ttrpc::{Task, TaskClient};
/// Shim events.
pub use shim::events_ttrpc::{Events, EventsClient};

View File

@ -1,3 +1,5 @@
//! A library to implement custom runtime v2 shims for containerd.
use std::collections::hash_map::DefaultHasher;
use std::env;
use std::error;
@ -28,6 +30,7 @@ mod reap;
pub use publisher::RemotePublisher;
/// Generated request/response structures.
pub mod api {
pub use super::protos::shim::empty::Empty;
pub use super::protos::shim::shim::*;
@ -115,6 +118,7 @@ pub trait Shim: Task {
}
}
/// Shim entry point that must be invoked from `main`.
pub fn run<T>(id: &str)
where
T: Shim + Send + Sync + 'static,
@ -255,6 +259,7 @@ pub const SOCKET_ROOT: &str = "/run/containerd";
#[cfg(target_os = "macos")]
pub const SOCKET_ROOT: &str = "/var/run/containerd";
/// Make socket path from namespace and id.
pub fn socket_address(socket_path: &str, namespace: &str, id: &str) -> String {
let path = PathBuf::from(socket_path)
.join(namespace)

View File

@ -1,3 +1,5 @@
//! Implements a client to publish events from the shim back to containerd.
use std::os::unix::io::RawFd;
use std::time::{SystemTime, UNIX_EPOCH};
@ -110,6 +112,7 @@ impl Events for RemotePublisher {
}
}
/// Errors returned from client if something went wrong.
#[derive(Debug, Error)]
pub enum Error {
#[error("Publisher TTRPC error: {0}")]