Skip to content

Commit

Permalink
filters: better handling of id=
Browse files Browse the repository at this point in the history
For filter=id=XXX (containers, pods) and =ctr-ids=XXX (pods):

  if XXX is only hex characters, treat it as a PREFIX
  otherwise, treat it as a REGEX

Add tests. Update documentation. And fix an incorrect help message.

Fixes: containers#18471

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago committed Jun 7, 2023
1 parent dd753c6 commit 992093a
Show file tree
Hide file tree
Showing 14 changed files with 327 additions and 133 deletions.
2 changes: 1 addition & 1 deletion cmd/podman/pods/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func sortPodPsOutput(sortBy string, lprs []*entities.ListPodsReport) error {
case "status":
sort.Sort(podPsSortedStatus{lprs})
default:
return errors.New("invalid option for --sort, options are: id, names, or number")
return errors.New("invalid option for --sort, options are: created, id, name, number, or status")
}
return nil
}
Expand Down
28 changes: 14 additions & 14 deletions docs/source/markdown/podman-pause.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ Filters with the same key work inclusive with the only exception being

Valid filters are listed below:

| **Filter** | **Description** |
| --------------- | -------------------------------------------------------------------------------- |
| id | [ID] Container's ID (accepts regex) |
| name | [Name] Container's name (accepts regex) |
| label | [Key] or [Key=Value] Label assigned to a container |
| exited | [Int] Container's exit code |
| status | [Status] Container's status: 'created', 'exited', 'paused', 'running', 'unknown' |
| ancestor | [ImageName] Image or descendant used to create container |
| before | [ID] or [Name] Containers created before this container |
| since | [ID] or [Name] Containers created since this container |
| volume | [VolumeName] or [MountpointDestination] Volume mounted in container |
| health | [Status] healthy or unhealthy |
| pod | [Pod] name or full or partial ID of pod |
| network | [Network] name or full ID of network |
| **Filter** | **Description** |
|------------|----------------------------------------------------------------------------------|
| id | [ID] Container's ID (CID prefix match by default; accepts regex) |
| name | [Name] Container's name (accepts regex) |
| label | [Key] or [Key=Value] Label assigned to a container |
| exited | [Int] Container's exit code |
| status | [Status] Container's status: 'created', 'exited', 'paused', 'running', 'unknown' |
| ancestor | [ImageName] Image or descendant used to create container |
| before | [ID] or [Name] Containers created before this container |
| since | [ID] or [Name] Containers created since this container |
| volume | [VolumeName] or [MountpointDestination] Volume mounted in container |
| health | [Status] healthy or unhealthy |
| pod | [Pod] name or full or partial ID of pod |
| network | [Network] name or full ID of network |

@@option latest

Expand Down
24 changes: 12 additions & 12 deletions docs/source/markdown/podman-pod-ps.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ The *filters* argument format is of `key=value`. If there is more than one *filt

Supported filters:

| Filter | Description |
| ---------- | -------------------------------------------------------------------------------------------------- |
| *ctr-ids* | Filter by container ID within the pod. |
| *ctr-names* | Filter by container name within the pod. |
| *ctr-number*| Filter by number of containers in the pod. |
| *ctr-status*| Filter by container status within the pod. |
| *id* | Filter by pod ID. |
| *label* | Filter by container with (or without, in the case of label!=[...] is used) the specified labels. |
| *name* | Filter by pod name. |
| *network* | Filter by network name or full ID of network. |
| *status* | Filter by pod status. |
| *until* | Filter by pods created before given timestamp. |
| Filter | Description |
|--------------|--------------------------------------------------------------------------------------------------|
| *ctr-ids* | Filter by container ID within the pod. (CID prefix match by default; accepts regex) |
| *ctr-names* | Filter by container name within the pod. |
| *ctr-number* | Filter by number of containers in the pod. |
| *ctr-status* | Filter by container status within the pod. |
| *id* | Filter by pod ID. (Prefix match by default; accepts regex) |
| *label* | Filter by container with (or without, in the case of label!=[...] is used) the specified labels. |
| *name* | Filter by pod name. |
| *network* | Filter by network name or full ID of network. |
| *status* | Filter by pod status. |
| *until* | Filter by pods created before given timestamp. |

The `ctr-ids`, `ctr-names`, `id`, `name` filters accept `regex` format.

Expand Down
28 changes: 14 additions & 14 deletions docs/source/markdown/podman-ps.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ Filters with the same key work inclusive with the only exception being

Valid filters are listed below:

| **Filter** | **Description** |
| --------------- | -------------------------------------------------------------------------------- |
| id | [ID] Container's ID (accepts regex) |
| name | [Name] Container's name (accepts regex) |
| label | [Key] or [Key=Value] Label assigned to a container |
| exited | [Int] Container's exit code |
| status | [Status] Container's status: 'created', 'exited', 'paused', 'running', 'unknown' |
| ancestor | [ImageName] Image or descendant used to create container (accepts regex) |
| before | [ID] or [Name] Containers created before this container |
| since | [ID] or [Name] Containers created since this container |
| volume | [VolumeName] or [MountpointDestination] Volume mounted in container |
| health | [Status] healthy or unhealthy |
| pod | [Pod] name or full or partial ID of pod |
| network | [Network] name or full ID of network |
| **Filter** | **Description** |
|------------|----------------------------------------------------------------------------------|
| id | [ID] Container's ID (CID prefix match by default; accepts regex) |
| name | [Name] Container's name (accepts regex) |
| label | [Key] or [Key=Value] Label assigned to a container |
| exited | [Int] Container's exit code |
| status | [Status] Container's status: 'created', 'exited', 'paused', 'running', 'unknown' |
| ancestor | [ImageName] Image or descendant used to create container (accepts regex) |
| before | [ID] or [Name] Containers created before this container |
| since | [ID] or [Name] Containers created since this container |
| volume | [VolumeName] or [MountpointDestination] Volume mounted in container |
| health | [Status] healthy or unhealthy |
| pod | [Pod] name or full or partial ID of pod |
| network | [Network] name or full ID of network |


