Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting the service name of Quadlet .pod units #23427

Merged
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
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=`
Copy link
Member

Choose a reason for hiding this comment

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

I have nothing against setting a a specific service name but IMO this should not be added for just pods. This is totally inconsistent like that and if we do it then it should be done for all units IMO

Copy link
Contributor Author

@ygalblum ygalblum Jul 29, 2024

Choose a reason for hiding this comment

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

I thought about it as well. But then I thought:

  • The service for .container and .kube files keeps the name
  • Unit types .network, .volume, .image and .build are intended mostly for dependencies
  • .pod are the only ones that both the users interact with and the name is not kept.

Plus, making these change for other types is more complicated because it requires handling the order differently. Something along the line of what I already did for .pod files. So, this gives a quick response for the issue that was raised

Copy link
Member

Choose a reason for hiding this comment

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

I guess I am open to wait for user feedback on this, but generally I find doing this for one option inconsistent and I am pretty sure that someone will request this for other types as well.
(I do agree that kube and container units are fine without it as they do not append anything)


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