ctr sandbox: handle sandbox config
"ctr s r" help suggests <pod-config.json> is taken as the first parameter and the sandbox ID becomes next. However, only the latter is read and used. Add code that reads <pod-config.json> and passes it to Sanbox. Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
This commit is contained in:
parent
405fba75dd
commit
900019b301
@ -17,6 +17,7 @@
|
|||||||
package sandboxes
|
package sandboxes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
@ -54,11 +55,24 @@ var runCommand = cli.Command{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
|
if context.NArg() != 2 {
|
||||||
|
return cli.ShowSubcommandHelp(context)
|
||||||
|
}
|
||||||
var (
|
var (
|
||||||
id = context.Args().Get(0)
|
id = context.Args().Get(1)
|
||||||
runtime = context.String("runtime")
|
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)
|
client, ctx, cancel, err := commands.NewClient(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -67,7 +81,7 @@ var runCommand = cli.Command{
|
|||||||
|
|
||||||
sandbox, err := client.NewSandbox(ctx, id,
|
sandbox, err := client.NewSandbox(ctx, id,
|
||||||
containerd.WithSandboxRuntime(runtime, nil),
|
containerd.WithSandboxRuntime(runtime, nil),
|
||||||
containerd.WithSandboxSpec(&oci.Spec{}),
|
containerd.WithSandboxSpec(&ociSpec),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create new sandbox: %w", err)
|
return fmt.Errorf("failed to create new sandbox: %w", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user