Skip to content

Commit a17f8af

Browse files
committed
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: containers#26236 Signed-off-by: Povilas Kanapickas <[email protected]>
1 parent 23ded8b commit a17f8af

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pkg/specgen/generate/container.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
338338
s.LogConfiguration.Options = make(map[string]string)
339339
}
340340

341-
s.LogConfiguration.Options["tag"] = rtc.Containers.LogTag
341+
if _, exists := s.LogConfiguration.Options["tag"]; !exists {
342+
s.LogConfiguration.Options["tag"] = rtc.Containers.LogTag
343+
}
342344
} else {
343345
logrus.Warnf("log_tag %q is not allowed with %q log_driver", rtc.Containers.LogTag, define.JSONLogging)
344346
}

test/e2e/containers_conf_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,29 @@ var _ = Describe("Verify podman containers.conf usage", func() {
267267
Expect(out).To(ContainSubstring("alpine"))
268268
})
269269

270+
It("using journald for container with container log_tag override", func() {
271+
SkipIfJournaldUnavailable()
272+
os.Setenv("CONTAINERS_CONF", "config/containers-journald.conf")
273+
if IsRemote() {
274+
podmanTest.RestartRemoteService()
275+
}
276+
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"})
277+
logc.WaitWithDefaultTimeout()
278+
Expect(logc).Should(ExitCleanly())
279+
cid := logc.OutputToString()
280+
281+
wait := podmanTest.Podman([]string{"wait", cid})
282+
wait.WaitWithDefaultTimeout()
283+
Expect(wait).Should(ExitCleanly())
284+
285+
// Flake prevention: journalctl makes no timeliness guarantees.
286+
time.Sleep(1 * time.Second)
287+
cmd := exec.Command("journalctl", "--no-pager", "-o", "json", "--output-fields=CONTAINER_TAG", fmt.Sprintf("CONTAINER_ID_FULL=%s", cid))
288+
out, err := cmd.CombinedOutput()
289+
Expect(err).ToNot(HaveOccurred())
290+
Expect(out).To(ContainSubstring("OverriddenTag"))
291+
})
292+
270293
It("add volumes", func() {
271294
conffile := filepath.Join(podmanTest.TempDir, "container.conf")
272295

0 commit comments

Comments
 (0)