mirror of
https://github.com/containerd/containerd.git
synced 2026-08-09 17:39:22 +00:00
Merge pull request #12017 from caoruidong/sandbox_info_com
ctr:add sandbox info command to print sandbox info
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/containerd/containerd/v2/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/v2/defaults"
|
||||
"github.com/containerd/containerd/v2/pkg/oci"
|
||||
"github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@@ -39,6 +40,7 @@ var Command = &cli.Command{
|
||||
runCommand,
|
||||
listCommand,
|
||||
removeCommand,
|
||||
infoCommand,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -191,3 +193,30 @@ var removeCommand = &cli.Command{
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var infoCommand = &cli.Command{
|
||||
Name: "info",
|
||||
Aliases: []string{"i"},
|
||||
Usage: "Get info about a sandbox",
|
||||
ArgsUsage: "<sandbox id>",
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
id := cliContext.Args().First()
|
||||
if id == "" {
|
||||
return fmt.Errorf("sandbox id must be provided: %w", errdefs.ErrInvalidArgument)
|
||||
}
|
||||
sandbox, err := client.LoadSandbox(ctx, id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load sandbox %s", id)
|
||||
}
|
||||
|
||||
info := sandbox.Metadata()
|
||||
commands.PrintAsJSON(info)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user