mirror of https://github.com/containers/podman.git
Quadlet Kube: Add support for relative path for YAML file
If the provided path is relative, turn path to absolute Add regex verification option in tests Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
This commit is contained in:
parent
b26d4fc36a
commit
a55413c802
|
@ -2,6 +2,7 @@ package quadlet
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
|
@ -617,6 +618,18 @@ func ConvertKube(kube *parser.UnitFile) (*parser.UnitFile, error) {
|
|||
return nil, fmt.Errorf("no Yaml key specified")
|
||||
}
|
||||
|
||||
if !filepath.IsAbs(yamlPath) {
|
||||
if len(kube.Path) > 0 {
|
||||
yamlPath = filepath.Join(filepath.Dir(kube.Path), yamlPath)
|
||||
} else {
|
||||
var err error
|
||||
yamlPath, err = filepath.Abs(yamlPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only allow mixed or control-group, as nothing else works well
|
||||
killMode, ok := service.Lookup(ServiceGroup, "KillMode")
|
||||
if !ok || !(killMode == "mixed" || killMode == "control-group") {
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
## assert-podman-args "kube"
|
||||
## assert-podman-args "play"
|
||||
## assert-podman-final-args /opt/k8s/deployment.yml
|
||||
## assert-podman-args "--replace"
|
||||
## assert-podman-args "--service-container=true"
|
||||
## assert-podman-stop-args "kube"
|
||||
## assert-podman-stop-args "down"
|
||||
## assert-podman-stop-final-args /opt/k8s/deployment.yml
|
||||
## assert-key-is "Unit" "RequiresMountsFor" "%t/containers"
|
||||
## assert-key-is "Service" "KillMode" "mixed"
|
||||
## assert-key-is "Service" "Type" "notify"
|
||||
## assert-key-is "Service" "NotifyAccess" "all"
|
||||
## assert-key-is "Service" "Environment" "PODMAN_SYSTEMD_UNIT=%n"
|
||||
|
||||
|
||||
[Kube]
|
||||
Yaml=/opt/k8s/deployment.yml
|
|
@ -1,11 +1,11 @@
|
|||
## assert-podman-args "kube"
|
||||
## assert-podman-args "play"
|
||||
## assert-podman-final-args deployment.yml
|
||||
## assert-podman-final-args-regex /tmp/podman_test.*/quadlet/deployment.yml
|
||||
## assert-podman-args "--replace"
|
||||
## assert-podman-args "--service-container=true"
|
||||
## assert-podman-stop-args "kube"
|
||||
## assert-podman-stop-args "down"
|
||||
## assert-podman-stop-final-args deployment.yml
|
||||
## assert-podman-stop-final-args-regex /tmp/podman_test.*/quadlet/deployment.yml
|
||||
## assert-key-is "Unit" "RequiresMountsFor" "%t/containers"
|
||||
## assert-key-is "Service" "KillMode" "mixed"
|
||||
## assert-key-is "Service" "Type" "notify"
|
||||
|
|
|
@ -1,16 +1,3 @@
|
|||
## assert-podman-args "kube"
|
||||
## assert-podman-args "play"
|
||||
## assert-podman-final-args deployment.yml
|
||||
## assert-podman-args "--replace"
|
||||
## assert-podman-args "--service-container=true"
|
||||
## assert-podman-stop-args "kube"
|
||||
## assert-podman-stop-args "down"
|
||||
## assert-podman-stop-final-args deployment.yml
|
||||
## assert-key-is "Unit" "RequiresMountsFor" "%t/containers"
|
||||
## assert-key-is "Service" "KillMode" "mixed"
|
||||
## assert-key-is "Service" "Type" "notify"
|
||||
## assert-key-is "Service" "NotifyAccess" "all"
|
||||
## assert-key-is "Service" "Environment" "PODMAN_SYSTEMD_UNIT=%n"
|
||||
## assert-key-is "Service" "SyslogIdentifier" "mytest"
|
||||
|
||||
[Service]
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/podman/v4/pkg/systemd/parser"
|
||||
|
@ -64,6 +65,20 @@ func matchSublistAt(full []string, pos int, sublist []string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func matchSublistRegexAt(full []string, pos int, sublist []string) bool {
|
||||
if len(sublist) > len(full)-pos {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := range sublist {
|
||||
matched, err := regexp.MatchString(sublist[i], full[pos+i])
|
||||
if err != nil || !matched {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func findSublist(full []string, sublist []string) int {
|
||||
if len(sublist) > len(full) {
|
||||
return -1
|
||||
|
@ -123,6 +138,14 @@ func (t *quadletTestcase) assertPodmanFinalArgs(args []string, unit *parser.Unit
|
|||
return matchSublistAt(podmanArgs, len(podmanArgs)-len(args), args)
|
||||
}
|
||||
|
||||
func (t *quadletTestcase) assertPodmanFinalArgsRegex(args []string, unit *parser.UnitFile, key string) bool {
|
||||
podmanArgs, _ := unit.LookupLastArgs("Service", key)
|
||||
if len(podmanArgs) < len(args) {
|
||||
return false
|
||||
}
|
||||
return matchSublistRegexAt(podmanArgs, len(podmanArgs)-len(args), args)
|
||||
}
|
||||
|
||||
func (t *quadletTestcase) assertStartPodmanArgs(args []string, unit *parser.UnitFile) bool {
|
||||
return t.assertPodmanArgs(args, unit, "ExecStart")
|
||||
}
|
||||
|
@ -131,6 +154,10 @@ func (t *quadletTestcase) assertStartPodmanFinalArgs(args []string, unit *parser
|
|||
return t.assertPodmanFinalArgs(args, unit, "ExecStart")
|
||||
}
|
||||
|
||||
func (t *quadletTestcase) assertStartPodmanFinalArgsRegex(args []string, unit *parser.UnitFile) bool {
|
||||
return t.assertPodmanFinalArgsRegex(args, unit, "ExecStart")
|
||||
}
|
||||
|
||||
func (t *quadletTestcase) assertStopPodmanArgs(args []string, unit *parser.UnitFile) bool {
|
||||
return t.assertPodmanArgs(args, unit, "ExecStop")
|
||||
}
|
||||
|
@ -139,6 +166,10 @@ func (t *quadletTestcase) assertStopPodmanFinalArgs(args []string, unit *parser.
|
|||
return t.assertPodmanFinalArgs(args, unit, "ExecStop")
|
||||
}
|
||||
|
||||
func (t *quadletTestcase) assertStopPodmanFinalArgsRegex(args []string, unit *parser.UnitFile) bool {
|
||||
return t.assertPodmanFinalArgsRegex(args, unit, "ExecStop")
|
||||
}
|
||||
|
||||
func (t *quadletTestcase) assertSymlink(args []string, unit *parser.UnitFile) bool {
|
||||
symlink := args[0]
|
||||
expectedTarget := args[1]
|
||||
|
@ -180,12 +211,16 @@ func (t *quadletTestcase) doAssert(check []string, unit *parser.UnitFile, sessio
|
|||
ok = t.assertStartPodmanArgs(args, unit)
|
||||
case "assert-podman-final-args":
|
||||
ok = t.assertStartPodmanFinalArgs(args, unit)
|
||||
case "assert-podman-final-args-regex":
|
||||
ok = t.assertStartPodmanFinalArgsRegex(args, unit)
|
||||
case "assert-symlink":
|
||||
ok = t.assertSymlink(args, unit)
|
||||
case "assert-podman-stop-args":
|
||||
ok = t.assertStopPodmanArgs(args, unit)
|
||||
case "assert-podman-stop-final-args":
|
||||
ok = t.assertStopPodmanFinalArgs(args, unit)
|
||||
case "assert-podman-stop-final-args-regex":
|
||||
ok = t.assertStopPodmanFinalArgsRegex(args, unit)
|
||||
default:
|
||||
return fmt.Errorf("Unsupported assertion %s", op)
|
||||
}
|
||||
|
@ -323,6 +358,7 @@ var _ = Describe("quadlet system generator", func() {
|
|||
|
||||
Entry("Basic kube", "basic.kube"),
|
||||
Entry("Syslog Identifier", "syslog.identifier.kube"),
|
||||
Entry("Absolute Path", "absolute.path.kube"),
|
||||
)
|
||||
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue