diff --git a/cmd/quadlet/main.go b/cmd/quadlet/main.go index e2b021b669..457b3f0a4e 100644 --- a/cmd/quadlet/main.go +++ b/cmd/quadlet/main.go @@ -589,7 +589,7 @@ func process() error { warnIfAmbiguousName(unit, quadlet.ImageGroup) service, name, err = quadlet.ConvertImage(unit) case strings.HasSuffix(unit.Filename, ".pod"): - service, err = quadlet.ConvertPod(unit, unit.Filename, podsInfoMap) + service, err = quadlet.ConvertPod(unit, unit.Filename, podsInfoMap, resourceNames) default: Logf("Unsupported file type %q", unit.Filename) continue diff --git a/docs/source/markdown/podman-systemd.unit.5.md b/docs/source/markdown/podman-systemd.unit.5.md index 49282bbb6f..fd11811e31 100644 --- a/docs/source/markdown/podman-systemd.unit.5.md +++ b/docs/source/markdown/podman-systemd.unit.5.md @@ -694,6 +694,7 @@ Valid options for `[Container]` are listed below: |-------------------------------------|----------------------------------------| | ContainersConfModule=/etc/nvd\.conf | --module=/etc/nvd\.conf | | GlobalArgs=--log-level=debug | --log-level=debug | +| Network=host | --network host | | PodmanArgs=\-\-cpus=2 | --cpus=2 | | PodName=name | --name=name | @@ -718,6 +719,19 @@ escaped to allow inclusion of whitespace and other control characters. This key can be listed multiple times. +### `Network=` + +Specify a custom network for the pod. +This has the same format as the `--network` option to `podman pod create`. +For example, use `host` to use the host network in the pod, or `none` to not set up networking in the pod. + +As a special case, if the `name` of the network ends with `.network`, Quadlet will look for the corresponding `.network` Quadlet unit. +If found, Quadlet will use the name of the Network set in the Unit, otherwise, `systemd-$name` is used. +The generated systemd service contains a dependency on the service unit generated for that `.network` unit, +or on `$name-network.service` if the `.network` unit is not found + +This key can be listed multiple times. + ### `PodmanArgs=` This key contains a list of arguments passed directly to the end of the `podman kube play` command diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index eeb40bc747..74d1c33c74 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -321,6 +321,7 @@ var ( supportedPodKeys = map[string]bool{ KeyContainersConfModule: true, KeyGlobalArgs: true, + KeyNetwork: true, KeyPodmanArgs: true, KeyPodName: true, } @@ -1253,7 +1254,7 @@ func GetPodServiceName(podUnit *parser.UnitFile) string { return replaceExtension(podUnit.Filename, "", "", "-pod") } -func ConvertPod(podUnit *parser.UnitFile, name string, podsInfoMap map[string]*PodInfo) (*parser.UnitFile, error) { +func ConvertPod(podUnit *parser.UnitFile, name string, podsInfoMap map[string]*PodInfo, names map[string]string) (*parser.UnitFile, error) { podInfo, ok := podsInfoMap[podUnit.Filename] if !ok { return nil, fmt.Errorf("internal error while processing pod %s", podUnit.Filename) @@ -1322,6 +1323,8 @@ func ConvertPod(podUnit *parser.UnitFile, name string, podsInfoMap map[string]*P "--replace", ) + addNetworks(podUnit, PodGroup, service, names, execStartPre) + execStartPre.addf("--name=%s", podName) handlePodmanArgs(podUnit, PodGroup, execStartPre) diff --git a/test/e2e/quadlet/network.pod b/test/e2e/quadlet/network.pod new file mode 100644 index 0000000000..edc89fcacf --- /dev/null +++ b/test/e2e/quadlet/network.pod @@ -0,0 +1,4 @@ +## assert-podman-pre-args "--network=host" + +[Pod] +Network=host diff --git a/test/e2e/quadlet/network.quadlet.pod b/test/e2e/quadlet/network.quadlet.pod new file mode 100644 index 0000000000..4c2b0bf7d6 --- /dev/null +++ b/test/e2e/quadlet/network.quadlet.pod @@ -0,0 +1,6 @@ +## assert-podman-pre-args "--network=systemd-basic" +## assert-key-is "Unit" "Requires" "basic-network.service" +## assert-key-is "Unit" "After" "basic-network.service" + +[Pod] +Network=basic.network diff --git a/test/e2e/quadlet_test.go b/test/e2e/quadlet_test.go index b887e5cf97..ee71cd6231 100644 --- a/test/e2e/quadlet_test.go +++ b/test/e2e/quadlet_test.go @@ -901,6 +901,8 @@ BOGUS=foo Entry("basic.pod", "basic.pod", 0, ""), Entry("name.pod", "name.pod", 0, ""), + Entry("network.pod", "network.pod", 0, ""), + Entry("network-quadlet.pod", "network.quadlet.pod", 0, ""), Entry("podmanargs.pod", "podmanargs.pod", 0, ""), )