specgen/generate: Fix log tag priority

Currently setting log_tag from containers.conf will override any value
set via --log-opt tag=value option. This commit fixes this.

Fixes: https://github.com/containers/podman/issues/26236

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
(cherry picked from commit a17f8afbbc634d81588e9f392a4b47542b6c2c29)
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Povilas Kanapickas
2025-05-30 01:37:21 +03:00
committed by Paul Holzinger
parent c5ac361844
commit 8e120c93bd
2 changed files with 26 additions and 1 deletions

View File

@ -338,7 +338,9 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
s.LogConfiguration.Options = make(map[string]string)
}
s.LogConfiguration.Options["tag"] = rtc.Containers.LogTag
if _, exists := s.LogConfiguration.Options["tag"]; !exists {
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)
}

View File

@ -267,6 +267,29 @@ var _ = Describe("Verify podman containers.conf usage", func() {
Expect(out).To(ContainSubstring("alpine"))
})
It("using journald for container with container log_tag override", func() {
SkipIfJournaldUnavailable()
os.Setenv("CONTAINERS_CONF", "config/containers-journald.conf")
if IsRemote() {
podmanTest.RestartRemoteService()
}
logc := podmanTest.Podman([]string{"run", "-d", "--log-opt", "tag=OverriddenTag", ALPINE, "sh", "-c", "echo podman; sleep 0.1; echo podman; sleep 0.1; echo podman"})
logc.WaitWithDefaultTimeout()
Expect(logc).Should(ExitCleanly())
cid := logc.OutputToString()
wait := podmanTest.Podman([]string{"wait", cid})
wait.WaitWithDefaultTimeout()
Expect(wait).Should(ExitCleanly())
// Flake prevention: journalctl makes no timeliness guarantees.
time.Sleep(1 * time.Second)
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).ToNot(HaveOccurred())
Expect(out).To(ContainSubstring("OverriddenTag"))
})
It("add volumes", func() {
conffile := filepath.Join(podmanTest.TempDir, "container.conf")