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:
Ygal Blum
2022-12-05 14:24:06 +02:00
parent b26d4fc36a
commit a55413c802
5 changed files with 68 additions and 15 deletions

View File

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