Skip to content

daemon/containerd: fix label!= filter ignoring images without label#52338

Merged
vvoland merged 1 commit intomoby:masterfrom
sahilsGit:52334-fix-label-negation-filter
Apr 16, 2026
Merged

daemon/containerd: fix label!= filter ignoring images without label#52338
vvoland merged 1 commit intomoby:masterfrom
sahilsGit:52334-fix-label-negation-filter

Conversation

@sahilsGit
Copy link
Copy Markdown
Contributor

@sahilsGit sahilsGit commented Apr 10, 2026

What changed

  • Fixed a logic bug in setupLabelFilter (daemon/containerd/image_list.go) where negated filter checks (label!=key=value) incorrectly failed when the image was missing the label entirely.
  • Modified the filter condition so that if a label is missing, we evaluate whether it's a negated check before deciding to early return.
  • Added a comprehensive regression test suite (TestSetupLabelFilterNegativeValue) into a new prune_test.go file.

Why
Prior to this fix, the containerd setupLabelFilter logic treated a missing label as a non-match regardless of whether the filter was negated. This caused commands like docker image prune --filter label!=key=value to silently skip images that don't have the label at all. Since containerd-snapshotter is enabled by default in Docker 29+, this caused a regression in pruning behavior where images lacking a key inexplicably failed to be deleted.

Validation

  • Manually verified docker image prune -a --force --filter 'label!=on_prune=keep' correctly reclaims space and deletes the image on the containerd backend.
  • Verified all newly added regression tests in image_labelfilter_test.go pass successfully:
    • label!=key=value correctly matches images missing the label.
    • label=key=value correctly does not match images missing the label.
    • label!=key=other correctly matches images with the key but a different value.
containerd image store: Fix `docker image prune --filter label!=key=value` incorrectly skipping images that don't have the specified label.

@github-actions github-actions Bot added area/daemon Core Engine containerd-integration Issues and PRs related to containerd integration labels Apr 10, 2026
Copy link
Copy Markdown
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

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

Thanks! A couple of suggestions

Comment thread daemon/containerd/image_labelfilter_test.go Outdated
Comment thread daemon/containerd/image_labelfilter_test.go Outdated
@sahilsGit sahilsGit force-pushed the 52334-fix-label-negation-filter branch from fc9a5d7 to 5ceaf41 Compare April 10, 2026 16:20
@github-actions github-actions Bot added area/testing area/images Image Distribution labels Apr 10, 2026
Comment thread integration/image/prune_test.go Outdated
@vvoland vvoland added this to the 29.4.1 milestone Apr 10, 2026
@sahilsGit sahilsGit force-pushed the 52334-fix-label-negation-filter branch from 5ceaf41 to c82009a Compare April 13, 2026 11:07
@sahilsGit sahilsGit requested a review from vvoland April 13, 2026 11:15
Copy link
Copy Markdown
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

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

Failure related:

=== FAIL: amd64.integration-cli TestDockerDaemonSuite/TestPruneImageLabel (21.40s)
    docker_cli_prune_unix_test.go:312: assertion failed: strings.Contains(strings.TrimSpace(out), id2) is true
    --- FAIL: TestDockerDaemonSuite/TestPruneImageLabel (21.40s)

Comment thread integration/image/prune_test.go Outdated
Comment thread integration/image/prune_test.go Outdated
@sahilsGit sahilsGit force-pushed the 52334-fix-label-negation-filter branch 2 times, most recently from 949c8dd to 5a46906 Compare April 16, 2026 06:39
@sahilsGit sahilsGit requested a review from vvoland April 16, 2026 07:19
Copy link
Copy Markdown
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

Prior to this fix, setupLabelFilter treated a missing label as a
non-match regardless of whether the filter was negated. This caused
'docker image prune --filter label!=key=value' to silently skip images
that don't have the label at all, even though those images clearly do
not have label=value and should be pruned.

The fix: when a label is absent and the check is negated (label!=),
we continue instead of returning nil, allowing the image to match.
For non-negated checks (label=), the existing early-return is kept.

A regression test is added in prune_test.go covering:
- label!=key=value matches images without the label
- label=key=value does NOT match images without the label

Signed-off-by: Sahil Singh <sahiilsiingh37@gmail.com>
@thaJeztah thaJeztah force-pushed the 52334-fix-label-negation-filter branch from 5a46906 to d994daf Compare April 16, 2026 13:54
@vvoland vvoland merged commit 3dc2075 into moby:master Apr 16, 2026
57 checks passed
@rrjjvv
Copy link
Copy Markdown

rrjjvv commented Apr 20, 2026

@vvoland @thaJeztah, on the surface, this appears to address one of my earlier reports in #50618; I'll verify when I get chance if you guys don't confirm and/or close first.

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

Labels

area/daemon Core Engine area/images Image Distribution ci/validate-only containerd-integration Issues and PRs related to containerd integration impact/changelog kind/bugfix PR's that fix bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker image prune ignores label!= filter on Docker 29+

4 participants