#### **--format**=*format*
Expand Down
28 changes: 14 additions & 14 deletions docs/source/markdown/podman-restart.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ Filters with the same key work inclusive with the only exception being

Valid filters are listed below:

| **Filter** | **Description** |
| --------------- | -------------------------------------------------------------------------------- |
| id | [ID] Container's ID (accepts regex) |
| name | [Name] Container's name (accepts regex) |
| label | [Key] or [Key=Value] Label assigned to a container |
| exited | [Int] Container's exit code |
| status | [Status] Container's status: 'created', 'exited', 'paused', 'running', 'unknown' |
| ancestor | [ImageName] Image or descendant used to create container |
| before | [ID] or [Name] Containers created before this container |
| since | [ID] or [Name] Containers created since this container |
| volume | [VolumeName] or [MountpointDestination] Volume mounted in container |
| health | [Status] healthy or unhealthy |
| pod | [Pod] name or full or partial ID of pod |
| network | [Network] name or full ID of network |
| **Filter** | **Description** |
|------------|----------------------------------------------------------------------------------|
| id | [ID] Container's ID (CID prefix match by default; accepts regex) |
| name | [Name] Container's name (accepts regex) |
| label | [Key] or [Key=Value] Label assigned to a container |
| exited | [Int] Container's exit code |
| status | [Status] Container's status: 'created', 'exited', 'paused', 'running', 'unknown' |
| ancestor | [ImageName] Image or descendant used to create container |
| before | [ID] or [Name] Containers created before this container |
| since | [ID] or [Name] Containers created since this container |
| volume | [VolumeName] or [MountpointDestination] Volume mounted in container |
| health | [Status] healthy or unhealthy |
| pod | [Pod] name or full or partial ID of pod |
| network | [Network] name or full ID of network |

@@option latest

Expand Down
28 changes: 14 additions & 14 deletions docs/source/markdown/podman-rm.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ Filters with the same key work inclusive with the only exception being

Valid filters are listed below:

| **Filter** | **Description** |
| --------------- | -------------------------------------------------------------------------------- |
| id | [ID] Container's ID (accepts regex) |
| name | [Name] Container's name (accepts regex) |
| label | [Key] or [Key=Value] Label assigned to a container |
| exited | [Int] Container's exit code |
| status | [Status] Container's status: 'created', 'exited', 'paused', 'running', 'unknown' |
| ancestor | [ImageName] Image or descendant used to create container |
| before | [ID] or [Name] Containers created before this container |
| since | [ID] or [Name] Containers created since this container |
| volume | [VolumeName] or [MountpointDestination] Volume mounted in container |
| health | [Status] healthy or unhealthy |
| pod | [Pod] name or full or partial ID of pod |
| network | [Network] name or full ID of network |
| **Filter** | **Description** |
|------------|----------------------------------------------------------------------------------|
| id | [ID] Container's ID (CID prefix match by default; accepts regex) |
| name | [Name] Container's name (accepts regex) |
| label | [Key] or [Key=Value] Label assigned to a container |
| exited | [Int] Container's exit code |
| status | [Status] Container's status: 'created', 'exited', 'paused', 'running', 'unknown' |
| ancestor | [ImageName] Image or descendant used to create container |
| before | [ID] or [Name] Containers created before this container |
| since | [ID] or [Name] Containers created since this container |
| volume | [VolumeName] or [MountpointDestination] Volume mounted in container |
| health | [Status] healthy or unhealthy |
| pod | [Pod] name or full or partial ID of pod |
| network | [Network] name or full ID of network |

#### **--force**, **-f**

Expand Down
28 changes: 14 additions & 14 deletions docs/source/markdown/podman-start.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ Filters with the same key work inclusive with the only exception being

Valid filters are listed below:

| **Filter** | **Description** |
| --------------- | -------------------------------------------------------------------------------- |
| id | [ID] Container's ID (accepts regex) |
| name | [Name] Container's name (accepts regex) |
| label | [Key] or [Key=Value] Label assigned to a container |
| exited | [Int] Container's exit code |
| status | [Status] Container's status: 'created', 'exited', 'paused', 'running', 'unknown' |
| ancestor | [ImageName] Image or descendant used to create container |
| before | [ID] or [Name] Containers created before this container |
| since | [ID] or [Name] Containers created since this container |
| volume | [VolumeName] or [MountpointDestination] Volume mounted in container |
| health | [Status] healthy or unhealthy |
| pod | [Pod] name or full or partial ID of pod |
| network | [Network] name or full ID of network |
| **Filter** | **Description** |
|------------|----------------------------------------------------------------------------------|
| id | [ID] Container's ID (CID prefix match by default; accepts regex) |
| name | [Name] Container's name (accepts regex) |
| label | [Key] or [Key=Value] Label assigned to a container |
| exited | [Int] Container's exit code |
| status | [Status] Container's status: 'created', 'exited', 'paused', 'running', 'unknown' |
| ancestor | [ImageName] Image or descendant used to create container |
| before | [ID] or [Name] Containers created before this container |
| since | [ID] or [Name] Containers created since this container |
| volume | [VolumeName] or [MountpointDestination] Volume mounted in container |
| health | [Status] healthy or unhealthy |
| pod | [Pod] name or full or partial ID of pod |
| network | [Network] name or full ID of network |

@@option interactive

Expand Down
Loading

0 comments on commit 992093a

Please sign in to comment.