Skip to content
Open
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-container.unit.5.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ setting up a container healthcheck, see the `HealthCmd` option for more.
Specify a Quadlet `.pod` unit to link the container to.
The value must take the form of `<name>.pod` and the `.pod` unit must exist.

In this value, Quadlet expands the `%N` specifier to the container's service name (the
`ServiceName=` value if set, otherwise the name derived from the unit file), for example
`Pod=%N.pod`. The expansion happens while the unit is generated, and `%N` is the only
specifier resolved in this key.

Quadlet will add all the necessary parameters to link between the container and the pod and between their corresponding services.


Expand Down Expand Up @@ -443,6 +448,7 @@ DefaultDependencies=false
By default, the container is named `systemd-<unitname>`. Use `ContainerName=` to override.

Avoid using systemd specifiers like `%N` in resource names—they break inter-resource linking.
The exception is `%N` in `Pod=`, which Quadlet expands while generating the unit.

# TEMPLATE UNITS

Expand Down
4 changes: 4 additions & 0 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,10 @@ func createBasePodmanCommand(unitFile *parser.UnitFile, groupName string) *Podma
func handlePod(quadletUnitFile, serviceUnitFile *parser.UnitFile, groupName string, unitsInfoMap map[string]*UnitInfo, podman *PodmanCmdline) error {
pod, ok := quadletUnitFile.Lookup(groupName, KeyPod)
if ok && len(pod) > 0 {
// XXX: only %N is handled.
// it is difficult to properly implement specifiers handling without consulting systemd.
pod = strings.ReplaceAll(pod, "%N", GetContainerServiceName(quadletUnitFile))

if !strings.HasSuffix(pod, ".pod") {
return fmt.Errorf("pod %s is not Quadlet based", pod)
}
Expand Down
1 change: 1 addition & 0 deletions test/e2e/quadlet/pod-specifier-svc.pod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Pod]
7 changes: 7 additions & 0 deletions test/e2e/quadlet/podspecifier.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## assert-podman-args "--pod" "systemd-podspecifier"
## assert-last-key-contains "Unit" "BindsTo" "podspecifier-pod.service"
## assert-last-key-contains "Unit" "After" "podspecifier-pod.service"

[Container]
Image=localhost/imagename
Pod=%N.pod
1 change: 1 addition & 0 deletions test/e2e/quadlet/podspecifier.pod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Pod]
8 changes: 8 additions & 0 deletions test/e2e/quadlet/podspecifier.servicename.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## assert-podman-args "--pod" "systemd-pod-specifier-svc"
## assert-last-key-contains "Unit" "BindsTo" "pod-specifier-svc-pod.service"
## assert-last-key-contains "Unit" "After" "pod-specifier-svc-pod.service"

[Container]
Image=localhost/imagename
ServiceName=pod-specifier-svc
Pod=%N.pod
2 changes: 2 additions & 0 deletions test/e2e/quadlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,8 @@ BOGUS=foo
Entry("Container - Mount overriding service name", "mount.servicename.container", []string{"service-name.volume"}),
Entry("Container - Quadlet Network overriding service name", "network.quadlet.servicename.container", []string{"service-name.network"}),
Entry("Container - Quadlet Volume overriding service name", "volume.servicename.container", []string{"service-name.volume"}),
Entry("Container - Pod with %N specifier", "podspecifier.container", []string{"podspecifier.pod"}),
Entry("Container - Pod with %N specifier and ServiceName", "podspecifier.servicename.container", []string{"pod-specifier-svc.pod"}),
Entry("Container - Quadlet build with multiple tags", "build.multiple-tags.container", []string{"multiple-tags.build"}),
Entry("Container - Artifact Mount", "artifact-mount.container", []string{"basic.artifact"}),
Entry("Container - Reuse another container's network", "network.reuse.container", []string{"basic.container"}),
Expand Down
Loading