Skip to content

Commit bc3b910

Browse files
Merge pull request #27340 from axel7083/feature/quadlet/kube-support-multiple-yaml
feat(quadlet: kube): support multiple Yaml entries
2 parents 998a8a0 + f957852 commit bc3b910

File tree

5 files changed

+44
-9
lines changed

5 files changed

+44
-9
lines changed

docs/source/markdown/podman-systemd.unit.5.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,9 @@ Alternatively, users can explicitly set the `WorkingDirectory` field of the `Ser
13921392
Please note that if the `WorkingDirectory` field of the `Service` group is set,
13931393
Quadlet will not set it even if `SetWorkingDirectory` is set
13941394

1395+
Special case:
1396+
* If multiple `Yaml` path are provided only `unit` is supported.
1397+
13951398
### `UserNS=`
13961399

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

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

1407+
This key can be listed multiple times.
1408+
14041409
## Network units [Network]
14051410

14061411
Network files are named with a `.network` extension and contain a section `[Network]` describing the

pkg/systemd/quadlet/quadlet.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,14 +1201,19 @@ func ConvertKube(kube *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, isUse
12011201
return nil, err
12021202
}
12031203

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

1209-
yamlPath, err = getAbsolutePath(kube, yamlPath)
1210-
if err != nil {
1211-
return nil, err
1209+
// Convert all yaml paths to absolute paths
1210+
absoluteYamlPaths := make([]string, 0, len(yamlPaths))
1211+
for _, yamlPath := range yamlPaths {
1212+
absPath, err := getAbsolutePath(kube, yamlPath)
1213+
if err != nil {
1214+
return nil, err
1215+
}
1216+
absoluteYamlPaths = append(absoluteYamlPaths, absPath)
12121217
}
12131218

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

12941299
handlePodmanArgs(kube, KubeGroup, execStart)
12951300

1296-
execStart.add(yamlPath)
1301+
// Add all YAML file paths to the command
1302+
execStart.add(absoluteYamlPaths...)
12971303

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

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

1310-
execStop.add(yamlPath)
1316+
// Add all YAML file paths to the stop command
1317+
execStop.add(absoluteYamlPaths...)
13111318
service.AddCmdline(ServiceGroup, "ExecStopPost", execStop.Args)
13121319

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

1991-
relativeToFile, ok = quadletUnitFile.Lookup(quadletGroup, KeyYaml)
1992-
if !ok {
1998+
yamlPaths := quadletUnitFile.LookupAllStrv(KubeGroup, KeyYaml)
1999+
if len(yamlPaths) == 0 {
19932000
return "", fmt.Errorf("no Yaml key specified")
2001+
} else if len(yamlPaths) != 1 {
2002+
return "", fmt.Errorf("SetWorkingDirectory=yaml is only supported when a single Yaml key is provided")
19942003
}
2004+
2005+
relativeToFile = yamlPaths[0]
19952006
case "file":
19962007
if quadletGroup != BuildGroup {
19972008
return "", fmt.Errorf("SetWorkingDirectory=%s is only supported in .build files", setWorkingDirectory)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## assert-failed
2+
## assert-stderr-contains "SetWorkingDirectory=yaml is only supported when a single Yaml key is provided"
3+
4+
[Kube]
5+
Yaml=foo.yml
6+
Yaml=bar.yml
7+
SetWorkingDirectory=yaml
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## assert-podman-args "kube"
2+
## assert-podman-args "play"
3+
## assert-podman-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/foo.yml .*/podman-e2e-.*/subtest-.*/quadlet/bar.yml
4+
## assert-podman-stop-post-args "kube"
5+
## assert-podman-stop-post-args "down"
6+
## assert-podman-stop-post-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/foo.yml .*/podman-e2e-.*/subtest-.*/quadlet/bar.yml
7+
8+
[Kube]
9+
Yaml=foo.yml
10+
Yaml=bar.yml

test/e2e/quadlet_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ BOGUS=foo
996996
Entry("Kube - Working Directory YAML Absolute Path", "workingdir-yaml-abs.kube"),
997997
Entry("Kube - Working Directory YAML Relative Path", "workingdir-yaml-rel.kube"),
998998
Entry("Kube - Working Directory Unit", "workingdir-unit.kube"),
999+
Entry("Kube - Multiple YAML entries", "multiple-yaml.kube"),
9991000
Entry("Kube - Working Directory already in Service", "workingdir-service.kube"),
10001001
Entry("Kube - global args", "globalargs.kube"),
10011002
Entry("Kube - Containers Conf Modules", "containersconfmodule.kube"),
@@ -1139,6 +1140,7 @@ BOGUS=foo
11391140
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"),
11401141

11411142
Entry("Kube - User Remap Manual", "remap-manual.kube", "converting \"remap-manual.kube\": RemapUsers=manual is not supported"),
1143+
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"),
11421144

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

0 commit comments

Comments
 (0)