Skip to content

Help using gRPC containerd-client, "namespace is required: failed precondition" #156

Description

@mfernd

Hello, I'm trying to use the grpc bindings from containerd-client.

And when I try to list containers in the namespace moby (I also tried with other namespaces I've created), I get an error about the namespace missing.

Here is a sample of my code:

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt().with_max_level(Level::INFO).init();

    let channel = containerd_client::connect("/run/containerd/containerd.sock").await?;

    let mut tasks_client = ContainersClient::new(channel.clone());

    let req = ListContainersRequest::default();
    let req = with_namespace!(req, "moby");
    info!("{:?}", req);

    let container_list = tasks_client.list(req.into_inner()).await?;
    info!("{:?}", container_list.into_inner());

    Ok(())
}

Here is the tonic Request sended to containerd:

Request { metadata: MetadataMap { headers: {"containerd-namespace": "moby"} }, message: ListContainersRequest { filters: [] }, extensions: Extensions }

I have this error:

Error: status: FailedPrecondition, message: "namespace is required: failed precondition", details: [], metadata: MetadataMap { headers: {"content-type": "application/grpc"} }

Versions

Here is my version of containerd (at least I can get this information from containerd):
VersionResponse { version: "1.6.21", revision: "3dce8eb055cbb6872793272b4f20ed16117344f8" }

And here is my dependencies from Cargo.toml
[dependencies]
anyhow = "1.0.72"
containerd-client = "0.3.0"
prost = "0.11.9"
prost-types = "0.11.9"
tokio = { version = "1.29.1", features = ["full"] }
tonic = "0.9.2"
tracing = "0.1.37"
tracing-subscriber = "0.3.17"

[build-dependencies]
tonic-build = "0.9.2"

Maybe I did something wrong somewhere, but I can't see where.
Hoping you could enlighten me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions