1 unstable release

1.0.0 Sep 24, 2024
0.1.1 Oct 9, 2024

#3 in #cri

Download history 127/week @ 2024-09-20 40/week @ 2024-09-27 130/week @ 2024-10-04 40/week @ 2024-10-11

337 downloads per month

Apache-2.0

25KB

cri-api

本项目基于k8s-cri,当前沿用其文档。 未来,本项目仅支持v1规范,并完善examples,指导用户如何开发使用。

改代码从

研制计划

  • 0.1.0:支持v1和v1alpha2规范,推送到rust仓库。
  • 0.1.1:删除对v1alpha2规范支持。
  • 0.2.0:添加示例代码。

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