1 unstable release
1.0.0 |
|
---|---|
0.1.1 | Oct 9, 2024 |
#3 in #cri
337 downloads per month
25KB
cri-api
本项目基于k8s-cri,当前沿用其文档。 未来,本项目仅支持v1规范,并完善examples,指导用户如何开发使用。
改代码从
研制计划
lib.rs
:
Examples
Connecting over TCP:
use cri_api::v1::runtime_service_client::RuntimeServiceClient;
use cri_api::v1::ListContainersRequest;
use tokio::main;
#[tokio::main]
async fn main() {
let mut client = RuntimeServiceClient::connect("http://[::1]:50051")
.await
.expect("Could not create client.");
let request = tonic::Request::new(ListContainersRequest { filter: None });
let response = client
.list_containers(request)
.await
.expect("Request failed.");
println!("{:?}", response);
}
Connecting to a Unix domain socket:
use std::convert::TryFrom;
use tokio::main;
use cri_api::v1::runtime_service_client::RuntimeServiceClient;
use tokio::net::UnixStream;
use tonic::transport::{Channel, Endpoint, Uri};
use tower::service_fn;
#[tokio::main]
async fn main() {
let path = "/run/containerd/containerd.sock";
let channel = Endpoint::try_from("http://[::]")
.unwrap()
.connect_with_connector(service_fn(move |_: Uri| UnixStream::connect(path)))
.await
.expect("Could not create client.");
let mut client = RuntimeServiceClient::new(channel);
}
API version v1, original Protocol Buffers file.
Dependencies
~4–12MB
~128K SLoC