Skip to content

Commit d1e3ca2

Browse files
authored
Merge pull request #77 from containerd/create-args
Add extra args for Opts and Runc
2 parents 6db4918 + 16abe56 commit d1e3ca2

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

runc.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ type CreateOpts struct {
100100
NoNewKeyring bool
101101
ExtraFiles []*os.File
102102
Started chan<- int
103+
ExtraArgs []string
103104
}
104105

105106
func (o *CreateOpts) args() (out []string, err error) {
@@ -125,6 +126,9 @@ func (o *CreateOpts) args() (out []string, err error) {
125126
if o.ExtraFiles != nil {
126127
out = append(out, "--preserve-fds", strconv.Itoa(len(o.ExtraFiles)))
127128
}
129+
if len(o.ExtraArgs) > 0 {
130+
out = append(out, o.ExtraArgs...)
131+
}
128132
return out, nil
129133
}
130134

@@ -182,6 +186,7 @@ type ExecOpts struct {
182186
ConsoleSocket ConsoleSocket
183187
Detach bool
184188
Started chan<- int
189+
ExtraArgs []string
185190
}
186191

187192
func (o *ExecOpts) args() (out []string, err error) {
@@ -198,6 +203,9 @@ func (o *ExecOpts) args() (out []string, err error) {
198203
}
199204
out = append(out, "--pid-file", abs)
200205
}
206+
if len(o.ExtraArgs) > 0 {
207+
out = append(out, o.ExtraArgs...)
208+
}
201209
return out, nil
202210
}
203211

@@ -292,13 +300,17 @@ func (r *Runc) Run(context context.Context, id, bundle string, opts *CreateOpts)
292300

293301
// DeleteOpts holds the deletion options for calling `runc delete`
294302
type DeleteOpts struct {
295-
Force bool
303+
Force bool
304+
ExtraArgs []string
296305
}
297306

298307
func (o *DeleteOpts) args() (out []string) {
299308
if o.Force {
300309
out = append(out, "--force")
301310
}
311+
if len(o.ExtraArgs) > 0 {
312+
out = append(out, o.ExtraArgs...)
313+
}
302314
return out
303315
}
304316

@@ -313,13 +325,17 @@ func (r *Runc) Delete(context context.Context, id string, opts *DeleteOpts) erro
313325

314326
// KillOpts specifies options for killing a container and its processes
315327
type KillOpts struct {
316-
All bool
328+
All bool
329+
ExtraArgs []string
317330
}
318331

319332
func (o *KillOpts) args() (out []string) {
320333
if o.All {
321334
out = append(out, "--all")
322335
}
336+
if len(o.ExtraArgs) > 0 {
337+
out = append(out, o.ExtraArgs...)
338+
}
323339
return out
324340
}
325341

@@ -461,6 +477,7 @@ type CheckpointOpts struct {
461477
LazyPages bool
462478
// StatusFile is the file criu writes \0 to once lazy-pages is ready
463479
StatusFile *os.File
480+
ExtraArgs []string
464481
}
465482

466483
// CgroupMode defines the cgroup mode used for checkpointing
@@ -509,6 +526,9 @@ func (o *CheckpointOpts) args() (out []string) {
509526
if o.LazyPages {
510527
out = append(out, "--lazy-pages")
511528
}
529+
if len(o.ExtraArgs) > 0 {
530+
out = append(out, o.ExtraArgs...)
531+
}
512532
return out
513533
}
514534

@@ -557,6 +577,7 @@ type RestoreOpts struct {
557577
NoSubreaper bool
558578
NoPivot bool
559579
ConsoleSocket ConsoleSocket
580+
ExtraArgs []string
560581
}
561582

562583
func (o *RestoreOpts) args() ([]string, error) {
@@ -580,6 +601,9 @@ func (o *RestoreOpts) args() ([]string, error) {
580601
if o.NoSubreaper {
581602
out = append(out, "-no-subreaper")
582603
}
604+
if len(o.ExtraArgs) > 0 {
605+
out = append(out, o.ExtraArgs...)
606+
}
583607
return out, nil
584608
}
585609

@@ -695,6 +719,9 @@ func (r *Runc) args() (out []string) {
695719
// nil stands for "auto" (differs from explicit "false")
696720
out = append(out, "--rootless="+strconv.FormatBool(*r.Rootless))
697721
}
722+
if len(r.ExtraArgs) > 0 {
723+
out = append(out, r.ExtraArgs...)
724+
}
698725
return out
699726
}
700727

runc_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
)
3131

3232
func TestParseVersion(t *testing.T) {
33-
3433
testParseVersion := func(t *testing.T, input string, expected Version) {
3534
actual, err := parseVersion([]byte(input))
3635
if err != nil {
@@ -314,3 +313,26 @@ func dummySleepRunc() (_ string, err error) {
314313
}
315314
return fh.Name(), nil
316315
}
316+
317+
func TestCreateArgs(t *testing.T) {
318+
o := &CreateOpts{}
319+
args, err := o.args()
320+
if err != nil {
321+
t.Fatal(err)
322+
}
323+
if len(args) != 0 {
324+
t.Fatal("args should be empty")
325+
}
326+
o.ExtraArgs = []string{"--other"}
327+
args, err = o.args()
328+
if err != nil {
329+
t.Fatal(err)
330+
}
331+
if len(args) != 1 {
332+
t.Fatal("args should have 1 arg")
333+
}
334+
if a := args[0]; a != "--other" {
335+
t.Fatalf("arg should be --other but got %q", a)
336+
}
337+
338+
}

runc_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ type Runc struct {
3535
Criu string
3636
SystemdCgroup bool
3737
Rootless *bool // nil stands for "auto"
38+
ExtraArgs []string
3839
}

0 commit comments

Comments
 (0)