From 900019b301c687660e6e94a2e0a7fc1d0db47c08 Mon Sep 17 00:00:00 2001 From: Mikko Ylinen Date: Thu, 19 May 2022 15:26:11 +0300 Subject: [PATCH] ctr sandbox: handle sandbox config "ctr s r" help suggests is taken as the first parameter and the sandbox ID becomes next. However, only the latter is read and used. Add code that reads and passes it to Sanbox. Signed-off-by: Mikko Ylinen --- cmd/ctr/commands/sandboxes/sandboxes.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/ctr/commands/sandboxes/sandboxes.go b/cmd/ctr/commands/sandboxes/sandboxes.go index 7e639afb2a05..ff0db8d8c5a4 100644 --- a/cmd/ctr/commands/sandboxes/sandboxes.go +++ b/cmd/ctr/commands/sandboxes/sandboxes.go @@ -17,6 +17,7 @@ package sandboxes import ( + "encoding/json" "fmt" "os" "text/tabwriter" @@ -54,11 +55,24 @@ var runCommand = cli.Command{ }, }, Action: func(context *cli.Context) error { + if context.NArg() != 2 { + return cli.ShowSubcommandHelp(context) + } var ( - id = context.Args().Get(0) + id = context.Args().Get(1) runtime = context.String("runtime") ) + spec, err := os.ReadFile(context.Args().First()) + if err != nil { + return fmt.Errorf("Failed to read sandbox config: %w", err) + } + + ociSpec := oci.Spec{} + if err = json.Unmarshal(spec, &ociSpec); err != nil { + return fmt.Errorf("Failed to parse sandbox config: %w", err) + } + client, ctx, cancel, err := commands.NewClient(context) if err != nil { return err @@ -67,7 +81,7 @@ var runCommand = cli.Command{ sandbox, err := client.NewSandbox(ctx, id, containerd.WithSandboxRuntime(runtime, nil), - containerd.WithSandboxSpec(&oci.Spec{}), + containerd.WithSandboxSpec(&ociSpec), ) if err != nil { return fmt.Errorf("failed to create new sandbox: %w", err)