mirror of
https://github.com/containers/podman.git
synced 2025-10-11 16:26:00 +08:00
Merge pull request #26720 from TusharMohapatra07/main
`feat:` add support for label filter with key only
This commit is contained in:
@ -99,7 +99,7 @@ filters are supported:
|
||||
| container | [Name or ID] Container's name or ID |
|
||||
| event | event_status (described above) |
|
||||
| image | [Name or ID] Image name or ID |
|
||||
| label | [key=value] label |
|
||||
| label | [key] or [key=value] label |
|
||||
| pod | [Name or ID] Pod name or ID |
|
||||
| volume | [Name or ID] Volume name or ID |
|
||||
| type | Event_type (described above) |
|
||||
|
@ -67,14 +67,20 @@ func generateEventFilter(filter, filterValue string) (func(e *Event) bool, error
|
||||
var found bool
|
||||
// iterate labels and see if we match a key and value
|
||||
for eventKey, eventValue := range e.Attributes {
|
||||
filterValueSplit := strings.SplitN(filterValue, "=", 2)
|
||||
// if the filter isn't right, just return false
|
||||
if len(filterValueSplit) < 2 {
|
||||
return false
|
||||
}
|
||||
if eventKey == filterValueSplit[0] && eventValue == filterValueSplit[1] {
|
||||
found = true
|
||||
break
|
||||
filterKey, filterVal, hasValue := strings.Cut(filterValue, "=")
|
||||
// match "key=value" or "key"
|
||||
if !hasValue {
|
||||
// match by key only
|
||||
if eventKey == filterKey {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
} else {
|
||||
// match by key and value
|
||||
if eventKey == filterKey && eventValue == filterVal {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return found
|
||||
|
@ -28,6 +28,10 @@ load helpers.network
|
||||
run_podman events --since "$before" --filter type=container --filter container=$cname --filter event=start --stream=false
|
||||
is "$output" "$expect" "filtering just by container"
|
||||
|
||||
# Filter just by label key (without value)
|
||||
run_podman events --since "$before" --filter type=container --filter label=${labelname} --filter event=start --stream=false
|
||||
is "$output" "$expect" "filtering by label key only"
|
||||
|
||||
# check --no-trunc=false
|
||||
truncID=${id:0:12}
|
||||
run_podman events --since "$before" --filter container=$cname --filter event=start --stream=false --no-trunc=false
|
||||
|
Reference in New Issue
Block a user