fullstorydev / grpcurl

Like cURL, but for gRPC: Command-line tool for interacting with gRPC servers
MIT License
10.96k stars 508 forks source link

how to provide namespace wtih grpcurl #397

Open coolninja1504 opened 1 year ago

coolninja1504 commented 1 year ago

Hi All, I am using grpcurl to get list of images from containerd as follows:

grpcurl -plaintext -proto images.proto -unix /run/containerd/containerd.sock containerd.services.images.v1.Images/List

but getting following error: ERROR: Code: FailedPrecondition Message: namespace is required: failed precondition

I tried giving the namespace as follows , but then getting another error: ./grpcurl -plaintext -d '{"namespace":"k8s.io"}' -proto images.proto -unix /run/containerd/containerd.sock containerd.services.images.v1.Images/List Error invoking method "containerd.services.images.v1.Images/List": error getting request data: message type containerd.services.images.v1.ListImagesRequest has no known field named namespace

How can I give the namespace with grpcurl ?

Thanks

jhump commented 1 year ago

This is really a question for the containerd project, about how to use their API.

FWIW, you can use grpcurl describe to look at the definition for the RPC request (or look at API docs). Those show that there is no field named namespace; only a field named filters, which is an array of strings.

I happened to do some searching and found a hint here. In their example, showing a REST mapping for the gRPC API, they are setting a header named containerd-namespace. So I'm going to guess that you need an argument like -H "containerd-namespace: k8s.io". But if that doesn't work, this is not the place for more questions. I'd recommend asking in the containerd Slack: https://slack.containerd.io/

haytok commented 2 months ago

When running below command, I can get image list from containerd.sock.

> sudo ~/go/bin/grpcurl -plaintext -H "containerd-namespace: moby"  -proto api/services/images/v1/images.proto -proto api/types/descriptor.proto -unix /run/docker/containerd/containerd.sock containerd.services.images.v1.Images/List
{
  "images": [
    {
      "name": "docker.io/library/alpine:latest",
      "target": {
        "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
        "digest": "sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d",
        "size": "1853"
      },
      "createdAt": "2024-09-26T10:44:30.407562469Z",
      "updatedAt": "2024-09-26T10:44:30.407562469Z"
    }
  ]
}

Note that I pulled images in advance by running below command.

sudo ctr --address /run/docker/containerd/containerd.sock --namespace moby images pull docker.io/library/alpine:latest