Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add podman system events alias to podman events #16464

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions cmd/podman/system/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
)

var (
eventsDescription = `Monitor podman events.
eventsDescription = `Monitor podman system events.

By default, streaming mode is used, printing new events as they occur. Previous events can be listed via --since and --until.`
eventsCommand = &cobra.Command{
Use: "events [options]",
Args: validate.NoArgs,
Short: "Show podman events",
Short: "Show podman system events",
Long: eventsDescription,
RunE: eventsCmd,
ValidArgsFunction: completion.AutocompleteNone,
Expand All @@ -31,6 +31,16 @@ var (
podman events --format {{.Image}}
podman events --since 1h30s`,
}

systemEventsCommand = &cobra.Command{
Args: eventsCommand.Args,
Use: eventsCommand.Use,
Short: eventsCommand.Short,
Long: eventsCommand.Long,
RunE: eventsCommand.RunE,
ValidArgsFunction: eventsCommand.ValidArgsFunction,
Example: `podman system events`,
}
)

var (
Expand All @@ -40,30 +50,39 @@ var (
)

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: systemEventsCommand,
Parent: systemCmd,
})
eventsFlags(systemEventsCommand)
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: eventsCommand,
})
flags := eventsCommand.Flags()
eventsFlags(eventsCommand)
}

func eventsFlags(cmd *cobra.Command) {
flags := cmd.Flags()

filterFlagName := "filter"
flags.StringArrayVarP(&eventOptions.Filter, filterFlagName, "f", []string{}, "filter output")
_ = eventsCommand.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteEventFilter)
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteEventFilter)

formatFlagName := "format"
flags.StringVar(&eventFormat, formatFlagName, "", "format the output using a Go template")
_ = eventsCommand.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&events.Event{}))
_ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&events.Event{}))

flags.BoolVar(&eventOptions.Stream, "stream", true, "stream new events; for testing only")

sinceFlagName := "since"
flags.StringVar(&eventOptions.Since, sinceFlagName, "", "show all events created since timestamp")
_ = eventsCommand.RegisterFlagCompletionFunc(sinceFlagName, completion.AutocompleteNone)
_ = cmd.RegisterFlagCompletionFunc(sinceFlagName, completion.AutocompleteNone)

flags.BoolVar(&noTrunc, "no-trunc", true, "do not truncate the output")

untilFlagName := "until"
flags.StringVar(&eventOptions.Until, untilFlagName, "", "show all events until timestamp")
_ = eventsCommand.RegisterFlagCompletionFunc(untilFlagName, completion.AutocompleteNone)
_ = cmd.RegisterFlagCompletionFunc(untilFlagName, completion.AutocompleteNone)

_ = flags.MarkHidden("stream")
}
Expand Down
1 change: 1 addition & 0 deletions commands-demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
| [podman-stop(1)](https://podman.readthedocs.io/en/latest/markdown/podman-stop.1.html) | Stops one or more running containers |
| [podman-system(1)](https://podman.readthedocs.io/en/latest/system.html) | Manage podman |
| [podman-system-df(1)](https://podman.readthedocs.io/en/latest/markdown/podman-system-df.1.html) | Show podman disk usage. |
| [podman-system-events(1)](https://podman.readthedocs.io/en/latest/markdown/podman-events.1.html) | Displays Podman related system events. |
| [podman-system-info(1)](https://podman.readthedocs.io/en/latest/markdown/podman-info.1.html) | Displays Podman related system information. |
| [podman-system-migrate(1)](https://podman.readthedocs.io/en/latest/markdown/podman-system-migrate.1.html) | Migrate existing containers to a new podman version |
| [podman-system-prune(1)](https://podman.readthedocs.io/en/latest/markdown/podman-system-prune.1.html) | Remove all unused container, image and volume data |
Expand Down
1 change: 1 addition & 0 deletions docs/source/markdown/links/podman-system-events.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.so man1/podman-events.1
2 changes: 2 additions & 0 deletions docs/source/markdown/podman-events.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ podman\-events - Monitor Podman events
## SYNOPSIS
**podman events** [*options*]

**podman system events** [*options*]

## DESCRIPTION

Monitor and print events that occur in Podman. Each event will include a timestamp,
Expand Down
1 change: 1 addition & 0 deletions docs/source/markdown/podman-system.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The system command allows you to manage the podman systems
| ------- | ------------------------------------------------------------ | ------------------------------------------------------------------------ |
| connection | [podman-system-connection(1)](podman-system-connection.1.md) | Manage the destination(s) for Podman service(s) |
| df | [podman-system-df(1)](podman-system-df.1.md) | Show podman disk usage. |
| events | [podman-system-events(1)](podman-events.1.md) | Monitor Podman events |
| info | [podman-system-info(1)](podman-info.1.md) | Displays Podman related system information. |
| migrate | [podman-system-migrate(1)](podman-system-migrate.1.md) | Migrate existing containers to a new podman version. |
| prune | [podman-system-prune(1)](podman-system-prune.1.md) | Remove all unused pods, containers, images, networks, and volume data. |
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ registries = ['{{.Host}}:{{.Port}}']`
})

It("podman search format json list tags", func() {
search := podmanTest.Podman([]string{"search", "--list-tags", "--format", "json", "alpine"})
search := podmanTest.Podman([]string{"search", "--list-tags", "--format", "json", ALPINE})
search.WaitWithDefaultTimeout()
Expect(search).Should(Exit(0))
Expect(search.OutputToString()).To(BeValidJSON())
Expect(search.OutputToString()).To(ContainSubstring("docker.io/library/alpine"))
Expect(search.OutputToString()).To(ContainSubstring("3.10"))
Expect(search.OutputToString()).To(ContainSubstring("2.7"))
Expect(search.OutputToString()).To(ContainSubstring("quay.io/libpod/alpine"))
Expect(search.OutputToString()).To(ContainSubstring("3.10.2"))
Expect(search.OutputToString()).To(ContainSubstring("3.2"))
})

// Test for https://github.com/containers/podman/issues/11894
Expand Down
2 changes: 1 addition & 1 deletion test/system/090-events.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ load helpers
is "$output" "$expect" "filtering by container name and label"

# Same thing, but without the container-name filter
run_podman events -f type=container --filter label=${labelname}=${labelvalue} --filter event=start --stream=false
run_podman system events -f type=container --filter label=${labelname}=${labelvalue} --filter event=start --stream=false
is "$output" "$expect" "filtering just by label"

# Now filter just by container name, no label
Expand Down
1 change: 1 addition & 0 deletions test/system/610-format.bats
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ search | $IMAGE
pod inspect | mypod

events | --stream=false --events-backend=file
system events | --stream=false --events-backend=file
"

# podman machine is finicky. Assume we can't run it, but see below for more.
Expand Down
1 change: 1 addition & 0 deletions transfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ There are other equivalents for these tools
| `docker stop` | [`podman stop`](./docs/source/markdown/podman-stop.1.md) |
| `docker system ` | [`podman system`](./docs/source/markdown/podman-system.1.md) |
| `docker system df` | [`podman system df`](./docs/source/markdown/podman-system-df.1.md) |
| `docker system events` | [`podman system events`](./docs/source/markdown/podman-events.1.md) |
| `docker system info` | [`podman system info`](./docs/source/markdown/podman-system-info.1.md) |
| `docker system prune` | [`podman system prune`](./docs/source/markdown/podman-system-prune.1.md)|
| `docker tag` | [`podman tag`](./docs/source/markdown/podman-tag.1.md) |
Expand Down