From b4374f2bd90a93334fff25631c645696466e95e2 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Wed, 19 Oct 2022 13:01:07 +0200 Subject: [PATCH] move quadlet packages into pkg/systemd Reduce the number of top-level packages in ./pkg by moving quadlet packages under ./pkg/systemd. [NO NEW TESTS NEEDED] - no functional change. Signed-off-by: Valentin Rothberg --- cmd/quadlet/main.go | 16 ++++++++-------- pkg/{systemdparser => systemd/parser}/split.go | 2 +- .../parser}/unitfile.go | 2 +- .../parser}/unitfile_test.go | 2 +- pkg/{ => systemd}/quadlet/podmancmdline.go | 0 pkg/{ => systemd}/quadlet/quadlet.go | 10 +++++----- pkg/{ => systemd}/quadlet/quadlet_test.go | 0 pkg/{ => systemd}/quadlet/ranges.go | 0 pkg/{ => systemd}/quadlet/ranges_test.go | 0 pkg/{ => systemd}/quadlet/subuids.go | 0 test/e2e/quadlet_test.go | 16 ++++++++-------- 11 files changed, 24 insertions(+), 24 deletions(-) rename pkg/{systemdparser => systemd/parser}/split.go (99%) rename pkg/{systemdparser => systemd/parser}/unitfile.go (99%) rename pkg/{systemdparser => systemd/parser}/unitfile_test.go (99%) rename pkg/{ => systemd}/quadlet/podmancmdline.go (100%) rename pkg/{ => systemd}/quadlet/quadlet.go (97%) rename pkg/{ => systemd}/quadlet/quadlet_test.go (100%) rename pkg/{ => systemd}/quadlet/ranges.go (100%) rename pkg/{ => systemd}/quadlet/ranges_test.go (100%) rename pkg/{ => systemd}/quadlet/subuids.go (100%) diff --git a/cmd/quadlet/main.go b/cmd/quadlet/main.go index 1e524b87a6..261e14d00e 100644 --- a/cmd/quadlet/main.go +++ b/cmd/quadlet/main.go @@ -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, @@ -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) { @@ -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 @@ -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("", @@ -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") @@ -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) } @@ -242,7 +242,7 @@ func main() { } for name, unit := range units { - var service *systemdparser.UnitFile + var service *parser.UnitFile var err error switch { diff --git a/pkg/systemdparser/split.go b/pkg/systemd/parser/split.go similarity index 99% rename from pkg/systemdparser/split.go rename to pkg/systemd/parser/split.go index 3ff3d83a55..0eaae09d42 100644 --- a/pkg/systemdparser/split.go +++ b/pkg/systemd/parser/split.go @@ -1,4 +1,4 @@ -package systemdparser +package parser import ( "fmt" diff --git a/pkg/systemdparser/unitfile.go b/pkg/systemd/parser/unitfile.go similarity index 99% rename from pkg/systemdparser/unitfile.go rename to pkg/systemd/parser/unitfile.go index 125ef9a26d..00d0a5b9d7 100644 --- a/pkg/systemdparser/unitfile.go +++ b/pkg/systemd/parser/unitfile.go @@ -1,4 +1,4 @@ -package systemdparser +package parser import ( "fmt" diff --git a/pkg/systemdparser/unitfile_test.go b/pkg/systemd/parser/unitfile_test.go similarity index 99% rename from pkg/systemdparser/unitfile_test.go rename to pkg/systemd/parser/unitfile_test.go index 308901b966..bb56d1b5fb 100644 --- a/pkg/systemdparser/unitfile_test.go +++ b/pkg/systemd/parser/unitfile_test.go @@ -1,4 +1,4 @@ -package systemdparser +package parser import ( "testing" diff --git a/pkg/quadlet/podmancmdline.go b/pkg/systemd/quadlet/podmancmdline.go similarity index 100% rename from pkg/quadlet/podmancmdline.go rename to pkg/systemd/quadlet/podmancmdline.go diff --git a/pkg/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go similarity index 97% rename from pkg/quadlet/quadlet.go rename to pkg/systemd/quadlet/quadlet.go index 78c672a7e9..b1869cca23 100644 --- a/pkg/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -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: @@ -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] { @@ -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 { @@ -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", "", "") @@ -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") diff --git a/pkg/quadlet/quadlet_test.go b/pkg/systemd/quadlet/quadlet_test.go similarity index 100% rename from pkg/quadlet/quadlet_test.go rename to pkg/systemd/quadlet/quadlet_test.go diff --git a/pkg/quadlet/ranges.go b/pkg/systemd/quadlet/ranges.go similarity index 100% rename from pkg/quadlet/ranges.go rename to pkg/systemd/quadlet/ranges.go diff --git a/pkg/quadlet/ranges_test.go b/pkg/systemd/quadlet/ranges_test.go similarity index 100% rename from pkg/quadlet/ranges_test.go rename to pkg/systemd/quadlet/ranges_test.go diff --git a/pkg/quadlet/subuids.go b/pkg/systemd/quadlet/subuids.go similarity index 100% rename from pkg/quadlet/subuids.go rename to pkg/systemd/quadlet/subuids.go diff --git a/test/e2e/quadlet_test.go b/test/e2e/quadlet_test.go index 27e30849b1..7da6f0730f 100644 --- a/test/e2e/quadlet_test.go +++ b/test/e2e/quadlet_test.go @@ -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" @@ -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:] @@ -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] @@ -110,12 +110,12 @@ 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 @@ -123,7 +123,7 @@ func (t *quadletTestcase) assertFinalArgs(args []string, unit *systemdparser.Uni 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] @@ -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:] { @@ -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 {