mirror of https://github.com/containers/podman.git
Merge pull request #16223 from vrothberg/quadlet
move quadlet packages into pkg/systemd
This commit is contained in:
commit
a301ec164c
|
@ -9,8 +9,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/podman/v4/pkg/quadlet"
|
"github.com/containers/podman/v4/pkg/systemd/parser"
|
||||||
"github.com/containers/podman/v4/pkg/systemdparser"
|
"github.com/containers/podman/v4/pkg/systemd/quadlet"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This commandline app is the systemd generator (system and user,
|
// This commandline app is the systemd generator (system and user,
|
||||||
|
@ -103,7 +103,7 @@ func getUnitDirs(user bool) []string {
|
||||||
return dirs
|
return dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadUnitsFromDir(sourcePath string, units map[string]*systemdparser.UnitFile) {
|
func loadUnitsFromDir(sourcePath string, units map[string]*parser.UnitFile) {
|
||||||
files, err := os.ReadDir(sourcePath)
|
files, err := os.ReadDir(sourcePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, os.ErrNotExist) {
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
|
@ -121,7 +121,7 @@ func loadUnitsFromDir(sourcePath string, units map[string]*systemdparser.UnitFil
|
||||||
|
|
||||||
Debugf("Loading source unit file %s", path)
|
Debugf("Loading source unit file %s", path)
|
||||||
|
|
||||||
if f, err := systemdparser.ParseUnitFile(path); err != nil {
|
if f, err := parser.ParseUnitFile(path); err != nil {
|
||||||
Logf("Error loading '%s', ignoring: %s", path, err)
|
Logf("Error loading '%s', ignoring: %s", path, err)
|
||||||
} else {
|
} else {
|
||||||
units[name] = f
|
units[name] = f
|
||||||
|
@ -130,7 +130,7 @@ func loadUnitsFromDir(sourcePath string, units map[string]*systemdparser.UnitFil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServiceFile(service *systemdparser.UnitFile) error {
|
func generateServiceFile(service *parser.UnitFile) error {
|
||||||
Debugf("writing '%s'", service.Path)
|
Debugf("writing '%s'", service.Path)
|
||||||
|
|
||||||
service.PrependComment("",
|
service.PrependComment("",
|
||||||
|
@ -161,7 +161,7 @@ func generateServiceFile(service *systemdparser.UnitFile) error {
|
||||||
// symlinks to get systemd to start the newly generated file as needed.
|
// symlinks to get systemd to start the newly generated file as needed.
|
||||||
// In a traditional setup this is done by "systemctl enable", but that doesn't
|
// In a traditional setup this is done by "systemctl enable", but that doesn't
|
||||||
// work for auto-generated files like these.
|
// work for auto-generated files like these.
|
||||||
func enableServiceFile(outputPath string, service *systemdparser.UnitFile) {
|
func enableServiceFile(outputPath string, service *parser.UnitFile) {
|
||||||
symlinks := make([]string, 0)
|
symlinks := make([]string, 0)
|
||||||
|
|
||||||
aliases := service.LookupAllStrv(quadlet.InstallGroup, "Alias")
|
aliases := service.LookupAllStrv(quadlet.InstallGroup, "Alias")
|
||||||
|
@ -230,7 +230,7 @@ func main() {
|
||||||
|
|
||||||
sourcePaths := getUnitDirs(isUser)
|
sourcePaths := getUnitDirs(isUser)
|
||||||
|
|
||||||
units := make(map[string]*systemdparser.UnitFile)
|
units := make(map[string]*parser.UnitFile)
|
||||||
for _, d := range sourcePaths {
|
for _, d := range sourcePaths {
|
||||||
loadUnitsFromDir(d, units)
|
loadUnitsFromDir(d, units)
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, unit := range units {
|
for name, unit := range units {
|
||||||
var service *systemdparser.UnitFile
|
var service *parser.UnitFile
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package systemdparser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package systemdparser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package systemdparser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/containers/podman/v4/pkg/systemdparser"
|
"github.com/containers/podman/v4/pkg/systemd/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Overwritten at build time:
|
// Overwritten at build time:
|
||||||
|
@ -152,7 +152,7 @@ func isPortRange(port string) bool {
|
||||||
return validPortRange.MatchString(port)
|
return validPortRange.MatchString(port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkForUnknownKeys(unit *systemdparser.UnitFile, groupName string, supportedKeys map[string]bool) error {
|
func checkForUnknownKeys(unit *parser.UnitFile, groupName string, supportedKeys map[string]bool) error {
|
||||||
keys := unit.ListKeys(groupName)
|
keys := unit.ListKeys(groupName)
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
if !supportedKeys[key] {
|
if !supportedKeys[key] {
|
||||||
|
@ -162,7 +162,7 @@ func checkForUnknownKeys(unit *systemdparser.UnitFile, groupName string, support
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupRanges(unit *systemdparser.UnitFile, groupName string, key string, nameLookup func(string) *Ranges, defaultValue *Ranges) *Ranges {
|
func lookupRanges(unit *parser.UnitFile, groupName string, key string, nameLookup func(string) *Ranges, defaultValue *Ranges) *Ranges {
|
||||||
v, ok := unit.Lookup(groupName, key)
|
v, ok := unit.Lookup(groupName, key)
|
||||||
if !ok {
|
if !ok {
|
||||||
if defaultValue != nil {
|
if defaultValue != nil {
|
||||||
|
@ -277,7 +277,7 @@ func addIDMaps(podman *PodmanCmdline, argPrefix string, containerID, hostID, rem
|
||||||
// service file (unit file with Service group) based on the options in the
|
// service file (unit file with Service group) based on the options in the
|
||||||
// Container group.
|
// Container group.
|
||||||
// The original Container group is kept around as X-Container.
|
// The original Container group is kept around as X-Container.
|
||||||
func ConvertContainer(container *systemdparser.UnitFile, isUser bool) (*systemdparser.UnitFile, error) {
|
func ConvertContainer(container *parser.UnitFile, isUser bool) (*parser.UnitFile, error) {
|
||||||
service := container.Dup()
|
service := container.Dup()
|
||||||
service.Filename = replaceExtension(container.Filename, ".service", "", "")
|
service.Filename = replaceExtension(container.Filename, ".service", "", "")
|
||||||
|
|
||||||
|
@ -643,7 +643,7 @@ func ConvertContainer(container *systemdparser.UnitFile, isUser bool) (*systemdp
|
||||||
// service file (unit file with Service group) based on the options in the
|
// service file (unit file with Service group) based on the options in the
|
||||||
// Volume group.
|
// Volume group.
|
||||||
// The original Container group is kept around as X-Container.
|
// The original Container group is kept around as X-Container.
|
||||||
func ConvertVolume(volume *systemdparser.UnitFile, name string) (*systemdparser.UnitFile, error) {
|
func ConvertVolume(volume *parser.UnitFile, name string) (*parser.UnitFile, error) {
|
||||||
service := volume.Dup()
|
service := volume.Dup()
|
||||||
service.Filename = replaceExtension(volume.Filename, ".service", "", "-volume")
|
service.Filename = replaceExtension(volume.Filename, ".service", "", "-volume")
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/podman/v4/pkg/systemdparser"
|
"github.com/containers/podman/v4/pkg/systemd/parser"
|
||||||
"github.com/mattn/go-shellwords"
|
"github.com/mattn/go-shellwords"
|
||||||
|
|
||||||
. "github.com/containers/podman/v4/test/utils"
|
. "github.com/containers/podman/v4/test/utils"
|
||||||
|
@ -83,7 +83,7 @@ func (t *quadletTestcase) assertStdErrContains(args []string, session *PodmanSes
|
||||||
return strings.Contains(session.OutputToString(), args[0])
|
return strings.Contains(session.OutputToString(), args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *quadletTestcase) assertKeyIs(args []string, unit *systemdparser.UnitFile) bool {
|
func (t *quadletTestcase) assertKeyIs(args []string, unit *parser.UnitFile) bool {
|
||||||
group := args[0]
|
group := args[0]
|
||||||
key := args[1]
|
key := args[1]
|
||||||
values := args[2:]
|
values := args[2:]
|
||||||
|
@ -101,7 +101,7 @@ func (t *quadletTestcase) assertKeyIs(args []string, unit *systemdparser.UnitFil
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *quadletTestcase) assertKeyContains(args []string, unit *systemdparser.UnitFile) bool {
|
func (t *quadletTestcase) assertKeyContains(args []string, unit *parser.UnitFile) bool {
|
||||||
group := args[0]
|
group := args[0]
|
||||||
key := args[1]
|
key := args[1]
|
||||||
value := args[2]
|
value := args[2]
|
||||||
|
@ -110,12 +110,12 @@ func (t *quadletTestcase) assertKeyContains(args []string, unit *systemdparser.U
|
||||||
return ok && strings.Contains(realValue, value)
|
return ok && strings.Contains(realValue, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *quadletTestcase) assertPodmanArgs(args []string, unit *systemdparser.UnitFile) bool {
|
func (t *quadletTestcase) assertPodmanArgs(args []string, unit *parser.UnitFile) bool {
|
||||||
podmanArgs, _ := unit.LookupLastArgs("Service", "ExecStart")
|
podmanArgs, _ := unit.LookupLastArgs("Service", "ExecStart")
|
||||||
return findSublist(podmanArgs, args) != -1
|
return findSublist(podmanArgs, args) != -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *quadletTestcase) assertFinalArgs(args []string, unit *systemdparser.UnitFile) bool {
|
func (t *quadletTestcase) assertFinalArgs(args []string, unit *parser.UnitFile) bool {
|
||||||
podmanArgs, _ := unit.LookupLastArgs("Service", "ExecStart")
|
podmanArgs, _ := unit.LookupLastArgs("Service", "ExecStart")
|
||||||
if len(podmanArgs) < len(args) {
|
if len(podmanArgs) < len(args) {
|
||||||
return false
|
return false
|
||||||
|
@ -123,7 +123,7 @@ func (t *quadletTestcase) assertFinalArgs(args []string, unit *systemdparser.Uni
|
||||||
return matchSublistAt(podmanArgs, len(podmanArgs)-len(args), args)
|
return matchSublistAt(podmanArgs, len(podmanArgs)-len(args), args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *quadletTestcase) assertSymlink(args []string, unit *systemdparser.UnitFile) bool {
|
func (t *quadletTestcase) assertSymlink(args []string, unit *parser.UnitFile) bool {
|
||||||
symlink := args[0]
|
symlink := args[0]
|
||||||
expectedTarget := args[1]
|
expectedTarget := args[1]
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ func (t *quadletTestcase) assertSymlink(args []string, unit *systemdparser.UnitF
|
||||||
return expectedTarget == target
|
return expectedTarget == target
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *quadletTestcase) doAssert(check []string, unit *systemdparser.UnitFile, session *PodmanSessionIntegration) error {
|
func (t *quadletTestcase) doAssert(check []string, unit *parser.UnitFile, session *PodmanSessionIntegration) error {
|
||||||
op := check[0]
|
op := check[0]
|
||||||
args := make([]string, 0)
|
args := make([]string, 0)
|
||||||
for _, a := range check[1:] {
|
for _, a := range check[1:] {
|
||||||
|
@ -193,7 +193,7 @@ func (t *quadletTestcase) check(generateDir string, session *PodmanSessionIntegr
|
||||||
return // Successful fail
|
return // Successful fail
|
||||||
}
|
}
|
||||||
|
|
||||||
unit, err := systemdparser.ParseUnitFile(file)
|
unit, err := parser.ParseUnitFile(file)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
for _, check := range t.checks {
|
for _, check := range t.checks {
|
||||||
|
|
Loading…
Reference in New Issue