From 6038200fe052d6a46355dd51bf91bf97601e6cf6 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 4 Jan 2023 18:59:53 +0100 Subject: [PATCH] k8s-file: podman logs --until --follow exit after time When you use podman logs with --until and --follow it should exit after the requested until time and not keep hanging forever. This fixes the behavior for the k8s-file backend. Signed-off-by: Paul Holzinger --- libpod/container_log.go | 8 ++++++++ test/system/035-logs.bats | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/libpod/container_log.go b/libpod/container_log.go index c49b54eb16..e33ede5dd1 100644 --- a/libpod/container_log.go +++ b/libpod/container_log.go @@ -72,6 +72,14 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption } } } + go func() { + if options.Until.After(time.Now()) { + time.Sleep(time.Until(options.Until)) + if err := t.Stop(); err != nil { + logrus.Errorf("Stopping logger: %v", err) + } + } + }() go func() { defer options.WaitGroup.Done() diff --git a/test/system/035-logs.bats b/test/system/035-logs.bats index 6f253a29c7..8f378054af 100644 --- a/test/system/035-logs.bats +++ b/test/system/035-logs.bats @@ -373,6 +373,10 @@ $content" "logs --until -f on running container works" run_podman ${events_backend} rm -t 0 -f $cname } +@test "podman logs - --until --follow k8s-file" { + _log_test_follow_until k8s-file +} + @test "podman logs - --until --follow journald" { # We can't use journald on RHEL as rootless: rhbz#1895105 skip_if_journald_unavailable