mirror of https://github.com/containers/podman.git
Merge pull request #10561 from vrothberg/fix-remote-events-label
remote events: support labels
This commit is contained in:
commit
5a209b3d76
|
@ -30,29 +30,41 @@ func ConvertToLibpodEvent(e Event) *libpodEvents.Event {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 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{
|
return &libpodEvents.Event{
|
||||||
ContainerExitCode: exitCode,
|
ContainerExitCode: exitCode,
|
||||||
ID: e.Actor.ID,
|
ID: e.Actor.ID,
|
||||||
Image: e.Actor.Attributes["image"],
|
Image: image,
|
||||||
Name: e.Actor.Attributes["name"],
|
Name: name,
|
||||||
Status: status,
|
Status: status,
|
||||||
Time: time.Unix(e.Time, e.TimeNano),
|
Time: time.Unix(e.Time, e.TimeNano),
|
||||||
Type: t,
|
Type: t,
|
||||||
|
Details: libpodEvents.Details{
|
||||||
|
Attributes: details,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConvertToEntitiesEvent converts a libpod event to an entities one.
|
// ConvertToEntitiesEvent converts a libpod event to an entities one.
|
||||||
func ConvertToEntitiesEvent(e libpodEvents.Event) *Event {
|
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{
|
return &Event{dockerEvents.Message{
|
||||||
Type: e.Type.String(),
|
Type: e.Type.String(),
|
||||||
Action: e.Status.String(),
|
Action: e.Status.String(),
|
||||||
Actor: dockerEvents.Actor{
|
Actor: dockerEvents.Actor{
|
||||||
ID: e.ID,
|
ID: e.ID,
|
||||||
Attributes: map[string]string{
|
Attributes: attributes,
|
||||||
"image": e.Image,
|
|
||||||
"name": e.Name,
|
|
||||||
"containerExitCode": strconv.Itoa(e.ContainerExitCode),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Scope: "local",
|
Scope: "local",
|
||||||
Time: e.Time.Unix(),
|
Time: e.Time.Unix(),
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/containers/podman/v3/libpod/events"
|
||||||
. "github.com/containers/podman/v3/test/utils"
|
. "github.com/containers/podman/v3/test/utils"
|
||||||
"github.com/containers/storage/pkg/stringid"
|
"github.com/containers/storage/pkg/stringid"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
|
@ -134,12 +135,10 @@ var _ = Describe("Podman events", func() {
|
||||||
jsonArr := test.OutputToStringArray()
|
jsonArr := test.OutputToStringArray()
|
||||||
Expect(test.OutputToStringArray()).ShouldNot(BeEmpty())
|
Expect(test.OutputToStringArray()).ShouldNot(BeEmpty())
|
||||||
|
|
||||||
eventsMap := make(map[string]string)
|
event := events.Event{}
|
||||||
err := json.Unmarshal([]byte(jsonArr[0]), &eventsMap)
|
err := json.Unmarshal([]byte(jsonArr[0]), &event)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
Expect(eventsMap).To(HaveKey("Status"))
|
|
||||||
|
|
||||||
test = podmanTest.Podman([]string{"events", "--stream=false", "--format", "{{json.}}"})
|
test = podmanTest.Podman([]string{"events", "--stream=false", "--format", "{{json.}}"})
|
||||||
test.WaitWithDefaultTimeout()
|
test.WaitWithDefaultTimeout()
|
||||||
Expect(test).To(Exit(0))
|
Expect(test).To(Exit(0))
|
||||||
|
@ -147,11 +146,9 @@ var _ = Describe("Podman events", func() {
|
||||||
jsonArr = test.OutputToStringArray()
|
jsonArr = test.OutputToStringArray()
|
||||||
Expect(test.OutputToStringArray()).ShouldNot(BeEmpty())
|
Expect(test.OutputToStringArray()).ShouldNot(BeEmpty())
|
||||||
|
|
||||||
eventsMap = make(map[string]string)
|
event = events.Event{}
|
||||||
err = json.Unmarshal([]byte(jsonArr[0]), &eventsMap)
|
err = json.Unmarshal([]byte(jsonArr[0]), &event)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
Expect(eventsMap).To(HaveKey("Status"))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman events --until future", func() {
|
It("podman events --until future", func() {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
load helpers
|
load helpers
|
||||||
|
|
||||||
@test "events with a filter by label" {
|
@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)
|
cname=test-$(random_string 30 | tr A-Z a-z)
|
||||||
labelname=$(random_string 10)
|
labelname=$(random_string 10)
|
||||||
labelvalue=$(random_string 15)
|
labelvalue=$(random_string 15)
|
||||||
|
|
Loading…
Reference in New Issue