Skip to content

Support '!=' operator in filters and record its usage #6035

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mohammedfuta2000
Copy link
Contributor

closes #6021
In Add() (vendor/github.com/docker/docker/api/types/filters/parse.go), we previously assigned args.fields[key][value] = true with "true" being a placeholder.

Now, it holds isEqualOp, a boolean indicating whether the filter uses = (true) or != (false). This enables us to distinguish between inclusion and exclusion filters.

The Set() function (opts/opts.go) has been updated to detect both = and != in filter strings, replacing the previous convention of using a trailing ! to indicate negation.

Update confirmationMessage() function (cli/command/system/prune.go) to include isEqualOp value in print out for prune command.

The daemon is to be updated this issue to support exclusionary filters.

In `Add()` (vendor/github.com/docker/docker/api/types/filters/parse.go),
we previously assigned `args.fields[key][value] = true` with "true" being a placeholder.

Now, it holds `isEqualOp`, a boolean indicating whether the
filter uses `=` (true) or `!=` (false). This enables us to distinguish
between inclusion and exclusion filters.

The `Set()` function (opts/opts.go) has been updated to detect both
`=` and `!=` in filter strings, replacing the previous convention of
using a trailing `!` to indicate negation.

Update `confirmationMessage()` function (cli/command/system/prune.go)
to include isEqualOp value in print out for prune command.

The daemon is to be updated [this issue](moby/moby#13533) to support exclusionary filters.

Signed-off-by: Mohammed Aminu Futa <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2025

Codecov Report

Attention: Patch coverage is 38.88889% with 11 lines in your changes missing coverage. Please review.

Project coverage is 58.89%. Comparing base (4eba377) to head (a88a98a).
Report is 24 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6035   +/-   ##
=======================================
  Coverage   58.89%   58.89%           
=======================================
  Files         358      358           
  Lines       29962    30001   +39     
=======================================
+ Hits        17647    17670   +23     
- Misses      11334    11350   +16     
  Partials      981      981           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +133 to +137
func (args Args) Add(key, value string, isEqualOps ...bool) {
isEqualOp := true
if len(isEqualOps) > 0 {
isEqualOp = isEqualOps[0]
}
Copy link
Member

Choose a reason for hiding this comment

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

This code is in a vendored file; it's code that's maintained in the https://github.com/moby/moby repository, and should not be modified here, but in upstream; https://github.com/moby/moby/blob/b466483877ee8047e33c66ad05b857b0340b81e4/api/types/filters/parse.go#L126-L133

The trickier bit here is that these are part of the API, so changing the format could require versioning to make sure that things don't break with a new CLI connecting to an older API version (or vice-versa)

Copy link
Contributor Author

@mohammedfuta2000 mohammedfuta2000 Apr 24, 2025

Choose a reason for hiding this comment

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

Seen it. thanks
yes versioning will be required. I've some suggestion for updating the docker daemon here(moby/moby#13533)

mohammedfuta2000 added a commit to mohammedfuta2000/moby that referenced this pull request Apr 25, 2025
Introduced matchWithOperator to determine inclusionary (=) or exclusionary (!=) filtering based on CLI input, per changes in [this PR](docker/cli#6035).

Integrated it into Match, ExactMatch, UniqueExactMatch, and FuzzyMatch functions

Also created GetPair Function and updated the Add function for use in the CLI update in the above PR

Signed-off-by: Mohammed Aminu Futa <[email protected]>
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.

--filter does not work with negatives anywhere other than prune
3 participants