diff --git a/cmd/crictl/events.go b/cmd/crictl/events.go index d7c5d7c0b2..27331e4563 100644 --- a/cmd/crictl/events.go +++ b/cmd/crictl/events.go @@ -28,7 +28,7 @@ import ( var eventsCommand = &cli.Command{ Name: "events", - Usage: "Fetch the events of containers", + Usage: "Stream the events of containers", Aliases: []string{"event"}, UseShortOptionHandling: true, Flags: []cli.Flag{ @@ -48,6 +48,16 @@ var eventsCommand = &cli.Command{ return cli.ShowSubcommandHelp(c) } + switch format := c.String("output"); format { + case "json", "yaml": + if len(c.String("template")) > 0 { + return fmt.Errorf("template can't be used with %q format", format) + } + case "go-template": + default: + return fmt.Errorf("don't support %q format", format) + } + runtimeClient, err := getRuntimeService(c, 0) if err != nil { return err @@ -82,7 +92,7 @@ func Events(cliContext *cli.Context, client internalapi.RuntimeService) error { case e := <-containerEventsCh: err := outputEvent(e, cliContext.String("output"), cliContext.String("template")) if err != nil { - return err + fmt.Printf("formatting container event: %s\n", err) } } } diff --git a/docs/crictl.md b/docs/crictl.md index a2134f6e63..1eb4270da0 100644 --- a/docs/crictl.md +++ b/docs/crictl.md @@ -65,7 +65,7 @@ COMMANDS: - `statsp`: List pod(s) resource usage statistics - `completion`: Output bash shell completion code - `checkpoint`: Checkpoint one or more running containers -- `events, event`: Fetch the events of containers +- `events, event`: Stream the events of containers - `help, h`: Shows a list of commands or help for one command `crictl` by default connects on Unix to: diff --git a/test/e2e/events_test.go b/test/e2e/events_test.go index 1b516c2552..073d6b947b 100644 --- a/test/e2e/events_test.go +++ b/test/e2e/events_test.go @@ -24,6 +24,14 @@ import ( // The actual test suite var _ = t.Describe("events", func() { + It("should fail with not supported output format", func() { + t.CrictlExpectFailure("events --output=ini", "", "don't support \"ini\" format") + }) + + It("should fail with template set for non go-template format", func() { + t.CrictlExpectFailure("events --template=\"{{ .containerID }}\"", "", "template can't be used with \"json\" format") + }) + It("should succeed", func() { // Given endpoint, testDir, crio := t.StartCrio()