Skip to content

Commit

Permalink
Merge pull request #16223 from vrothberg/quadlet
Browse files Browse the repository at this point in the history
move quadlet packages into pkg/systemd
  • Loading branch information
openshift-merge-robot authored Oct 19, 2022
2 parents 2936e60 + b4374f2 commit a301ec1
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions cmd/quadlet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"path/filepath"
"strings"

"github.com/containers/podman/v4/pkg/quadlet"
"github.com/containers/podman/v4/pkg/systemdparser"
"github.com/containers/podman/v4/pkg/systemd/parser"
"github.com/containers/podman/v4/pkg/systemd/quadlet"
)

// This commandline app is the systemd generator (system and user,
Expand Down Expand Up @@ -103,7 +103,7 @@ func getUnitDirs(user bool) []string {
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)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
Expand All @@ -121,7 +121,7 @@ func loadUnitsFromDir(sourcePath string, units map[string]*systemdparser.UnitFil

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)
} else {
units[name] = f
Expand All @@ -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)

service.PrependComment("",
Expand Down Expand Up @@ -161,7 +161,7 @@ func generateServiceFile(service *systemdparser.UnitFile) error {
// 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
// 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)

aliases := service.LookupAllStrv(quadlet.InstallGroup, "Alias")
Expand Down Expand Up @@ -230,7 +230,7 @@ func main() {

sourcePaths := getUnitDirs(isUser)

units := make(map[string]*systemdparser.UnitFile)
units := make(map[string]*parser.UnitFile)
for _, d := range sourcePaths {
loadUnitsFromDir(d, units)
}
Expand All @@ -242,7 +242,7 @@ func main() {
}

for name, unit := range units {
var service *systemdparser.UnitFile
var service *parser.UnitFile
var err error

switch {
Expand Down
2 changes: 1 addition & 1 deletion pkg/systemdparser/split.go → pkg/systemd/parser/split.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package systemdparser
package parser

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package systemdparser
package parser

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package systemdparser
package parser

import (
"testing"
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions pkg/quadlet/quadlet.go → pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"unicode"

"github.com/containers/podman/v4/pkg/systemdparser"
"github.com/containers/podman/v4/pkg/systemd/parser"
)

// Overwritten at build time:
Expand Down Expand Up @@ -152,7 +152,7 @@ func isPortRange(port string) bool {
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)
for _, key := range keys {
if !supportedKeys[key] {
Expand All @@ -162,7 +162,7 @@ func checkForUnknownKeys(unit *systemdparser.UnitFile, groupName string, support
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)
if !ok {
if defaultValue != nil {
Expand Down Expand Up @@ -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
// Container group.
// 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.Filename = replaceExtension(container.Filename, ".service", "", "")

Expand Down Expand Up @@ -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
// Volume group.
// 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.Filename = replaceExtension(volume.Filename, ".service", "", "-volume")

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions test/e2e/quadlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"

"github.com/containers/podman/v4/pkg/systemdparser"
"github.com/containers/podman/v4/pkg/systemd/parser"
"github.com/mattn/go-shellwords"

. "github.com/containers/podman/v4/test/utils"
Expand Down Expand Up @@ -83,7 +83,7 @@ func (t *quadletTestcase) assertStdErrContains(args []string, session *PodmanSes
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]
key := args[1]
values := args[2:]
Expand All @@ -101,7 +101,7 @@ func (t *quadletTestcase) assertKeyIs(args []string, unit *systemdparser.UnitFil
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]
key := args[1]
value := args[2]
Expand All @@ -110,20 +110,20 @@ func (t *quadletTestcase) assertKeyContains(args []string, unit *systemdparser.U
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")
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")
if len(podmanArgs) < len(args) {
return false
}
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]
expectedTarget := args[1]

Expand All @@ -135,7 +135,7 @@ func (t *quadletTestcase) assertSymlink(args []string, unit *systemdparser.UnitF
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]
args := make([]string, 0)
for _, a := range check[1:] {
Expand Down Expand Up @@ -193,7 +193,7 @@ func (t *quadletTestcase) check(generateDir string, session *PodmanSessionIntegr
return // Successful fail
}

unit, err := systemdparser.ParseUnitFile(file)
unit, err := parser.ParseUnitFile(file)
Expect(err).To(BeNil())

for _, check := range t.checks {
Expand Down

0 comments on commit a301ec1

Please sign in to comment.