Skip to content

Commit

Permalink
remote events: support labels
Browse files Browse the repository at this point in the history
Certain event meta data was lost when converting the remote events to
libpod events and vice versa.  Enable the skipped system tests for
remote.

Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg authored and mheon committed Jun 11, 2021
1 parent c28f442 commit c751544
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
28 changes: 20 additions & 8 deletions pkg/domain/entities/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,41 @@ func ConvertToLibpodEvent(e Event) *libpodEvents.Event {
if err != nil {
return nil
}
image := e.Actor.Attributes["image"]
name := e.Actor.Attributes["name"]
details := e.Actor.Attributes
delete(details, "image")
delete(details, "name")
delete(details, "containerExitCode")
return &libpodEvents.Event{
ContainerExitCode: exitCode,
ID: e.Actor.ID,
Image: e.Actor.Attributes["image"],
Name: e.Actor.Attributes["name"],
Image: image,
Name: name,
Status: status,
Time: time.Unix(e.Time, e.TimeNano),
Type: t,
Details: libpodEvents.Details{
Attributes: details,
},
}
}

// ConvertToEntitiesEvent converts a libpod event to an entities one.
func ConvertToEntitiesEvent(e libpodEvents.Event) *Event {
attributes := e.Details.Attributes
if attributes == nil {
attributes = make(map[string]string)
}
attributes["image"] = e.Image
attributes["name"] = e.Name
attributes["containerExitCode"] = strconv.Itoa(e.ContainerExitCode)
return &Event{dockerEvents.Message{
Type: e.Type.String(),
Action: e.Status.String(),
Actor: dockerEvents.Actor{
ID: e.ID,
Attributes: map[string]string{
"image": e.Image,
"name": e.Name,
"containerExitCode": strconv.Itoa(e.ContainerExitCode),
},
ID: e.ID,
Attributes: attributes,
},
Scope: "local",
Time: e.Time.Unix(),
Expand Down
13 changes: 5 additions & 8 deletions test/e2e/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

"github.com/containers/podman/v3/libpod/events"
. "github.com/containers/podman/v3/test/utils"
"github.com/containers/storage/pkg/stringid"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -134,24 +135,20 @@ var _ = Describe("Podman events", func() {
jsonArr := test.OutputToStringArray()
Expect(test.OutputToStringArray()).ShouldNot(BeEmpty())

eventsMap := make(map[string]string)
err := json.Unmarshal([]byte(jsonArr[0]), &eventsMap)
event := events.Event{}
err := json.Unmarshal([]byte(jsonArr[0]), &event)
Expect(err).ToNot(HaveOccurred())

Expect(eventsMap).To(HaveKey("Status"))

test = podmanTest.Podman([]string{"events", "--stream=false", "--format", "{{json.}}"})
test.WaitWithDefaultTimeout()
Expect(test).To(Exit(0))

jsonArr = test.OutputToStringArray()
Expect(test.OutputToStringArray()).ShouldNot(BeEmpty())

eventsMap = make(map[string]string)
err = json.Unmarshal([]byte(jsonArr[0]), &eventsMap)
event = events.Event{}
err = json.Unmarshal([]byte(jsonArr[0]), &event)
Expect(err).ToNot(HaveOccurred())

Expect(eventsMap).To(HaveKey("Status"))
})

It("podman events --until future", func() {
Expand Down
1 change: 0 additions & 1 deletion test/system/090-events.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
load helpers

@test "events with a filter by label" {
skip_if_remote "FIXME: -remote does not include labels in event output"
cname=test-$(random_string 30 | tr A-Z a-z)
labelname=$(random_string 10)
labelvalue=$(random_string 15)
Expand Down

0 comments on commit c751544

Please sign in to comment.