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 <pholzing@redhat.com>
This commit is contained in:
parent
c5bdb6afe7
commit
138b09c7e2
|
|
@ -99,25 +99,28 @@ func eventsCmd(cmd *cobra.Command, _ []string) error {
|
||||||
errChannel <- err
|
errChannel <- err
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for event := range eventChannel {
|
for {
|
||||||
switch {
|
select {
|
||||||
case event == nil:
|
case err := <-errChannel:
|
||||||
// no-op
|
return err
|
||||||
case doJSON:
|
case event := <-eventChannel:
|
||||||
jsonStr, err := event.ToJSONString()
|
switch {
|
||||||
if err != nil {
|
case event == nil:
|
||||||
return err
|
// 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
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func NewEventer(options EventerOptions) (Eventer, error) {
|
||||||
case strings.ToUpper(LogFile.String()):
|
case strings.ToUpper(LogFile.String()):
|
||||||
return newLogFileEventer(options)
|
return newLogFileEventer(options)
|
||||||
case strings.ToUpper(Null.String()):
|
case strings.ToUpper(Null.String()):
|
||||||
return NewNullEventer(), nil
|
return newNullEventer(), nil
|
||||||
case strings.ToUpper(Memory.String()):
|
case strings.ToUpper(Memory.String()):
|
||||||
return NewMemoryEventer(), nil
|
return NewMemoryEventer(), nil
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@ package events
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EventToNull is an eventer type that only performs write operations
|
// EventToNull is an eventer type that does nothing.
|
||||||
// and only writes to /dev/null. It is meant for unittests only
|
// It is meant for unittests only
|
||||||
type EventToNull struct{}
|
type EventToNull struct{}
|
||||||
|
|
||||||
// Write eats the event and always returns nil
|
// Write eats the event and always returns nil
|
||||||
|
|
@ -13,14 +14,14 @@ func (e EventToNull) Write(ee Event) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read does nothing. Do not use it.
|
// Read does nothing and returns an error.
|
||||||
func (e EventToNull) Read(ctx context.Context, options ReadOptions) error {
|
func (e EventToNull) Read(ctx context.Context, options ReadOptions) error {
|
||||||
return nil
|
return errors.New("cannot read events with the \"none\" backend")
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNullEventer returns a new null eventer. You should only do this for
|
// newNullEventer returns a new null eventer. You should only do this for
|
||||||
// the purposes of internal libpod testing.
|
// the purposes of internal libpod testing.
|
||||||
func NewNullEventer() Eventer {
|
func newNullEventer() Eventer {
|
||||||
return EventToNull{}
|
return EventToNull{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -217,3 +217,12 @@ EOF
|
||||||
--format="{{.Attributes.$lname}}"
|
--format="{{.Attributes.$lname}}"
|
||||||
assert "$output" = "$lvalue" "podman-events output includes container label"
|
assert "$output" = "$lvalue" "podman-events output includes container label"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "events - backend none should error" {
|
||||||
|
skip_if_remote "remote does not support --events-backend"
|
||||||
|
|
||||||
|
run_podman 125 --events-backend none events
|
||||||
|
is "$output" "Error: cannot read events with the \"none\" backend" "correct error message"
|
||||||
|
run_podman 125 --events-backend none events --stream=false
|
||||||
|
is "$output" "Error: cannot read events with the \"none\" backend" "correct error message"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue