Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #15617: emit container labels for container exited and exec died events #15633

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions libpod/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func (c *Container) newContainerExitedEvent(exitCode int32) {
e.Image = c.config.RootfsImageName
e.Type = events.Container
e.ContainerExitCode = int(exitCode)

e.Details = events.Details{
ID: e.ID,
Attributes: c.Labels(),
}

if err := c.runtime.eventer.Write(e); err != nil {
logrus.Errorf("Unable to write container exited event: %q", err)
}
Expand All @@ -70,6 +76,12 @@ func (c *Container) newExecDiedEvent(sessionID string, exitCode int) {
e.ContainerExitCode = exitCode
e.Attributes = make(map[string]string)
e.Attributes["execID"] = sessionID

e.Details = events.Details{
ID: e.ID,
Attributes: c.Labels(),
}

if err := c.runtime.eventer.Write(e); err != nil {
logrus.Errorf("Unable to write exec died event: %q", err)
}
Expand Down
19 changes: 19 additions & 0 deletions test/system/090-events.bats
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,22 @@ EOF
is "$(wc -l <$eventsFile)" "$(wc -l <<<$output)" "all events are returned"
is "${lines[-2]}" ".* log-rotation $eventsFile"
}

# Prior to #15633, container labels would not appear in 'die' log events
@test "events - labels included in container die" {
skip_if_remote "remote does not support --events-backend"
local cname=c$(random_string 15)
local lname=l$(random_string 10)
local lvalue="v$(random_string 10) $(random_string 5)"

run_podman 17 --events-backend=file run --rm \
--name=$cname \
--label=$lname="$lvalue" \
$IMAGE sh -c 'exit 17'
run_podman --events-backend=file events \
--filter=container=$cname \
--filter=status=died \
--stream=false \
--format="{{.Attributes.$lname}}"
assert "$output" = "$lvalue" "podman-events output includes container label"
}