Skip to content

Commit 25defe7

Browse files
committed
pkg/systemd: expose [Pod] ExitPolicy key for pod create --exit-policy
Add ExitPolicy key to pod quadlets with logic to default to stop. Docs updated with clarifcation on default value and usage example. Simple assert added to bats to verify default constraint exists. Changed argument order in ginkgo basic pod unit test Signed-off-by: Neil Bailey <nbsp@nbailey.net>
1 parent 70435a0 commit 25defe7

File tree

6 files changed

+7157
-3
lines changed

6 files changed

+7157
-3
lines changed

docs/source/markdown/podman-pod-create.1.md.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Set the exit policy of the pod when the last container exits. Supported policie
7676
| Exit Policy | Description |
7777
| ------------------ | -------------------------------------------------------------------------------------------------------------------------- |
7878
| *continue* | The pod continues running, by keeping its infra container alive, when the last container exits. Used by default. |
79-
| *stop* | The pod (including its infra container) is stopped when the last container exits. Used in `kube play`. |
79+
| *stop* | The pod (including its infra container) is stopped when the last container exits. Used in `kube play` and quadlets. |
8080

8181
@@option gidmap.pod
8282

docs/source/markdown/podman-systemd.unit.5.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ Valid options for `[Pod]` are listed below:
10061006
| DNS=192.168.55.1 | --dns=192.168.55.1 |
10071007
| DNSOption=ndots:1 | --dns-option=ndots:1 |
10081008
| DNSSearch=example.com | --dns-search example.com |
1009+
| ExitPolicy=stop | --exit-policy stop |
10091010
| GIDMap=0:10000:10 | --gidmap=0:10000:10 |
10101011
| GlobalArgs=--log-level=debug | --log-level=debug |
10111012
| HostName=name | --hostname=name |
@@ -1058,6 +1059,11 @@ This key can be listed multiple times.
10581059
Set custom DNS search domains. Use **DNSSearch=.** to remove the search domain.
10591060

10601061
This key can be listed multiple times.
1062+
### `ExitPolicy=`
1063+
1064+
Set the exit policy of the pod when the last container exits. Default for quadlets is **stop**.
1065+
1066+
To keep the pod active, set `ExitPolicy=continue`.
10611067

10621068
### `GIDMap=`
10631069

@@ -2175,6 +2181,39 @@ Exec=sh -c "sleep inf"
21752181
Pod=test.pod
21762182
```
21772183

2184+
Example for a Pod with a oneshot Startup Task:
2185+
2186+
`test.pod`
2187+
```
2188+
[Pod]
2189+
PodName=test
2190+
ExitPolicy=continue
2191+
```
2192+
2193+
`startup-task.container`
2194+
```
2195+
[Service]
2196+
Type=oneshot
2197+
RemainAfterExit=yes
2198+
2199+
[Container]
2200+
Pod=test.pod
2201+
Image=quay.io/centos/centos:latest
2202+
Exec=sh -c "echo 'setup starting'; sleep 2; echo 'setup complete'"
2203+
```
2204+
2205+
`app.container`
2206+
```
2207+
[Unit]
2208+
Requires=startup-task.container
2209+
After=startup-task.container
2210+
2211+
[Container]
2212+
Pod=test.pod
2213+
Image=quay.io/centos/centos:latest
2214+
Exec=sh -c "echo 'app running.'; sleep 30"
2215+
```
2216+
21782217
Example `s3fs.volume`:
21792218

21802219
For further details, please see the [s3fs-fuse](https://github.com/s3fs-fuse/s3fs-fuse) project.

pkg/systemd/quadlet/quadlet.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const (
8686
KeyEnvironmentHost = "EnvironmentHost"
8787
KeyExec = "Exec"
8888
KeyExitCodePropagation = "ExitCodePropagation"
89+
KeyExitPolicy = "ExitPolicy"
8990
KeyExposeHostPort = "ExposeHostPort"
9091
KeyFile = "File"
9192
KeyForceRM = "ForceRM"
@@ -472,6 +473,7 @@ var (
472473
KeyDNS: true,
473474
KeyDNSOption: true,
474475
KeyDNSSearch: true,
476+
KeyExitPolicy: true,
475477
KeyGIDMap: true,
476478
KeyGlobalArgs: true,
477479
KeyHostName: true,
@@ -1538,10 +1540,11 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
15381540
execStartPre.add("pod", "create")
15391541
execStartPre.add(
15401542
"--infra-conmon-pidfile=%t/%N.pid",
1541-
"--exit-policy=stop",
15421543
"--replace",
15431544
)
15441545

1546+
handleExitPolicy(podUnit, PodGroup, execStartPre)
1547+
15451548
if err := handleUserMappings(podUnit, PodGroup, execStartPre, true); err != nil {
15461549
return nil, warnings, err
15471550
}
@@ -1800,6 +1803,17 @@ func getAbsolutePath(quadletUnitFile *parser.UnitFile, filePath string) (string,
18001803
return filePath, nil
18011804
}
18021805

1806+
func handleExitPolicy(unitFile *parser.UnitFile, groupName string, podman *PodmanCmdline) {
1807+
exitPolicy, found := unitFile.Lookup(groupName, KeyExitPolicy)
1808+
1809+
podman.add("--exit-policy")
1810+
if found {
1811+
podman.add(exitPolicy)
1812+
} else {
1813+
podman.add("stop")
1814+
}
1815+
}
1816+
18031817
func handlePublishPorts(unitFile *parser.UnitFile, groupName string, podman *PodmanCmdline) {
18041818
publishPorts := unitFile.LookupAll(groupName, KeyPublishPort)
18051819
for _, publishPort := range publishPorts {

0 commit comments

Comments
 (0)