Skip to content

Commit

Permalink
ctr: Add sandbox flag to ctr run
Browse files Browse the repository at this point in the history
Add a flag to be able to run a container in a given sandbox.

Signed-off-by: Danny Canter <danny@dcantah.dev>
  • Loading branch information
dcantah authored and k8s-infra-cherrypick-robot committed Dec 1, 2023
1 parent 9c65471 commit 5fc0e4e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/ctr/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ var (
Usage: "Runtime name or absolute path to runtime binary",
Value: defaults.DefaultRuntime,
},
cli.StringFlag{
Name: "sandbox",
Usage: "Create the container in the given sandbox",
},
cli.StringFlag{
Name: "runtime-config-path",
Usage: "Optional runtime config path",
Expand Down
1 change: 1 addition & 0 deletions cmd/ctr/commands/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ var Command = cli.Command{
return err
}
defer cancel()

container, err := NewContainer(ctx, client, context)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions cmd/ctr/commands/run/run_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
spec containerd.NewContainerOpts
)

if sandbox := context.String("sandbox"); sandbox != "" {
cOpts = append(cOpts, containerd.WithSandbox(sandbox))
}

if config {
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("label"))))
opts = append(opts, oci.WithSpecFromFile(context.String("config")))
Expand Down
4 changes: 4 additions & 0 deletions cmd/ctr/commands/run/run_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
config = context.IsSet("config")
)

if sandbox := context.String("sandbox"); sandbox != "" {
cOpts = append(cOpts, containerd.WithSandbox(sandbox))
}

if config {
id = context.Args().First()
opts = append(opts, oci.WithSpecFromFile(context.String("config")))
Expand Down

0 comments on commit 5fc0e4e

Please sign in to comment.