containerd / ttrpc-rust

Rust implementation of ttrpc (GRPC for low-memory environments)
Apache License 2.0
195 stars 45 forks source link

Can't properly connect to containerd? #108

Closed abalmos closed 2 years ago

abalmos commented 2 years ago

Description of problem

All of my attempts to use ttrpc-rust to connect to the containerd deamon is failing. I'm sure I am doing something wrong, but I can't seem to send a request such that the service is found. Would you have any immediate thoughts on that?

I've used the protobuf files from here: https://github.com/containerd/containerd/tree/main/api

mod protocols;

use protocols::sync::{tasks, tasks_ttrpc};
use nix::sys::socket::*;
use ttrpc::{context, Client};

fn main() {
    let path = "/run/containerd/containerd.sock.ttrpc";

    let fd = socket(
        AddressFamily::Unix,
        SockType::Stream,
        SockFlag::SOCK_CLOEXEC,
        None,
    )
    .unwrap();

    let sockaddr = path.to_owned(); // + &"\x00".to_string();
    let sockaddr = UnixAddr::new(sockaddr.as_bytes()).unwrap();
    let sockaddr = SockAddr::Unix(sockaddr);
    connect(fd, &sockaddr).unwrap();

    let c = Client::new(fd);

    let t = tasks_ttrpc::TasksClient::new(c);
    let req = tasks::ListTasksRequest::new();

    let mut ctx = context::with_timeout(0);
    ctx.add("containerd-namespace-ttrpc".to_string(), "moby".to_string());

    println!("RES: {:?}", t.list(ctx, &req));
}

Expected result

A print out of ListTaskResponse

Actual result

RES: Err(RpcStatus(code: NOT_FOUND message: "service containerd.services.tasks.v1.Tasks"))

Side question: containerd's Content protobuf's use a few stream responses. Those result in compile time errors when built with ttrpc-rust. Are streaming responses not supported by ttrpc-rust?

Thank you for the help and the all the work to bring this functionality to rust!

mxpv commented 2 years ago

containerd doesn't expose all APIs via TTRPC, just events endpoint, which is used by shims. You'd need to use GRPC for everything else.

abalmos commented 2 years ago

@mxpv Well, that explains it :smile: The error was pretty telling after all.

In the meantime I had been working on a tonic based solution and have had success. I will continue down that path then.

Thanks for the help!

mxpv commented 2 years ago

You might be interested in this: https://github.com/containerd/project/issues/82

abalmos commented 2 years ago

@mxpv I would be. I started working on a containerd rust library today. It seems the repo is not available?

mxpv commented 2 years ago

It'll be open sourced once the voting is done (if approved (: )

abalmos commented 2 years ago

I see. Is the library complete? I'll keep working on my solution in the meantime.

mxpv commented 2 years ago

@abalmos you can now give it a try, repo is here: https://github.com/containerd/rust-extensions