Skip to content

Commit 125a587

Browse files
add jailer support for parent-cgroup argument (#638)
Signed-off-by: JooYoung Park <[email protected]>
1 parent 3a6ac02 commit 125a587

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

jailer.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ type JailerConfig struct {
8989
// formatted like <cgroup_file>=<value>, like "cpu.shares=10"
9090
CgroupArgs []string
9191

92+
// ParentCgroup is the parent cgroup for the jailer. By specifying this
93+
// parameter, the jailer will create a new cgroup named id for the
94+
// microvm in the <cgroup_base>/<parent_cgroup> subfolder.
95+
ParentCgroup string
96+
9297
// Stdout specifies the IO writer for STDOUT to use when spawning the jailer.
9398
Stdout io.Writer
9499
// Stderr specifies the IO writer for STDERR to use when spawning the jailer.
@@ -114,6 +119,7 @@ type JailerCommandBuilder struct {
114119
firecrackerArgs []string
115120
cgroupVersion string
116121
cgroupArgs []string
122+
parentCgroup string
117123

118124
stdin io.Reader
119125
stdout io.Writer
@@ -156,6 +162,10 @@ func (b JailerCommandBuilder) Args() []string {
156162
args = append(args, "--cgroup-version", b.cgroupVersion)
157163
}
158164

165+
if len(b.parentCgroup) > 0 {
166+
args = append(args, "--parent-cgroup", b.parentCgroup)
167+
}
168+
159169
if len(b.chrootBaseDir) > 0 {
160170
args = append(args, "--chroot-base-dir", b.chrootBaseDir)
161171
}
@@ -237,6 +247,12 @@ func (b JailerCommandBuilder) WithCgroupArgs(cgroupArgs ...string) JailerCommand
237247
return b
238248
}
239249

250+
// WithParentCgroup will set the parent cgroup for the jailer.
251+
func (b JailerCommandBuilder) WithParentCgroup(parentCgroup string) JailerCommandBuilder {
252+
b.parentCgroup = parentCgroup
253+
return b
254+
}
255+
240256
// WithChrootBaseDir will set the given path as the chroot base directory. This
241257
// specifies where chroot jails are built and defaults to /srv/jailer.
242258
func (b JailerCommandBuilder) WithChrootBaseDir(path string) JailerCommandBuilder {
@@ -375,6 +391,7 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
375391
WithDaemonize(cfg.JailerCfg.Daemonize).
376392
WithCgroupVersion(cfg.JailerCfg.CgroupVersion).
377393
WithCgroupArgs(cfg.JailerCfg.CgroupArgs...).
394+
WithParentCgroup(cfg.JailerCfg.ParentCgroup).
378395
WithFirecrackerArgs(fcArgs...).
379396
WithStdout(stdout).
380397
WithStderr(stderr)

jailer_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func TestJailerBuilder(t *testing.T) {
109109
ChrootBaseDir: "/tmp",
110110
JailerBinary: "/path/to/the/jailer",
111111
CgroupVersion: "2",
112+
ParentCgroup: "/path/to/parent-cgroup",
112113
},
113114
expectedArgs: []string{
114115
"/path/to/the/jailer",
@@ -128,6 +129,8 @@ func TestJailerBuilder(t *testing.T) {
128129
"cpu.shares=10",
129130
"--cgroup-version",
130131
"2",
132+
"--parent-cgroup",
133+
"/path/to/parent-cgroup",
131134
"--chroot-base-dir",
132135
"/tmp",
133136
"--netns",
@@ -151,6 +154,7 @@ func TestJailerBuilder(t *testing.T) {
151154
WithNumaNode(IntValue(c.jailerCfg.NumaNode)).
152155
WithCgroupArgs(c.jailerCfg.CgroupArgs...).
153156
WithCgroupVersion(c.jailerCfg.CgroupVersion).
157+
WithParentCgroup(c.jailerCfg.ParentCgroup).
154158
WithExecFile(c.jailerCfg.ExecFile)
155159

156160
if len(c.jailerCfg.JailerBinary) > 0 {
@@ -274,6 +278,7 @@ func TestJail(t *testing.T) {
274278
ChrootBaseDir: "/tmp",
275279
JailerBinary: "/path/to/the/jailer",
276280
CgroupVersion: "2",
281+
ParentCgroup: "/path/to/parent-cgroup",
277282
},
278283
expectedArgs: []string{
279284
"/path/to/the/jailer",
@@ -291,6 +296,8 @@ func TestJail(t *testing.T) {
291296
fmt.Sprintf("cpuset.cpus=%s", getNumaCpuset(0)),
292297
"--cgroup-version",
293298
"2",
299+
"--parent-cgroup",
300+
"/path/to/parent-cgroup",
294301
"--chroot-base-dir",
295302
"/tmp",
296303
"--netns",

0 commit comments

Comments
 (0)