@@ -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.
242258func (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 )
0 commit comments