summaryrefslogtreecommitdiff
path: root/libpod/events/journal_linux.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2020-10-21 11:59:35 -0500
committerbaude <bbaude@redhat.com>2020-10-23 12:07:34 -0500
commitc593e49701b3a4bb48050f3d8829f2fe6ac457ef (patch)
treef69648182082c37d4416efdb5405a9431984463c /libpod/events/journal_linux.go
parent51fa8ded9ffb7924288a2728ce92af7f6cc66d34 (diff)
downloadpodman-c593e49701b3a4bb48050f3d8829f2fe6ac457ef.tar.gz
podman-c593e49701b3a4bb48050f3d8829f2fe6ac457ef.tar.bz2
podman-c593e49701b3a4bb48050f3d8829f2fe6ac457ef.zip
filter events by labels
adding the ability to filter evens by the container labels. this requires that container labels be added to the events data being recorded and subsequently read. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'libpod/events/journal_linux.go')
-rw-r--r--libpod/events/journal_linux.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/libpod/events/journal_linux.go b/libpod/events/journal_linux.go
index dc55dbc77..5d17a85b4 100644
--- a/libpod/events/journal_linux.go
+++ b/libpod/events/journal_linux.go
@@ -4,6 +4,7 @@ package events
import (
"context"
+ "encoding/json"
"strconv"
"time"
@@ -46,6 +47,15 @@ func (e EventJournalD) Write(ee Event) error {
if ee.ContainerExitCode != 0 {
m["PODMAN_EXIT_CODE"] = strconv.Itoa(ee.ContainerExitCode)
}
+ // If we have container labels, we need to convert them to a string so they
+ // can be recorded with the event
+ if len(ee.Details.Attributes) > 0 {
+ b, err := json.Marshal(ee.Details.Attributes)
+ if err != nil {
+ return err
+ }
+ m["PODMAN_LABELS"] = string(b)
+ }
case Volume:
m["PODMAN_NAME"] = ee.Name
}
@@ -174,6 +184,19 @@ func newEventFromJournalEntry(entry *sdjournal.JournalEntry) (*Event, error) { /
newEvent.ContainerExitCode = intCode
}
}
+
+ // we need to check for the presence of labels recorded to a container event
+ if stringLabels, ok := entry.Fields["PODMAN_LABELS"]; ok && len(stringLabels) > 0 {
+ labels := make(map[string]string, 0)
+ if err := json.Unmarshal([]byte(stringLabels), &labels); err != nil {
+ return nil, err
+ }
+
+ // if we have labels, add them to the event
+ if len(labels) > 0 {
+ newEvent.Details = Details{Attributes: labels}
+ }
+ }
case Image:
newEvent.ID = entry.Fields["PODMAN_ID"]
}