Skip to content
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
2 changes: 1 addition & 1 deletion docs/source/markdown/podman-pod-create.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Set the exit policy of the pod when the last container exits. Supported policie
| Exit Policy | Description |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------- |
| *continue* | The pod continues running, by keeping its infra container alive, when the last container exits. Used by default. |
| *stop* | The pod (including its infra container) is stopped when the last container exits. Used in `kube play`. |
| *stop* | The pod (including its infra container) is stopped when the last container exits. Used in `kube play` and quadlets. |

@@option gidmap.pod

Expand Down
40 changes: 40 additions & 0 deletions docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ Valid options for `[Pod]` are listed below:
| DNS=192.168.55.1 | --dns=192.168.55.1 |
| DNSOption=ndots:1 | --dns-option=ndots:1 |
| DNSSearch=example.com | --dns-search example.com |
| ExitPolicy=stop | --exit-policy stop |
| GIDMap=0:10000:10 | --gidmap=0:10000:10 |
| GlobalArgs=--log-level=debug | --log-level=debug |
| HostName=name | --hostname=name |
Expand Down Expand Up @@ -1059,6 +1060,12 @@ Set custom DNS search domains. Use **DNSSearch=.** to remove the search domain.

This key can be listed multiple times.

### `ExitPolicy=`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an extra empty line


Set the exit policy of the pod when the last container exits. Default for quadlets is **stop**.

To keep the pod active, set `ExitPolicy=continue`.

### `GIDMap=`

Create the pod in a new user namespace using the supplied GID mapping.
Expand Down Expand Up @@ -2175,6 +2182,39 @@ Exec=sh -c "sleep inf"
Pod=test.pod
```

Example for a Pod with a oneshot Startup Task:

`test.pod`
```
[Pod]
PodName=test
ExitPolicy=continue
```

`startup-task.container`
```
[Service]
Type=oneshot
RemainAfterExit=yes

[Container]
Pod=test.pod
Image=quay.io/centos/centos:latest
Exec=sh -c "echo 'setup starting'; sleep 2; echo 'setup complete'"
```

`app.container`
```
[Unit]
Requires=startup-task.container
After=startup-task.container

[Container]
Pod=test.pod
Image=quay.io/centos/centos:latest
Exec=sh -c "echo 'app running.'; sleep 30"
```

Example `s3fs.volume`:

For further details, please see the [s3fs-fuse](https://github.com/s3fs-fuse/s3fs-fuse) project.
Expand Down
16 changes: 15 additions & 1 deletion pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const (
KeyEnvironmentHost = "EnvironmentHost"
KeyExec = "Exec"
KeyExitCodePropagation = "ExitCodePropagation"
KeyExitPolicy = "ExitPolicy"
KeyExposeHostPort = "ExposeHostPort"
KeyFile = "File"
KeyForceRM = "ForceRM"
Expand Down Expand Up @@ -472,6 +473,7 @@ var (
KeyDNS: true,
KeyDNSOption: true,
KeyDNSSearch: true,
KeyExitPolicy: true,
KeyGIDMap: true,
KeyGlobalArgs: true,
KeyHostName: true,
Expand Down Expand Up @@ -1538,10 +1540,11 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
execStartPre.add("pod", "create")
execStartPre.add(
"--infra-conmon-pidfile=%t/%N.pid",
"--exit-policy=stop",
"--replace",
)

handleExitPolicy(podUnit, PodGroup, execStartPre)

if err := handleUserMappings(podUnit, PodGroup, execStartPre, true); err != nil {
return nil, warnings, err
}
Expand Down Expand Up @@ -1800,6 +1803,17 @@ func getAbsolutePath(quadletUnitFile *parser.UnitFile, filePath string) (string,
return filePath, nil
}

func handleExitPolicy(unitFile *parser.UnitFile, groupName string, podman *PodmanCmdline) {
exitPolicy, found := unitFile.Lookup(groupName, KeyExitPolicy)

podman.add("--exit-policy")
if found {
podman.add(exitPolicy)
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no biggie but if one of these options is kind of a default, we will often set that and use a single condition as an override. maybe consider fix if you repush with someone else's comment (only if you consider one of them to be the default).

podman.add("stop")
}
}

func handlePublishPorts(unitFile *parser.UnitFile, groupName string, podman *PodmanCmdline) {
publishPorts := unitFile.LookupAll(groupName, KeyPublishPort)
for _, publishPort := range publishPorts {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/quadlet/basic.pod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## assert-key-is Unit RequiresMountsFor "%t/containers"
## assert-key-is Service Type forking
## assert-key-is Service SyslogIdentifier "%N"
## assert-key-is-regex Service ExecStartPre ".*/podman pod create --infra-conmon-pidfile=%t/%N.pid --exit-policy=stop --replace --infra-name systemd-basic-infra --name systemd-basic"
## assert-key-is-regex Service ExecStartPre ".*/podman pod create --infra-conmon-pidfile=%t/%N.pid --replace --exit-policy stop --infra-name systemd-basic-infra --name systemd-basic"
## assert-key-is-regex Service ExecStart ".*/podman pod start systemd-basic"
## assert-key-is-regex Service ExecStop ".*/podman pod stop --ignore --time=10 systemd-basic"
## assert-key-is-regex Service ExecStopPost ".*/podman pod rm --ignore --force systemd-basic"
Expand Down
5 changes: 5 additions & 0 deletions test/system/252-quadlet.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,11 @@ EOF
# Pod should exist
run_podman pod exists ${test_pod_name}

# Pod exit policy should be stop by default
run_podman pod inspect --format "{{.ExitPolicy}}" ${test_pod_name}
assert "$output" = "stop" \
"quadlet - pod: default ExitPolicy should be stop"

# Wait for systemd to activate the container service
wait_for_command_output "systemctl show --property=ActiveState $container_service" "ActiveState=active"

Expand Down