Fix --tail log on restart problem

--tail=1 is not working f you restart a container with journald logging.

We see the exit status and then call into the logging a second time
causing all of the logs to print.

Removing the tail log on exited seems to fix the problem.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh 2022-04-13 08:34:02 -04:00
parent b962fb9f29
commit 63c38b99f4
No known key found for this signature in database
GPG Key ID: A2DF901DABE2C028
2 changed files with 28 additions and 3 deletions

View File

@ -209,9 +209,6 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption
containerCouldBeLogging = true containerCouldBeLogging = true
case events.Exited: case events.Exited:
containerCouldBeLogging = false containerCouldBeLogging = false
if doTail {
doTailFunc()
}
} }
continue continue
} }

View File

@ -30,6 +30,34 @@ load helpers
run_podman rm $cid run_podman rm $cid
} }
function _log_test_tail() {
local driver=$1
run_podman run -d --log-driver=$driver $IMAGE sh -c "echo test1; echo test2"
cid="$output"
run_podman logs --tail 1 $cid
is "$output" "test2" "logs should only show last line"
run_podman restart $cid
run_podman logs --tail 1 $cid
is "$output" "test2" "logs should only show last line after restart"
run_podman rm $cid
}
@test "podman logs - tail test, k8s-file" {
_log_test_tail k8s-file
}
@test "podman logs - tail test, journald" {
# We can't use journald on RHEL as rootless: rhbz#1895105
skip_if_journald_unavailable
_log_test_tail journald
}
function _additional_events_backend() { function _additional_events_backend() {
local driver=$1 local driver=$1
# Since PR#10431, 'logs -f' with journald driver is only supported with journald events backend. # Since PR#10431, 'logs -f' with journald driver is only supported with journald events backend.