Merge pull request #16862 from alexlarsson/quadlet-podman-binary-name

Quadlet handle podman binary name better
This commit is contained in:
OpenShift Merge Robot 2022-12-16 07:00:38 -05:00 committed by GitHub
commit 3219650fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 4 deletions

View File

@ -110,6 +110,7 @@ LDFLAGS_PODMAN ?= \
$(if $(BUILD_INFO),-X $(LIBPOD)/define.buildInfo=$(BUILD_INFO),) \
-X $(LIBPOD)/config._installPrefix=$(PREFIX) \
-X $(LIBPOD)/config._etcDir=$(ETCDIR) \
-X $(PROJECT)/v4/pkg/systemd/quadlet._binDir=$(BINDIR) \
-X github.com/containers/common/pkg/config.additionalHelperBinariesDir=$(HELPER_BINARIES_DIR)\
$(EXTRA_LDFLAGS)
LDFLAGS_PODMAN_STATIC ?= \

View File

@ -2,9 +2,24 @@ package quadlet
import (
"fmt"
"os"
"path"
"sort"
)
// Overwritten at build time
var (
_binDir string
)
func podmanBinary() string {
podman := os.Getenv("PODMAN")
if len(podman) > 0 {
return podman
}
return path.Join(_binDir, "podman")
}
/* This is a helper for constructing podman commandlines */
type PodmanCmdline struct {
Args []string
@ -47,7 +62,7 @@ func NewPodmanCmdline(args ...string) *PodmanCmdline {
Args: make([]string, 0),
}
c.add("/usr/bin/podman")
c.add(podmanBinary())
c.add(args...)
return c
}

View File

@ -229,7 +229,7 @@ func ConvertContainer(container *parser.UnitFile, isUser bool) (*parser.UnitFile
// If the conman exited uncleanly it may not have removed the container, so force it,
// -i makes it ignore non-existing files.
service.Add(ServiceGroup, "ExecStopPost", "-/usr/bin/podman rm -f -i --cidfile=%t/%N.cid")
service.Add(ServiceGroup, "ExecStopPost", "-"+podmanBinary()+" rm -f -i --cidfile=%t/%N.cid")
// Remove the cid file, to avoid confusion as the container is no longer running.
service.Add(ServiceGroup, "ExecStopPost", "-rm -f %t/%N.cid")

View File

@ -14,7 +14,7 @@
## assert-key-is "Service" "Type" "notify"
## assert-key-is "Service" "NotifyAccess" "all"
## assert-key-is "Service" "SyslogIdentifier" "%N"
## assert-key-is "Service" "ExecStopPost" "-/usr/bin/podman rm -f -i --cidfile=%t/%N.cid" "-rm -f %t/%N.cid"
## assert-key-is-regex "Service" "ExecStopPost" "-.*/podman rm -f -i --cidfile=%t/%N.cid" "-rm -f %t/%N.cid"
## assert-key-is "Service" "Environment" "PODMAN_SYSTEMD_UNIT=%n"
[Container]

View File

@ -1,7 +1,7 @@
## assert-key-is Unit RequiresMountsFor "%t/containers"
## assert-key-is Service Type oneshot
## assert-key-is Service RemainAfterExit yes
## assert-key-is Service ExecStart "/usr/bin/podman volume create --ignore systemd-basic"
## assert-key-is-regex Service ExecStart ".*/podman volume create --ignore systemd-basic"
## assert-key-is Service SyslogIdentifier "%N"
[Volume]

View File

@ -99,6 +99,7 @@ func (t *quadletTestcase) assertStdErrContains(args []string, session *PodmanSes
}
func (t *quadletTestcase) assertKeyIs(args []string, unit *parser.UnitFile) bool {
Expect(len(args)).To(BeNumerically(">=", 3))
group := args[0]
key := args[1]
values := args[2:]
@ -116,7 +117,28 @@ func (t *quadletTestcase) assertKeyIs(args []string, unit *parser.UnitFile) bool
return true
}
func (t *quadletTestcase) assertKeyIsRegex(args []string, unit *parser.UnitFile) bool {
Expect(len(args)).To(BeNumerically(">=", 3))
group := args[0]
key := args[1]
values := args[2:]
realValues := unit.LookupAll(group, key)
if len(realValues) != len(values) {
return false
}
for i := range realValues {
matched, _ := regexp.MatchString(values[i], realValues[i])
if !matched {
return false
}
}
return true
}
func (t *quadletTestcase) assertKeyContains(args []string, unit *parser.UnitFile) bool {
Expect(args).To(HaveLen(3))
group := args[0]
key := args[1]
value := args[2]
@ -171,6 +193,7 @@ func (t *quadletTestcase) assertStopPodmanFinalArgsRegex(args []string, unit *pa
}
func (t *quadletTestcase) assertSymlink(args []string, unit *parser.UnitFile) bool {
Expect(args).To(HaveLen(2))
symlink := args[0]
expectedTarget := args[1]
@ -183,6 +206,7 @@ func (t *quadletTestcase) assertSymlink(args []string, unit *parser.UnitFile) bo
}
func (t *quadletTestcase) doAssert(check []string, unit *parser.UnitFile, session *PodmanSessionIntegration) error {
Expect(len(check)).To(BeNumerically(">=", 1))
op := check[0]
args := make([]string, 0)
for _, a := range check[1:] {
@ -205,6 +229,8 @@ func (t *quadletTestcase) doAssert(check []string, unit *parser.UnitFile, sessio
ok = t.assertStdErrContains(args, session)
case "assert-key-is":
ok = t.assertKeyIs(args, unit)
case "assert-key-is-regex":
ok = t.assertKeyIsRegex(args, unit)
case "assert-key-contains":
ok = t.assertKeyContains(args, unit)
case "assert-podman-args":