Skip to content

Commit

Permalink
Merge pull request #23427 from ygalblum/quadlet-pod-service-name
Browse files Browse the repository at this point in the history
Allow setting the service name of Quadlet .pod units
  • Loading branch information
openshift-merge-bot[bot] authored Jul 30, 2024
2 parents ae5d970 + f3a8626 commit b4d0c95
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 232 deletions.
9 changes: 9 additions & 0 deletions docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ Valid options for `[Pod]` are listed below:
| PodmanArgs=\-\-cpus=2 | --cpus=2 |
| PodName=name | --name=name |
| PublishPort=50-59 | --publish 50-59 |
| ServiceName=name | Name the systemd unit `name.service` |
| Volume=/source:/dest | --volume /source:/dest |

Supported keys in the `[Pod]` section are:
Expand Down Expand Up @@ -947,6 +948,14 @@ When using `host` networking via `Network=host`, the `PublishPort=` option canno

This key can be listed multiple times.


### `ServiceName=`

By default, Quadlet will name the systemd service unit by appending `-pod` to the name of the Quadlet.
Setting this key overrides this behavior by instructing Quadlet to use the provided name.

Note, the name should not include the `.service` file extension

### `Volume=`

Mount a volume in the pod. This is equivalent to the Podman `--volume` option, and
Expand Down
5 changes: 5 additions & 0 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const (
KeySecurityLabelLevel = "SecurityLabelLevel"
KeySecurityLabelNested = "SecurityLabelNested"
KeySecurityLabelType = "SecurityLabelType"
KeyServiceName = "ServiceName"
KeySetWorkingDirectory = "SetWorkingDirectory"
KeyShmSize = "ShmSize"
KeyStopSignal = "StopSignal"
Expand Down Expand Up @@ -373,6 +374,7 @@ var (
KeyPodName: true,
KeyPodmanArgs: true,
KeyPublishPort: true,
KeyServiceName: true,
KeyVolume: true,
}
)
Expand Down Expand Up @@ -1474,6 +1476,9 @@ func GetBuiltImageName(buildUnit *parser.UnitFile) string {
}

func GetPodServiceName(podUnit *parser.UnitFile) string {
if serviceName, ok := podUnit.Lookup(PodGroup, KeyServiceName); ok {
return serviceName
}
return replaceExtension(podUnit.Filename, "", "", "-pod")
}

Expand Down
5 changes: 5 additions & 0 deletions test/e2e/quadlet/service-name.pod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## assert-podman-pre-args "--name=test-pod"

[Pod]
PodName=test-pod
ServiceName=test-pod
Loading

0 comments on commit b4d0c95

Please sign in to comment.