Skip to content

Commit

Permalink
Merge pull request #23675 from ruihe774/fix-pod-cgroups
Browse files Browse the repository at this point in the history
Add key CgroupsMode in Quadlet container unit
  • Loading branch information
openshift-merge-bot[bot] authored Aug 20, 2024
2 parents a3adad9 + 1ccccde commit 8be89ca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ Valid options for `[Container]` are listed below:
| AddDevice=/dev/foo | --device /dev/foo |
| Annotation="XYZ" | --annotation "XYZ" |
| AutoUpdate=registry | --label "io.containers.autoupdate=registry" |
| CgroupsMode=no-conmon | --cgroups=no-conmon |
| ContainerName=name | --name name |
| ContainersConfModule=/etc/nvd\.conf | --module=/etc/nvd\.conf |
| DNS=192.168.55.1 | --dns=192.168.55.1 |
Expand Down Expand Up @@ -370,6 +371,16 @@ Indicates whether the container will be auto-updated ([podman-auto-update(1)](po

* `local`: Tells Podman to compare the image a container is using to the image with its raw name in local storage. If an image is updated locally, Podman simply restarts the systemd unit executing the container.

### `CgroupsMode=`

The cgroups mode of the Podman container. Equivalent to the Podman `--cgroups` option.

By default, the cgroups mode of the container created by Quadlet is `split`,
which differs from the default (`enabled`) used by the Podman CLI.

If the container joins a pod (i.e. `Pod=` is specified), you may want to change this to
`no-conmon` or `enabled` so that pod level cgroup resource limits can take effect.

### `ContainerName=`

The (optional) name of the Podman container. If this is not specified, the default value
Expand Down
9 changes: 8 additions & 1 deletion pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const (
KeyAuthFile = "AuthFile"
KeyAutoUpdate = "AutoUpdate"
KeyCertDir = "CertDir"
KeyCgroupsMode = "CgroupsMode"
KeyConfigMap = "ConfigMap"
KeyContainerName = "ContainerName"
KeyContainersConfModule = "ContainersConfModule"
Expand Down Expand Up @@ -191,6 +192,7 @@ var (
KeyAddDevice: true,
KeyAnnotation: true,
KeyAutoUpdate: true,
KeyCgroupsMode: true,
KeyContainerName: true,
KeyContainersConfModule: true,
KeyDNS: true,
Expand Down Expand Up @@ -581,7 +583,12 @@ func ConvertContainer(container *parser.UnitFile, isUser bool, unitsInfoMap map[

// We delegate groups to the runtime
service.Add(ServiceGroup, "Delegate", "yes")
podman.add("--cgroups=split")

if cgroupsMode, ok := container.Lookup(ContainerGroup, KeyCgroupsMode); ok && len(cgroupsMode) > 0 {
podman.addf("--cgroups=%s", cgroupsMode)
} else {
podman.add("--cgroups=split")
}

timezone, ok := container.Lookup(ContainerGroup, KeyTimezone)
if ok && len(timezone) > 0 {
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/quadlet/cgroups-mode.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## assert-podman-args --cgroups=no-conmon

[Container]
Image=localhost/imagename
CgroupsMode=no-conmon
1 change: 1 addition & 0 deletions test/e2e/quadlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ BOGUS=foo
Entry("[email protected]", "[email protected]"),
Entry("Unit After Override", "unit-after-override.container"),
Entry("NetworkAlias", "network-alias.container"),
Entry("CgroupMode", "cgroups-mode.container"),

Entry("basic.volume", "basic.volume"),
Entry("device-copy.volume", "device-copy.volume"),
Expand Down

0 comments on commit 8be89ca

Please sign in to comment.