aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-09-07 10:39:38 +0200
committerGitHub <noreply@github.com>2022-09-07 10:39:38 +0200
commitb231e73c206dfcc576de83c83c65240259b6d119 (patch)
tree95121ae81be087050a68ae0d2dcac71f58478518
parentea3e7ef0733dfc010606fdc8fc631e1d17866349 (diff)
parentd759576ab3387321984da582810f3476dfa4df36 (diff)
downloadpodman-b231e73c206dfcc576de83c83c65240259b6d119.tar.gz
podman-b231e73c206dfcc576de83c83c65240259b6d119.tar.bz2
podman-b231e73c206dfcc576de83c83c65240259b6d119.zip
Merge pull request #15633 from thediveo/events
Closes #15617: emit container labels for container exited and exec died events
-rw-r--r--libpod/events.go12
-rw-r--r--test/system/090-events.bats19
2 files changed, 31 insertions, 0 deletions
diff --git a/libpod/events.go b/libpod/events.go
index c9e4c9d26..60142cb60 100644
--- a/libpod/events.go
+++ b/libpod/events.go
@@ -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)
}
@@ -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)
}
diff --git a/test/system/090-events.bats b/test/system/090-events.bats
index cee0e23b0..cd1bf327b 100644
--- a/test/system/090-events.bats
+++ b/test/system/090-events.bats
@@ -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"
+}