Skip to content

Commit cb1c938

Browse files
committed
Allow passing cgroup-version to jailer
Signed-off-by: Lorenzo Fontana <[email protected]>
1 parent b53c309 commit cb1c938

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

jailer.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ type JailerConfig struct {
8383
// ChrootStrategy will dictate how files are transfered to the root drive.
8484
ChrootStrategy HandlersAdapter
8585

86+
// CgroupVersion is the version of the cgroup filesystem to use.
87+
CgroupVersion string
88+
8689
// Stdout specifies the IO writer for STDOUT to use when spawning the jailer.
8790
Stdout io.Writer
8891
// Stderr specifies the IO writer for STDERR to use when spawning the jailer.
@@ -106,6 +109,7 @@ type JailerCommandBuilder struct {
106109
netNS string
107110
daemonize bool
108111
firecrackerArgs []string
112+
cgroupVersion string
109113

110114
stdin io.Reader
111115
stdout io.Writer
@@ -140,6 +144,10 @@ func (b JailerCommandBuilder) Args() []string {
140144
args = append(args, "--cgroup", fmt.Sprintf("cpuset.cpus=%s", cpulist))
141145
}
142146

147+
if len(b.cgroupVersion) > 0 {
148+
args = append(args, "--cgroup-version", b.cgroupVersion)
149+
}
150+
143151
if len(b.chrootBaseDir) > 0 {
144152
args = append(args, "--chroot-base-dir", b.chrootBaseDir)
145153
}
@@ -271,6 +279,12 @@ func (b JailerCommandBuilder) WithFirecrackerArgs(args ...string) JailerCommandB
271279
return b
272280
}
273281

282+
// WithCgroupVersion specifies which cgroup version to use
283+
func (b JailerCommandBuilder) WithCgroupVersion(version string) JailerCommandBuilder {
284+
b.cgroupVersion = version
285+
return b
286+
}
287+
274288
// Build will build a jailer command.
275289
func (b JailerCommandBuilder) Build(ctx context.Context) *exec.Cmd {
276290
cmd := exec.CommandContext(
@@ -334,6 +348,7 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
334348
WithExecFile(cfg.JailerCfg.ExecFile).
335349
WithChrootBaseDir(cfg.JailerCfg.ChrootBaseDir).
336350
WithDaemonize(cfg.JailerCfg.Daemonize).
351+
WithCgroupVersion(cfg.JailerCfg.CgroupVersion).
337352
WithFirecrackerArgs(fcArgs...).
338353
WithStdout(stdout).
339354
WithStderr(stderr)

jailer_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func TestJailerBuilder(t *testing.T) {
107107
ExecFile: "/path/to/firecracker",
108108
ChrootBaseDir: "/tmp",
109109
JailerBinary: "/path/to/the/jailer",
110+
CgroupVersion: "2",
110111
},
111112
expectedArgs: []string{
112113
"/path/to/the/jailer",
@@ -122,6 +123,8 @@ func TestJailerBuilder(t *testing.T) {
122123
"cpuset.mems=0",
123124
"--cgroup",
124125
fmt.Sprintf("cpuset.cpus=%s", getNumaCpuset(0)),
126+
"--cgroup-version",
127+
"2",
125128
"--chroot-base-dir",
126129
"/tmp",
127130
"--netns",
@@ -143,6 +146,7 @@ func TestJailerBuilder(t *testing.T) {
143146
WithUID(IntValue(c.jailerCfg.UID)).
144147
WithGID(IntValue(c.jailerCfg.GID)).
145148
WithNumaNode(IntValue(c.jailerCfg.NumaNode)).
149+
WithCgroupVersion(c.jailerCfg.CgroupVersion).
146150
WithExecFile(c.jailerCfg.ExecFile)
147151

148152
if len(c.jailerCfg.JailerBinary) > 0 {
@@ -265,6 +269,7 @@ func TestJail(t *testing.T) {
265269
ExecFile: "/path/to/firecracker",
266270
ChrootBaseDir: "/tmp",
267271
JailerBinary: "/path/to/the/jailer",
272+
CgroupVersion: "2",
268273
},
269274
expectedArgs: []string{
270275
"/path/to/the/jailer",
@@ -280,6 +285,8 @@ func TestJail(t *testing.T) {
280285
"cpuset.mems=0",
281286
"--cgroup",
282287
fmt.Sprintf("cpuset.cpus=%s", getNumaCpuset(0)),
288+
"--cgroup-version",
289+
"2",
283290
"--chroot-base-dir",
284291
"/tmp",
285292
"--netns",

0 commit comments

Comments
 (0)