Skip to content

Commit 32e5fd9

Browse files
committed
specs-go/config: add systemd cgroup support
The `--systemd-cgroup` flag and the systemd cgroup path convention currently implemented in `runc/crun` should be added to the spec. This patch adds in the spec: * the option to enable systemd cgroup; * the configs of systemd units and the containing slice to map to the cgroup tree. Fixes #1021 Signed-off-by: Kailun Qin <kailun.qin@intel.com>
1 parent 8961758 commit 32e5fd9

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

config-linux.md

+48
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,54 @@ Runtimes MAY attach the container process to additional cgroup controllers beyon
214214
}
215215
```
216216

217+
### <a name="configLinuxSystemdCgroup" />Systemd Cgroup
218+
219+
* **`systemdCgroup`** *(bool, OPTIONAL)* - enables or disables systemd cgroup support.
220+
If enabled (`true`), the container runtime switches to the systemd cgroup driver for creating
221+
cgroups and setting cgroup limits.
222+
223+
* **`systemdCgroupsPath`** (object, OPTIONAL) - sets the systemd cgroups path configurations.
224+
By specifying with the transient systemd unit to create for the container and the containing
225+
slice which hosts the unit, the systemd units directly map to objects in the cgroup tree.
226+
When these units are activated, they map directly to cgroup paths built from the unit names.
227+
228+
The following parameters can be specified to set up the `systemdCgroupsPath`:
229+
Each entry has the following structure:
230+
231+
* **`type`** *(string, REQUIRED)* - type of the systemd unit: `scope` or `slice`.
232+
* **`parentSlice`** *(string, OPTIONAL)* - name of the parent slice with type suffix, under which the container is placed.
233+
Note that `slice` can contain dashes to denote a sub-slice (e.g. `user-1000.slice` is a correct
234+
notation, meaning a subslice of `user.slice`), but it must not contain slashes (e.g.
235+
`user.slice/user-1000.slice` is invalid).
236+
There might be some slices already created by default, for example:
237+
`-.slice` - the root slice;
238+
`system.slice` - the default place for all system services;
239+
`user.slice` - the default place for all user sessions.
240+
* **`name`** *(string, OPTIONAL)* - systemd unit name (without type suffix).
241+
242+
### Example
243+
244+
```json
245+
"systemdCgroup": true,
246+
"systemdCgroupsPath": {
247+
"type": "scope",
248+
"parentSlice": "user.slice",
249+
"name": "runtime-foo"
250+
},
251+
"resources": {
252+
"memory": {
253+
"limit": 100000,
254+
"reservation": 200000
255+
},
256+
"devices": [
257+
{
258+
"allow": false,
259+
"access": "rwm"
260+
}
261+
]
262+
}
263+
```
264+
217265
### <a name="configLinuxDeviceAllowedlist" />Allowed Device list
218266

219267
**`devices`** (array of objects, OPTIONAL) configures the [allowed device list][cgroup-v1-devices].

specs-go/config.go

+37
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ type Linux struct {
163163
// The path is expected to be relative to the cgroups mountpoint.
164164
// If resources are specified, the cgroups at CgroupsPath will be updated based on resources.
165165
CgroupsPath string `json:"cgroupsPath,omitempty"`
166+
// SystemdCgroup controls whether to enable systemd cgroup support.
167+
SystemdCgroup bool `json:"systemdCgroup,omitempty"`
168+
// SystemdCgroupsPath specifies the transient systemd unit to create for the container and the
169+
// containing slice which hosts the unit. The systemd units directly map to objects in the
170+
// cgroup tree. When these units are activated, they map directly to cgroup paths built from the
171+
// unit names.
172+
SystemdCgroupsPath LinuxSystemdCgroupsPath `json:"systemdCgroupsPath,omitempty"`
166173
// Namespaces contains the namespaces that are created and/or joined by the container
167174
Namespaces []LinuxNamespace `json:"namespaces,omitempty"`
168175
// Devices are a list of device nodes that are created for the container
@@ -184,6 +191,36 @@ type Linux struct {
184191
Personality *LinuxPersonality `json:"personality,omitempty"`
185192
}
186193

194+
// LinuxSystemdCgroupsPath specifies the transient systemd unit to create for the container and the
195+
// containing slice which hosts the unit.
196+
type LinuxSystemdCgroupsPath struct {
197+
// Type is the type of the systemd unit.
198+
Type SystemdUnitType `json:"type"`
199+
// ParentSlice specifies the name of the parent slice with type suffix, under which the
200+
// container is placed. Some examples below:
201+
// `-.slice` - the root slice;
202+
// `system.slice` - the default place for all system services;
203+
// `user.slice` - the default place for all user sessions.
204+
ParentSlice string `json:"parentSlice,omitempty"`
205+
// Name is the systemd unit name (without type suffix).
206+
Name string `json:"name,omitempty"`
207+
}
208+
209+
// SystemdUnitType defines the type of the systemd unit.
210+
type SystemdUnitType string
211+
212+
// SystemdUnitType defines the type of the systemd unit.
213+
const (
214+
// Scope is a group of externally created processes.
215+
// Scopes encapsulate processes that are started and stopped by arbitrary processes through the
216+
// fork() function and then registered by systemd at runtime.
217+
Scope SystemdUnitType = "scope"
218+
// Slice is a group of hierarchically organized units.
219+
// Slices do not contain processes, they organize a hierarchy in which scopes and services are
220+
// placed.
221+
Slice SystemdUnitType = "slice"
222+
)
223+
187224
// LinuxNamespace is the configuration for a Linux namespace
188225
type LinuxNamespace struct {
189226
// Type is the type of namespace

0 commit comments

Comments
 (0)