api/services/instrospection: add PluginInfo

The new `PlunginInfo()` call can be used for instrospecting the details
of the runtime plugin.

```console
$ ctr plugins inspect-runtime --runtime=io.containerd.runc.v2 --runc-binary=runc
{
    "Name": "io.containerd.runc.v2",
    "Version": {
        "Version": "v2.0.0-beta.0-XX-gXXXXXXXXX.m",
        "Revision": "v2.0.0-beta.0-XX-gXXXXXXXXX.m"
    },
    "Options": {
        "binary_name": "runc"
    },
    "Features": {
        "ociVersionMin": "1.0.0",
        "ociVersionMax": "1.1.0-rc.2",
        ...,
    },
    "Annotations": null
}
```

The shim binary has to support `-info` flag, see `runtime/v2/README.md`

Replaces PR 8509 (`api/services/task: add RuntimeInfo()`)

Co-authored-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda
2023-05-11 18:17:13 +09:00
parent 9dbb7615b6
commit 22d586e515
24 changed files with 1423 additions and 204 deletions

View File

@@ -24,11 +24,13 @@ import (
"io"
"os"
"os/exec"
"runtime"
"testing"
"time"
"github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/identity"
"github.com/opencontainers/runtime-spec/specs-go/features"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel"
@@ -546,3 +548,46 @@ func TestDefaultRuntimeWithNamespaceLabels(t *testing.T) {
t.Error("failed to set default runtime from namespace labels")
}
}
func TestRuntimeInfo(t *testing.T) {
t.Parallel()
if runtime.GOOS == "windows" {
t.Skip("io.containerd.runhcs.v1 does not implement `containerd-shim-runhcs-v1.exe -info` yet")
}
client, err := newClient(t, address)
if err != nil {
t.Fatal(err)
}
defer client.Close()
ctx, cancel := testContext(t)
defer cancel()
rti, err := client.RuntimeInfo(ctx, "", nil)
if err != nil {
t.Fatal(err)
}
if rti.Name == "" {
t.Fatal("got empty RuntimeInfo.Name")
}
feat, ok := rti.Features.(*features.Features)
if !ok {
t.Fatalf("expected RuntimeInfo.Features to be *features.Features, got %T", rti.Features)
}
var rroRecognized bool
for _, f := range feat.MountOptions {
// "rro" is recognized since runc v1.1.
// The functionality needs kernel >= 5.12, but `runc features` consistently include "rro" in feat.MountOptions.
if f == "rro" {
rroRecognized = true
}
}
if !rroRecognized {
t.Fatalf("expected feat.MountOptions to contain \"rro\", only got %v", feat.MountOptions)
}
}