quadlet: Add support for Network=...

This just gets translated to --network=...

Signed-off-by: Alexander Larsson <alexl@redhat.com>
This commit is contained in:
Alexander Larsson
2022-10-20 12:51:27 +02:00
parent 721922fa7e
commit 8716de2ac3
4 changed files with 19 additions and 0 deletions

View File

@ -234,6 +234,12 @@ created by using a `$name.volume` quadlet file.
This key can be listed multiple times.
#### `Network=`
Specify a custom network for the container. This has the same format as the `--network` option
to `podman run`. For example, use `host` to use the host network in the container, or `none` to
not set up networking in the container.
#### `ExposeHostPort=`
Exposes a port, or a range of ports (e.g. `50-59`), from the host to the container. Equivalent

View File

@ -72,6 +72,7 @@ const (
KeyTimezone = "Timezone"
KeySeccompProfile = "SeccompProfile"
KeyAddDevice = "AddDevice"
KeyNetwork = "Network"
)
// Supported keys in "Container" group
@ -106,6 +107,7 @@ var supportedContainerKeys = map[string]bool{
KeyTimezone: true,
KeySeccompProfile: true,
KeyAddDevice: true,
KeyNetwork: true,
}
// Supported keys in "Volume" group
@ -371,6 +373,11 @@ func ConvertContainer(container *parser.UnitFile, isUser bool) (*parser.UnitFile
podman.addf("--tz=%s", timezone)
}
network, ok := container.Lookup(ContainerGroup, KeyNetwork)
if ok && len(network) > 0 {
podman.addf("--network=%s", network)
}
// Run with a pid1 init to reap zombies by default (as most apps don't do that)
runInit := container.LookupBoolean(ContainerGroup, KeyRunInit, true)
if runInit {

View File

@ -0,0 +1,5 @@
## assert-podman-args "--network=host"
[Container]
Image=localhost/imagename
Network=host

View File

@ -278,6 +278,7 @@ var _ = Describe("quadlet system generator", func() {
Entry("install.container", "install.container"),
Entry("label.container", "label.container"),
Entry("name.container", "name.container"),
Entry("network.container", "network.container"),
Entry("noimage.container", "noimage.container"),
Entry("noremapuser2.container", "noremapuser2.container"),
Entry("noremapuser.container", "noremapuser.container"),