Quadlet .pod - add support for the Network Key

Add e2e tests
Update documentation

Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
This commit is contained in:
Ygal Blum
2023-12-03 09:57:24 +02:00
parent 0d260bdc1f
commit 212b4c9e93
6 changed files with 31 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1,4 @@
## assert-podman-pre-args "--network=host"
[Pod]
Network=host

View File

@ -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

View File

@ -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, ""),
)