Skip to content

Commit 246831b

Browse files
Merge pull request #21409 from rhatdan/events
Show network name network events with podman -remote events
2 parents 5e081e4 + c7910e7 commit 246831b

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

pkg/domain/entities/events.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@ func ConvertToLibpodEvent(e Event) *libpodEvents.Event {
3131
}
3232
image := e.Actor.Attributes["image"]
3333
name := e.Actor.Attributes["name"]
34-
details := e.Actor.Attributes
34+
network := e.Actor.Attributes["network"]
3535
podID := e.Actor.Attributes["podId"]
36+
details := e.Actor.Attributes
3637
delete(details, "image")
3738
delete(details, "name")
39+
delete(details, "network")
40+
delete(details, "podId")
3841
delete(details, "containerExitCode")
3942
return &libpodEvents.Event{
4043
ContainerExitCode: &exitCode,
4144
ID: e.Actor.ID,
4245
Image: image,
4346
Name: name,
47+
Network: network,
4448
Status: status,
4549
Time: time.Unix(0, e.TimeNano),
4650
Type: t,
@@ -64,6 +68,9 @@ func ConvertToEntitiesEvent(e libpodEvents.Event) *types.Event {
6468
attributes["containerExitCode"] = strconv.Itoa(*e.ContainerExitCode)
6569
}
6670
attributes["podId"] = e.PodID
71+
if e.Network != "" {
72+
attributes["network"] = e.Network
73+
}
6774
message := dockerEvents.Message{
6875
// Compatibility with clients that still look for deprecated API elements
6976
Status: e.Status.String(),

test/e2e/events_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,36 @@ var _ = Describe("Podman events", func() {
222222
Expect(result2.OutputToString()).To(ContainSubstring(fmt.Sprintf("pod_id=%s", id)))
223223
})
224224

225+
It("podman events network connection", func() {
226+
network := stringid.GenerateRandomID()
227+
result := podmanTest.Podman([]string{"create", "--network", "bridge", ALPINE, "top"})
228+
result.WaitWithDefaultTimeout()
229+
Expect(result).Should(ExitCleanly())
230+
ctrID := result.OutputToString()
231+
232+
result = podmanTest.Podman([]string{"network", "create", network})
233+
result.WaitWithDefaultTimeout()
234+
Expect(result).Should(ExitCleanly())
235+
236+
result = podmanTest.Podman([]string{"network", "connect", network, ctrID})
237+
result.WaitWithDefaultTimeout()
238+
Expect(result).Should(ExitCleanly())
239+
240+
result = podmanTest.Podman([]string{"network", "disconnect", network, ctrID})
241+
result.WaitWithDefaultTimeout()
242+
Expect(result).Should(ExitCleanly())
243+
244+
result = podmanTest.Podman([]string{"events", "--stream=false", "--since", "30s"})
245+
result.WaitWithDefaultTimeout()
246+
Expect(result).Should(ExitCleanly())
247+
lines := result.OutputToStringArray()
248+
Expect(lines).To(HaveLen(5))
249+
Expect(lines[3]).To(ContainSubstring("network connect"))
250+
Expect(lines[3]).To(ContainSubstring(fmt.Sprintf("(container=%s, name=%s)", ctrID, network)))
251+
Expect(lines[4]).To(ContainSubstring("network disconnect"))
252+
Expect(lines[4]).To(ContainSubstring(fmt.Sprintf("(container=%s, name=%s)", ctrID, network)))
253+
})
254+
225255
It("podman events health_status generated", func() {
226256
session := podmanTest.Podman([]string{"run", "--name", "test-hc", "-dt", "--health-cmd", "echo working", "busybox"})
227257
session.WaitWithDefaultTimeout()

0 commit comments

Comments
 (0)