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

Quadlet - add support for keys that may refer to other Quadlet units in .pod files #20887

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion cmd/quadlet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ var (
supportedPodKeys = map[string]bool{
KeyContainersConfModule: true,
KeyGlobalArgs: true,
KeyNetwork: true,
KeyPodmanArgs: true,
KeyPodName: true,
}
Expand Down Expand Up @@ -1253,14 +1254,14 @@ 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) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you change the variable name to networkNames?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's incorrect. The map is called names (here and in other methods) because it hold a mapping between Quadlet unit files and the name of the entity they create (Netowork, Volume or Image). You can see that the same map is passed on to both addNetworks and addVolumes

podInfo, ok := podsInfoMap[podUnit.Filename]
if !ok {
return nil, fmt.Errorf("internal error while processing pod %s", podUnit.Filename)
}

service := podUnit.Dup()
service.Filename = replaceExtension(podInfo.ServiceName, ".service", "", "")
service.Filename = fmt.Sprintf("%s.service", podInfo.ServiceName)

if podUnit.Path != "" {
service.Add(UnitGroup, "SourcePath", podUnit.Path)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/quadlet/network.pod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## assert-podman-pre-args "--network=host"

[Pod]
Network=host
6 changes: 6 additions & 0 deletions test/e2e/quadlet/network.quadlet.pod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/e2e/quadlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""),
)

Expand Down