Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PidsLimit in quadlet #19955

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Valid options for `[Container]` are listed below:
| NoNewPrivileges=true | --security-opt no-new-privileges |
| Rootfs=/var/lib/rootfs | --rootfs /var/lib/rootfs |
| Notify=true | --sdnotify container |
| PidsLimit=10000 | --pids-limit 10000 |
| PodmanArgs=--add-host foobar | --add-host foobar |
| PublishPort=50-59 | --publish 50-59 |
| Pull=never | --pull=never |
Expand Down Expand Up @@ -410,6 +411,11 @@ starts the child in the container. However, if the container application support
`Notify` to true passes the notification details to the container allowing it to notify
of startup on its own.

### `PidsLimit=`

Tune the container's pids limit.
This is equivalent to the Podman `--pids-limit` option.

### `PodmanArgs=`

This key contains a list of arguments passed directly to the end of the `podman run` command
Expand Down
19 changes: 13 additions & 6 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const (
KeyNoNewPrivileges = "NoNewPrivileges"
KeyNotify = "Notify"
KeyOptions = "Options"
KeyPidsLimit = "PidsLimit"
KeyPodmanArgs = "PodmanArgs"
KeyPublishPort = "PublishPort"
KeyPull = "Pull"
Expand Down Expand Up @@ -163,6 +164,7 @@ var (
KeyNetwork: true,
KeyNoNewPrivileges: true,
KeyNotify: true,
KeyPidsLimit: true,
KeyPodmanArgs: true,
KeyPublishPort: true,
KeyPull: true,
Expand Down Expand Up @@ -449,18 +451,23 @@ func ConvertContainer(container *parser.UnitFile, names map[string]string, isUse
podman.add("--security-opt", "label:nested")
}

securityLabelType, _ := container.Lookup(ContainerGroup, KeySecurityLabelType)
if len(securityLabelType) > 0 {
pidsLimit, ok := container.Lookup(ContainerGroup, KeyPidsLimit)
if ok && len(pidsLimit) > 0 {
podman.add("--pids-limit", pidsLimit)
}

securityLabelType, ok := container.Lookup(ContainerGroup, KeySecurityLabelType)
if ok && len(securityLabelType) > 0 {
podman.add("--security-opt", fmt.Sprintf("label=type:%s", securityLabelType))
}

securityLabelFileType, _ := container.Lookup(ContainerGroup, KeySecurityLabelFileType)
if len(securityLabelFileType) > 0 {
securityLabelFileType, ok := container.Lookup(ContainerGroup, KeySecurityLabelFileType)
if ok && len(securityLabelFileType) > 0 {
podman.add("--security-opt", fmt.Sprintf("label=filetype:%s", securityLabelFileType))
}

securityLabelLevel, _ := container.Lookup(ContainerGroup, KeySecurityLabelLevel)
if len(securityLabelLevel) > 0 {
securityLabelLevel, ok := container.Lookup(ContainerGroup, KeySecurityLabelLevel)
if ok && len(securityLabelLevel) > 0 {
podman.add("--security-opt", fmt.Sprintf("label=level:%s", securityLabelLevel))
}

Expand Down
6 changes: 6 additions & 0 deletions test/e2e/quadlet/pids-limit.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## assert-podman-final-args localhost/imagename
## assert-podman-args "--pids-limit" "8765432"

[Container]
Image=localhost/imagename
PidsLimit=8765432