From 138b09c7e28de336717191ec79c0b0bdf61b448a Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 9 Sep 2022 11:43:20 +0200 Subject: event backend none: return an error when reading events podman --events-backend none events should return with an error since it will never be able to actually list events. Fixes part three of #15688 Signed-off-by: Paul Holzinger --- cmd/podman/system/events.go | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go index 3c6a35e83..57279bb02 100644 --- a/cmd/podman/system/events.go +++ b/cmd/podman/system/events.go @@ -99,25 +99,28 @@ func eventsCmd(cmd *cobra.Command, _ []string) error { errChannel <- err }() - for event := range eventChannel { - switch { - case event == nil: - // no-op - case doJSON: - jsonStr, err := event.ToJSONString() - if err != nil { - return err + for { + select { + case err := <-errChannel: + return err + case event := <-eventChannel: + switch { + case event == nil: + // no-op + case doJSON: + jsonStr, err := event.ToJSONString() + if err != nil { + return err + } + fmt.Println(jsonStr) + case cmd.Flags().Changed("format"): + if err := rpt.Execute(event); err != nil { + return err + } + os.Stdout.WriteString("\n") + default: + fmt.Println(event.ToHumanReadable(!noTrunc)) } - fmt.Println(jsonStr) - case cmd.Flags().Changed("format"): - if err := rpt.Execute(event); err != nil { - return err - } - os.Stdout.WriteString("\n") - default: - fmt.Println(event.ToHumanReadable(!noTrunc)) } } - - return <-errChannel } -- cgit v1.2.3-54-g00ecf From 2ae4ce79996097fb0a403abbb9be9ef7b5c02d80 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 12 Sep 2022 14:22:27 +0200 Subject: fix race where podman events exits to early In order to display all events we have to read until the event channel is closed. Signed-off-by: Paul Holzinger --- cmd/podman/system/events.go | 16 +++++++++++----- test/system/090-events.bats | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go index 57279bb02..693af3e60 100644 --- a/cmd/podman/system/events.go +++ b/cmd/podman/system/events.go @@ -101,12 +101,12 @@ func eventsCmd(cmd *cobra.Command, _ []string) error { for { select { - case err := <-errChannel: - return err - case event := <-eventChannel: + case event, ok := <-eventChannel: + if !ok { + // channel was closed we can exit + return nil + } switch { - case event == nil: - // no-op case doJSON: jsonStr, err := event.ToJSONString() if err != nil { @@ -121,6 +121,12 @@ func eventsCmd(cmd *cobra.Command, _ []string) error { default: fmt.Println(event.ToHumanReadable(!noTrunc)) } + case err := <-errChannel: + // only exit in case of an error, + // otherwise keep reading events until the event channel is closed + if err != nil { + return err + } } } } diff --git a/test/system/090-events.bats b/test/system/090-events.bats index 509e7a306..3fac51938 100644 --- a/test/system/090-events.bats +++ b/test/system/090-events.bats @@ -74,6 +74,7 @@ load helpers .*image tag $imageID $tag .*image untag $imageID $tag:latest .*image tag $imageID $tag +.*image untag $imageID $IMAGE .*image untag $imageID $tag:latest .*image remove $imageID $imageID" \ "podman events" -- cgit v1.2.3-54-g00ecf From a63a40c3eece95e96e5b52a00646998606c5f82c Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 12 Sep 2022 18:02:45 +0200 Subject: podman events --format: fix duplicated newline The --format changes caused a duplicated newline. PR #15678 should have a test for this. Signed-off-by: Paul Holzinger --- cmd/podman/system/events.go | 1 - 1 file changed, 1 deletion(-) (limited to 'cmd') diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go index 693af3e60..290f5b0fa 100644 --- a/cmd/podman/system/events.go +++ b/cmd/podman/system/events.go @@ -117,7 +117,6 @@ func eventsCmd(cmd *cobra.Command, _ []string) error { if err := rpt.Execute(event); err != nil { return err } - os.Stdout.WriteString("\n") default: fmt.Println(event.ToHumanReadable(!noTrunc)) } -- cgit v1.2.3-54-g00ecf