Skip to content

Add --filter label support to container ls (#2403) - #2435

Open
kavix wants to merge 2 commits into
apple:mainfrom
kavix:issue-2403-ls-label-filter
Open

kavix wants to merge 2 commits into
apple:mainfrom
kavix:issue-2403-ls-label-filter

Conversation

@kavix

@kavix kavix commented Oct 27, 2026

Copy link
Copy Markdown

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Closes #2403.

This PR adds Docker-compatible label filtering to container ls / container list via -f, --filter:

  • Supports label presence filtering: --filter label=key / -f label=key
  • Supports literal key-value filtering: --filter label=key=value / -f label=key=value
  • Supports repeating --filter multiple times (logical AND)
  • Escapes regex special characters in label values (e.g. 1.0.0, foo+bar) to ensure literal matching across the API
  • Applies client-side validation to accurately handle absent labels vs. empty-string labels (key="")
  • Rejects unsupported filter types and malformed inputs with clear validation errors
  • Preserves running/all container status selection (--all / -a) and machine exclusion (.withoutMachines())
  • Updates docs/command-reference.md
  • Adds unit tests covering argument parsing, syntax validation, and container matching

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

kavix added 2 commits October 27, 2026 20:49
- Add `-f, --filter` option to `container ls` / `container list`
  supporting `label=key` (presence) and `label=key=value` (exact match).
- Escape special regex characters in label values to guarantee literal
  matching against the daemon API.
- Apply client-side refinement to handle absent vs. empty labels accurately.
- Preserve running/all status filtering and machine exclusion.
- Add comprehensive unit tests in ContainerListTests covering flag parsing,
  filter syntax validation, and container matching.
- Update command-reference documentation for container list.

Fixes apple#2403

Signed-off-by: kavix <kavix@yahoo.com>
Signed-off-by: kavix <kavix@yahoo.com>
labels: serverLabels
).withoutMachines()

let containers = try await client.list(filters: filters)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the parser and matching tests cover a good range of label values, including regex-special characters. the one path they don't exercise is the server-side filter sent through client.list. an integration test for that request would be useful to verify that the anchored expression matches the service's filtering behavior.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request]: container ls --filter label=key=value

2 participants