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

@@ -17,6 +17,7 @@
package plugins
import (
"encoding/json"
"fmt"
"os"
"sort"
@@ -39,6 +40,7 @@ var Command = cli.Command{
Usage: "Provides information about containerd plugins",
Subcommands: []cli.Command{
listCommand,
inspectRuntimeCommand,
},
}
@@ -162,3 +164,32 @@ func prettyPlatforms(pspb []*types.Platform) string {
sort.Stable(sort.StringSlice(ps))
return strings.Join(ps, ",")
}
var inspectRuntimeCommand = cli.Command{
Name: "inspect-runtime",
Usage: "Display runtime info",
ArgsUsage: "[flags]",
Flags: commands.RuntimeFlags,
Action: func(context *cli.Context) error {
rt := context.String("runtime")
rtOptions, err := commands.RuntimeOptions(context)
if err != nil {
return err
}
client, ctx, cancel, err := commands.NewClient(context)
if err != nil {
return err
}
defer cancel()
rtInfo, err := client.RuntimeInfo(ctx, rt, rtOptions)
if err != nil {
return err
}
j, err := json.MarshalIndent(rtInfo, "", " ")
if err != nil {
return err
}
_, err = fmt.Fprintln(context.App.Writer, string(j))
return err
},
}