Skip to content

Commit

Permalink
legacy events: also set exitCode
Browse files Browse the repository at this point in the history
For Status = "die", Docker sets the exit code of the container
to a field "exitCode".  Podman uses "containerExitCode".
Copy the value into "exitCode" as well, for compatibility.

Signed-off-by: Leah Neukirchen <[email protected]>
  • Loading branch information
leahneukirchen committed Jan 3, 2022
1 parent a1ebde1 commit 116a276
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/api/handlers/compat/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func GetEvents(w http.ResponseWriter, r *http.Request) {
if !utils.IsLibpodRequest(r) && e.Status == "died" {
e.Status = "die"
e.Action = "die"
e.Actor.Attributes["exitCode"] = e.Actor.Attributes["containerExitCode"]
}

if err := coder.Encode(e); err != nil {
Expand Down
27 changes: 27 additions & 0 deletions test/apiv2/27-containersEvents.at
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- sh -*-
#
# test container-related events
#

podman pull $IMAGE &>/dev/null

# Ensure clean slate
podman rm -a -f &>/dev/null

START=$(date +%s)

podman run $IMAGE false || true

# libpod api
t GET "libpod/events?stream=false&since=$START" 200 \
'select(.status | contains("start")).Action=start' \
'select(.status | contains("died")).Action=died' \
'select(.status | contains("died")).Actor.Attributes.containerExitCode=1'

# compat api, uses status=die (#12643)
t GET "events?stream=false&since=$START" 200 \
'select(.status | contains("start")).Action=start' \
'select(.status | contains("die")).Action=die' \
'select(.status | contains("die")).Actor.Attributes.exitCode=1'

# vim: filetype=sh

0 comments on commit 116a276

Please sign in to comment.