Skip to content

Commit 5fc0e4e

Browse files
dcantahk8s-infra-cherrypick-robot
authored andcommitted
ctr: Add sandbox flag to ctr run
Add a flag to be able to run a container in a given sandbox. Signed-off-by: Danny Canter <[email protected]>
1 parent 9c65471 commit 5fc0e4e

4 files changed

Lines changed: 13 additions & 0 deletions

File tree

cmd/ctr/commands/commands.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ var (
143143
Usage: "Runtime name or absolute path to runtime binary",
144144
Value: defaults.DefaultRuntime,
145145
},
146+
cli.StringFlag{
147+
Name: "sandbox",
148+
Usage: "Create the container in the given sandbox",
149+
},
146150
cli.StringFlag{
147151
Name: "runtime-config-path",
148152
Usage: "Optional runtime config path",

cmd/ctr/commands/run/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ var Command = cli.Command{
164164
return err
165165
}
166166
defer cancel()
167+
167168
container, err := NewContainer(ctx, client, context)
168169
if err != nil {
169170
return err

cmd/ctr/commands/run/run_unix.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
102102
spec containerd.NewContainerOpts
103103
)
104104

105+
if sandbox := context.String("sandbox"); sandbox != "" {
106+
cOpts = append(cOpts, containerd.WithSandbox(sandbox))
107+
}
108+
105109
if config {
106110
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("label"))))
107111
opts = append(opts, oci.WithSpecFromFile(context.String("config")))

cmd/ctr/commands/run/run_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
5151
config = context.IsSet("config")
5252
)
5353

54+
if sandbox := context.String("sandbox"); sandbox != "" {
55+
cOpts = append(cOpts, containerd.WithSandbox(sandbox))
56+
}
57+
5458
if config {
5559
id = context.Args().First()
5660
opts = append(opts, oci.WithSpecFromFile(context.String("config")))

0 commit comments

Comments
 (0)