Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,9 @@ Alternatively, users can explicitly set the `WorkingDirectory` field of the `Ser
Please note that if the `WorkingDirectory` field of the `Service` group is set,
Quadlet will not set it even if `SetWorkingDirectory` is set

Special case:
* If multiple `Yaml` path are provided only `unit` is supported.

### `UserNS=`

Set the user namespace mode for the container. This is equivalent to the Podman `--userns` option and
Expand All @@ -1401,6 +1404,8 @@ generally has the form `MODE[:OPTIONS,...]`.

The path, absolute or relative to the location of the unit file, to the Kubernetes YAML file to use.

This key can be listed multiple times.

## Network units [Network]

Network files are named with a `.network` extension and contain a section `[Network]` describing the
Expand Down
29 changes: 20 additions & 9 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1201,14 +1201,19 @@ func ConvertKube(kube *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, isUse
return nil, err
}

yamlPath, ok := kube.Lookup(KubeGroup, KeyYaml)
if !ok || len(yamlPath) == 0 {
yamlPaths := kube.LookupAllStrv(KubeGroup, KeyYaml)
if len(yamlPaths) == 0 {
return nil, fmt.Errorf("no Yaml key specified")
}

yamlPath, err = getAbsolutePath(kube, yamlPath)
if err != nil {
return nil, err
// Convert all yaml paths to absolute paths
absoluteYamlPaths := make([]string, 0, len(yamlPaths))
for _, yamlPath := range yamlPaths {
absPath, err := getAbsolutePath(kube, yamlPath)
if err != nil {
return nil, err
}
absoluteYamlPaths = append(absoluteYamlPaths, absPath)
}

// Only allow mixed or control-group, as nothing else works well
Expand Down Expand Up @@ -1293,7 +1298,8 @@ func ConvertKube(kube *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, isUse

handlePodmanArgs(kube, KubeGroup, execStart)

execStart.add(yamlPath)
// Add all YAML file paths to the command
execStart.add(absoluteYamlPaths...)

service.AddCmdline(ServiceGroup, "ExecStart", execStart.Args)

Expand All @@ -1307,7 +1313,8 @@ func ConvertKube(kube *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, isUse
execStop.addBool("--force", kubeDownForce)
}

execStop.add(yamlPath)
// Add all YAML file paths to the stop command
execStop.add(absoluteYamlPaths...)
service.AddCmdline(ServiceGroup, "ExecStopPost", execStop.Args)

_, err = handleSetWorkingDirectory(kube, service, KubeGroup)
Expand Down Expand Up @@ -1988,10 +1995,14 @@ func handleSetWorkingDirectory(quadletUnitFile, serviceUnitFile *parser.UnitFile
return "", fmt.Errorf("SetWorkingDirectory=%s is only supported in .kube files", setWorkingDirectory)
}

relativeToFile, ok = quadletUnitFile.Lookup(quadletGroup, KeyYaml)
if !ok {
yamlPaths := quadletUnitFile.LookupAllStrv(KubeGroup, KeyYaml)
if len(yamlPaths) == 0 {
return "", fmt.Errorf("no Yaml key specified")
} else if len(yamlPaths) != 1 {
return "", fmt.Errorf("SetWorkingDirectory=yaml is only supported when a single Yaml key is provided")
}

relativeToFile = yamlPaths[0]
case "file":
if quadletGroup != BuildGroup {
return "", fmt.Errorf("SetWorkingDirectory=%s is only supported in .build files", setWorkingDirectory)
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/quadlet/multiple-yaml-set-working-dir-yaml.kube
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## assert-failed
## assert-stderr-contains "SetWorkingDirectory=yaml is only supported when a single Yaml key is provided"

[Kube]
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is missing:

## assert-failed
## assert-stderr-contains <The expected error message>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I was kinda lost 😿 !

Yaml=foo.yml
Yaml=bar.yml
SetWorkingDirectory=yaml
10 changes: 10 additions & 0 deletions test/e2e/quadlet/multiple-yaml.kube
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## assert-podman-args "kube"
## assert-podman-args "play"
## assert-podman-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/foo.yml .*/podman-e2e-.*/subtest-.*/quadlet/bar.yml
## assert-podman-stop-post-args "kube"
## assert-podman-stop-post-args "down"
## assert-podman-stop-post-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/foo.yml .*/podman-e2e-.*/subtest-.*/quadlet/bar.yml

[Kube]
Yaml=foo.yml
Yaml=bar.yml
2 changes: 2 additions & 0 deletions test/e2e/quadlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ BOGUS=foo
Entry("Kube - Working Directory YAML Absolute Path", "workingdir-yaml-abs.kube"),
Entry("Kube - Working Directory YAML Relative Path", "workingdir-yaml-rel.kube"),
Entry("Kube - Working Directory Unit", "workingdir-unit.kube"),
Entry("Kube - Multiple YAML entries", "multiple-yaml.kube"),
Entry("Kube - Working Directory already in Service", "workingdir-service.kube"),
Entry("Kube - global args", "globalargs.kube"),
Entry("Kube - Containers Conf Modules", "containersconfmodule.kube"),
Expand Down Expand Up @@ -1139,6 +1140,7 @@ BOGUS=foo
Entry("Volume - Quadlet image (.image) not found", "image-not-found.quadlet.volume", "converting \"image-not-found.quadlet.volume\": requested Quadlet image not-found.image was not found"),

Entry("Kube - User Remap Manual", "remap-manual.kube", "converting \"remap-manual.kube\": RemapUsers=manual is not supported"),
Entry("Kube - Multiple Yaml and SetWorkingDir=yaml", "multiple-yaml-set-working-dir-yaml.kube", "converting \"multiple-yaml-set-working-dir-yaml.kube\": SetWorkingDirectory=yaml is only supported when a single Yaml key is provided"),

Entry("Network - Gateway not enough Subnet", "gateway.less-subnet.network", "converting \"gateway.less-subnet.network\": cannot set more gateways than subnets"),
Entry("Network - Gateway without Subnet", "gateway.no-subnet.network", "converting \"gateway.no-subnet.network\": cannot set gateway or range without subnet"),
Expand Down