Skip to content

Commit b97be34

Browse files
committed
quadlet: support HostName
Add a new `HostName` field to Quadlet `.container` files. Fixes: #18486 Signed-off-by: Valentin Rothberg <[email protected]>
1 parent edcb29b commit b97be34

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Valid options for `[Container]` are listed below:
109109
| HealthStartupSuccess=2 | --health-startup-success=2 |
110110
| HealthStartupTimeout=1m33s | --health-startup-timeout=1m33s |
111111
| HealthTimeout=20s | --health-timeout=20s |
112+
| HostName=new-host-name | --hostname="new-host-name" |
112113
| Image=ubi8 | Image specification - ubi8 |
113114
| IP=192.5.0.1 | --ip 192.5.0.0 |
114115
| IP6=fd46:db93:aa76:ac37::10 | --ip6 2001:db8::1 |
@@ -276,6 +277,11 @@ Equivalent to the Podman `--health-startup-timeout` option.
276277
The maximum time allowed to complete the healthcheck before an interval is considered failed.
277278
Equivalent to the Podman `--health-timeout` option.
278279

280+
### `HostName=`
281+
282+
Sets the host name that is available inside the container.
283+
Equivalent to the Podman `--hostname` option.
284+
279285
### `Image=`
280286

281287
The image to run in the container. This image must be locally installed for the service to work

pkg/systemd/quadlet/quadlet.go

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const (
5858
KeyHealthStartupSuccess = "HealthStartupSuccess"
5959
KeyHealthStartupTimeout = "HealthStartupTimeout"
6060
KeyHealthTimeout = "HealthTimeout"
61+
KeyHostName = "HostName"
6162
KeyImage = "Image"
6263
KeyIP = "IP"
6364
KeyIP6 = "IP6"
@@ -129,6 +130,7 @@ var (
129130
KeyHealthStartupSuccess: true,
130131
KeyHealthStartupTimeout: true,
131132
KeyHealthTimeout: true,
133+
KeyHostName: true,
132134
KeyImage: true,
133135
KeyIP: true,
134136
KeyIP6: true,
@@ -614,6 +616,10 @@ func ConvertContainer(container *parser.UnitFile, isUser bool) (*parser.UnitFile
614616

615617
handleHealth(container, ContainerGroup, podman)
616618

619+
if hostname, ok := container.Lookup(ContainerGroup, KeyHostName); ok {
620+
podman.add("--hostname", hostname)
621+
}
622+
617623
podmanArgs := container.LookupAllArgs(ContainerGroup, KeyPodmanArgs)
618624
podman.add(podmanArgs...)
619625

test/e2e/quadlet/hostname.container

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[Container]
2+
Image=localhost/imagename
3+
## assert-podman-args "--hostname" "\"quadlet-host\""
4+
HostName="quadlet-host"

test/e2e/quadlet_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ var _ = Describe("quadlet system generator", func() {
575575
Entry("logdriver.container", "logdriver.container"),
576576
Entry("mount.container", "mount.container"),
577577
Entry("health.container", "health.container"),
578+
Entry("hostname.container", "hostname.container"),
578579

579580
Entry("basic.volume", "basic.volume"),
580581
Entry("label.volume", "label.volume"),

0 commit comments

Comments
 (0)