Skip to content

Commit a1ac6c3

Browse files
Merge pull request #26113 from ygalblum/quadlet-pod-name
Quadlet - restore pod name to not use systemd specifiers
2 parents cbcb777 + 700c679 commit a1ac6c3

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ Requires=basic.container
274274
Image=registry.fedoraproject.org/fedora:41
275275
```
276276

277+
### Setting resource names
278+
279+
Quadlet units allow setting the names of the created resources
280+
(e.g. `VolumeName` for `.volume` units or `PodName` for `.pod` units).
281+
282+
Note that using systemd specifiers that reference the generated service unit (e.g. `$N`)
283+
breaks Quadlet's ability to link between resources as they are translated differently in each service
284+
277285
## Container units [Container]
278286

279287
Container units are named with a `.container` extension and contain a `[Container]` section describing
@@ -1138,9 +1146,9 @@ This key can be listed multiple times.
11381146

11391147
### `PodName=`
11401148

1141-
The (optional) name of the Podman pod. If this is not specified, the default value
1142-
of `systemd-%N` is used, which is the same as the service name but with a `systemd-`
1143-
prefix to avoid conflicts with user-managed containers.
1149+
The (optional) name of the Podman pod.
1150+
If this is not specified, the default value is the same name as the unit, but with a `systemd-` prefix,
1151+
i.e. a `$name.pod` file creates a `systemd-$name` Podman pod to avoid conflicts with user-managed pods.
11441152

11451153
Please note that pods and containers cannot have the same name.
11461154
So, if PodName is set, it must not conflict with any container.
@@ -1488,9 +1496,10 @@ When set to `true` the network is deleted when the service is stopped
14881496

14891497
### `NetworkName=`
14901498

1491-
The (optional) name of the Podman network. If this is not specified, the default value of
1492-
`systemd-%N` is used, which is the same as the unit name but with a `systemd-` prefix to avoid
1493-
conflicts with user-managed networks.
1499+
The (optional) name of the Podman network.
1500+
If this is not specified, the default value is the same name as the unit, but with a `systemd-` prefix,
1501+
i.e. a `$name.network` file creates a `systemd-$name` Podman network to avoid
1502+
conflicts with user-managed network.
14941503

14951504
### `Options=`
14961505

@@ -1639,8 +1648,9 @@ The host (numeric) UID, or user name to use as the owner for the volume
16391648

16401649
### `VolumeName=`
16411650

1642-
The (optional) name of the Podman volume. If this is not specified, the default value of
1643-
`systemd-%N` is used, which is the same as the unit name but with a `systemd-` prefix to avoid
1651+
The (optional) name of the Podman volume.
1652+
If this is not specified, the default value is the same name as the unit, but with a `systemd-` prefix,
1653+
i.e. a `$name.volume` file creates a `systemd-$name` Podman volume to avoid
16441654
conflicts with user-managed volumes.
16451655

16461656
## Build units [Build]

pkg/systemd/quadlet/quadlet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ func GetPodResourceName(podUnit *parser.UnitFile) string {
14821482
// Derive pod name from unit name (with added prefix), or use user-provided name.
14831483
podName, ok := podUnit.Lookup(PodGroup, KeyPodName)
14841484
if !ok || len(podName) == 0 {
1485-
podName = "systemd-%N"
1485+
podName = removeExtension(podUnit.Filename, "systemd-", "")
14861486
}
14871487
return podName
14881488
}

test/e2e/quadlet/basic.pod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
## assert-key-is Unit RequiresMountsFor "%t/containers"
22
## assert-key-is Service Type forking
33
## assert-key-is Service SyslogIdentifier "%N"
4-
## assert-key-is-regex Service ExecStartPre ".*/podman pod create --infra-conmon-pidfile=%t/%N.pid --exit-policy=stop --replace --infra-name systemd-%N-infra --name systemd-%N"
5-
## assert-key-is-regex Service ExecStart ".*/podman pod start systemd-%N"
6-
## assert-key-is-regex Service ExecStop ".*/podman pod stop --ignore --time=10 systemd-%N"
7-
## assert-key-is-regex Service ExecStopPost ".*/podman pod rm --ignore --force systemd-%N"
4+
## 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"
5+
## assert-key-is-regex Service ExecStart ".*/podman pod start systemd-basic"
6+
## assert-key-is-regex Service ExecStop ".*/podman pod stop --ignore --time=10 systemd-basic"
7+
## assert-key-is-regex Service ExecStopPost ".*/podman pod rm --ignore --force systemd-basic"
88

99
[Pod]

0 commit comments

Comments
 (0)