podman events --filter network=<name> always fails with "NETWORK is an invalid filter"
Issue Description
When trying to filter podman events by network name or ID (e.g., podman events --filter network=mynet), the command unconditionally fails with the error Error: NETWORK is an invalid filter.
This seems to be an oversight in the event filtering logic. The Network event type is fully defined (Network Type = "network" in libpod/events/config.go), and network events like connect and disconnect are successfully emitted. However, the NETWORK case is completely missing from the generateEventFilter switch statement in libpod/events/filters.go.
Steps to reproduce the issue
Steps to reproduce the issue 1.1. Create a dummy network and start a container on it:
podman network create mynet
podman run -d --name mytest --network mynet alpine sleep 300
2.Try to filter the events by the network name:
podman events --filter network=mynet --no-stream
Describe the results you received
The command immediately errors out:
Error: NETWORK is an invalid filter
Describe the results you expected
It should return the network events (like connect and disconnect) that match the given network name or ID prefix, which would match Docker's behavior for --filter network=....
If you run podman events --no-stream --type network (without the specific name filter), you can see that the events are being tracked perfectly fine, we just can't filter them by name.
podman info output
Client: Podman Engine
Version: 5.0.0 (or current main branch)
API Version: 5.0.0
OS/Arch: linux/amd64
Root Cause & Proposed Fix
In libpod/events/filters.go, the generateEventFilter function has cases for CONTAINER, IMAGE, POD, VOLUME, etc., but no NETWORK case. Anything falling through the switch statement returns fmt.Errorf("%s is an invalid filter", filter).
It looks like we just need to add the missing case to generateEventFilter in libpod/events/filters.go:
case "NETWORK":
return func(e *Event) bool {
if e.Type != Network {
return false
}
// Prefix match with name or ID for consistency
if e.Network == filterValue {
return true
}
return strings.HasPrefix(e.ID, filterValue)
}, nil
Podman in a container
No
Privileged Or Rootless
Rootless
Upstream Latest Release
Yes
I have identified the root cause of this issue and have a verified fix ready.
Cause:
- The
NETWORKfilter casing is missing in thegenerateEventFilterswitch statement insidelibpod/events/filters.go. Because of this, any attempt to filter events bynetworkimmediately hits the fallback error handler.
Solution & Optimization:
-
Filter Support: Added a
case "NETWORK"ingenerateEventFilterto match network events by name or ID prefix:case "NETWORK": return func(e *Event) bool { if e.Type != Network { return false } if e.Name == filterValue { return true } return strings.HasPrefix(e.ID, filterValue) }, nil