mirror of https://github.com/containers/podman.git
Support log_tag defaults from containers.conf
Fixes: https://github.com/containers/podman/issues/10204 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
510509bafc
commit
f2dff41dbc
|
@ -7,12 +7,14 @@ import (
|
||||||
|
|
||||||
"github.com/containers/common/libimage"
|
"github.com/containers/common/libimage"
|
||||||
"github.com/containers/podman/v3/libpod"
|
"github.com/containers/podman/v3/libpod"
|
||||||
|
"github.com/containers/podman/v3/libpod/define"
|
||||||
ann "github.com/containers/podman/v3/pkg/annotations"
|
ann "github.com/containers/podman/v3/pkg/annotations"
|
||||||
envLib "github.com/containers/podman/v3/pkg/env"
|
envLib "github.com/containers/podman/v3/pkg/env"
|
||||||
"github.com/containers/podman/v3/pkg/signal"
|
"github.com/containers/podman/v3/pkg/signal"
|
||||||
"github.com/containers/podman/v3/pkg/specgen"
|
"github.com/containers/podman/v3/pkg/specgen"
|
||||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -203,6 +205,17 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
|
||||||
if len(s.LogConfiguration.Driver) < 1 {
|
if len(s.LogConfiguration.Driver) < 1 {
|
||||||
s.LogConfiguration.Driver = rtc.Containers.LogDriver
|
s.LogConfiguration.Driver = rtc.Containers.LogDriver
|
||||||
}
|
}
|
||||||
|
if len(rtc.Containers.LogTag) > 0 {
|
||||||
|
if s.LogConfiguration.Driver != define.JSONLogging {
|
||||||
|
if s.LogConfiguration.Options == nil {
|
||||||
|
s.LogConfiguration.Options = make(map[string]string)
|
||||||
|
}
|
||||||
|
|
||||||
|
s.LogConfiguration.Options["tag"] = rtc.Containers.LogTag
|
||||||
|
} else {
|
||||||
|
logrus.Warnf("log_tag %q is not allowed with %q log_driver", rtc.Containers.LogTag, define.JSONLogging)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
warnings, err := verifyContainerResources(s)
|
warnings, err := verifyContainerResources(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
[containers]
|
||||||
|
|
||||||
|
log_driver="journald"
|
||||||
|
log_tag="{{.ImageName}}"
|
|
@ -167,16 +167,34 @@ var _ = Describe("Podman run", func() {
|
||||||
verifyNSHandling("/proc/self/ns/cgroup", "--cgroupns")
|
verifyNSHandling("/proc/self/ns/cgroup", "--cgroupns")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("using journald for container with container log_tag", func() {
|
||||||
|
SkipIfInContainer("journalctl inside a container doesn't work correctly")
|
||||||
|
os.Setenv("CONTAINERS_CONF", "config/containers-journald.conf")
|
||||||
|
if IsRemote() {
|
||||||
|
podmanTest.RestartRemoteService()
|
||||||
|
}
|
||||||
|
logc := podmanTest.Podman([]string{"run", "-d", ALPINE, "sh", "-c", "echo podman; sleep 0.1; echo podman; sleep 0.1; echo podman"})
|
||||||
|
logc.WaitWithDefaultTimeout()
|
||||||
|
Expect(logc.ExitCode()).To(Equal(0))
|
||||||
|
cid := logc.OutputToString()
|
||||||
|
|
||||||
|
wait := podmanTest.Podman([]string{"wait", cid})
|
||||||
|
wait.WaitWithDefaultTimeout()
|
||||||
|
Expect(wait.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
cmd := exec.Command("journalctl", "--no-pager", "-o", "json", "--output-fields=CONTAINER_TAG", fmt.Sprintf("CONTAINER_ID_FULL=%s", cid))
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(string(out)).To(ContainSubstring("alpine"))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman containers.conf additionalvolumes", func() {
|
It("podman containers.conf additionalvolumes", func() {
|
||||||
conffile := filepath.Join(podmanTest.TempDir, "container.conf")
|
conffile := filepath.Join(podmanTest.TempDir, "container.conf")
|
||||||
tempdir, err = CreateTempDirInTempDir()
|
tempdir, err = CreateTempDirInTempDir()
|
||||||
if err != nil {
|
Expect(err).To(BeNil())
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
err := ioutil.WriteFile(conffile, []byte(fmt.Sprintf("[containers]\nvolumes=[\"%s:%s:Z\",]\n", tempdir, tempdir)), 0755)
|
err := ioutil.WriteFile(conffile, []byte(fmt.Sprintf("[containers]\nvolumes=[\"%s:%s:Z\",]\n", tempdir, tempdir)), 0755)
|
||||||
if err != nil {
|
Expect(err).To(BeNil())
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Setenv("CONTAINERS_CONF", conffile)
|
os.Setenv("CONTAINERS_CONF", conffile)
|
||||||
if IsRemote() {
|
if IsRemote() {
|
||||||
|
|
Loading…
Reference in New Issue