Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
surik committed Aug 17, 2023
1 parent b703e6a commit 3a881ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
14 changes: 12 additions & 2 deletions cmd/crictl/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/crictl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3a881ad

Please sign in to comment.