Skip to content

Image filters - #40584

Merged
Kevin Vega (kvega005) merged 25 commits into
microsoft:masterfrom
kvega005:imageFilters
May 29, 2026
Merged

Image filters#40584
Kevin Vega (kvega005) merged 25 commits into
microsoft:masterfrom
kvega005:imageFilters

Conversation

@kvega005

Copy link
Copy Markdown
Contributor

This pull request refactors and simplifies how image listing and pruning filters are handled in the Windows Subsystem for Linux Containers (WSLC) service. It removes custom filter structures and flag enums in favor of using generic key-value filter arrays, making the API more flexible and closer to Docker's native filtering model. The changes also update related method signatures and test cases to match the new approach.

Key changes:

API and Data Structure Simplification

  • Replaced the WSLCListImageOptions and related filter fields (such as Reference, Before, Since, and Labels) with a generic WSLCListImagesOptions struct that uses an array of WSLCFilter key-value pairs for filters. The corresponding flags for dangling images were removed, and only the All and Digests flags remain valid. (src/windows/service/inc/wslc.idl, [1] [2]
  • Removed the WSLCPruneImagesFlags enum and WSLCPruneImagesOptions struct. The PruneImages method now directly takes an array of WSLCFilter key-value pairs, aligning its interface with the new filtering model. (src/windows/service/inc/wslc.idl, [1] [2]

Implementation Updates

  • Refactored the implementation of image listing and pruning in WSLCSession to use the new generic filter map, removing custom filter structs and flag logic. Filters are now parsed from the key-value array and passed directly to the Docker HTTP client. (src/windows/wslcsession/WSLCSession.cpp, [1] [2] [3]
  • Updated the DockerHTTPClient interface and implementation to accept filters as a std::map<std::string, std::vector<std::string>> instead of custom filter structs. Removed the now-unused filter conversion utility. (src/windows/wslcsession/DockerHTTPClient.h, [1]; src/windows/wslcsession/DockerHTTPClient.cpp, [2] [3] [4]

Test and Usage Updates

  • Modified tests and service usage to construct filters using the new WSLCFilter array approach instead of setting individual fields in the options struct. (test/windows/WSLCTests.cpp, [1] [2] [3]; src/windows/wslc/services/ImageService.cpp, [4]

Interface and Type Renaming

  • Renamed all references from WSLCListImageOptions to WSLCListImagesOptions and updated method signatures accordingly to maintain consistency. (src/windows/service/inc/wslc.idl, [1]; src/windows/wslcsession/WSLCSession.h, [2]; src/windows/wslcsession/WSLCSession.cpp, [3]

These changes make the WSLC image management API more flexible, maintainable, and consistent with Docker's own API conventions.

Summary of the Pull Request

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copilot AI review requested due to automatic review settings May 18, 2026 22:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors WSLC image list/prune filtering to use generic key/value filter arrays (closer to Docker’s filter model), removing bespoke option structs/flag enums and threading the new filter representation through the service, session, HTTP client, and tests.

Changes:

  • Replaced image list/prune option structs and dangling-related enums with WSLCFilter key/value arrays in the WSLC COM API.
  • Updated WSLCSession and DockerHTTPClient to pass filters as std::map<std::string, std::vector<std::string>> serialized into Docker’s filters query parameter.
  • Updated tests and ImageService call sites to construct and pass the new filter arrays.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/windows/WSLCTests.cpp Updates image list/prune tests to use WSLCFilter arrays instead of specialized options/flags.
src/windows/wslcsession/WSLCSession.h Updates IWSLCSession method signatures to use WSLCListImagesOptions and filter arrays for prune.
src/windows/wslcsession/WSLCSession.cpp Refactors ListImages/PruneImages to parse WSLCFilter arrays via ParseKeyMultiValuePairs and pass maps to Docker client.
src/windows/wslcsession/DockerHTTPClient.h Removes custom filter structs; updates ListImages/PruneImages to accept map<string, vector<string>>.
src/windows/wslcsession/DockerHTTPClient.cpp Serializes the generic filter map directly into Docker’s filters query parameter.
src/windows/wslc/services/ImageService.cpp Updates pruning to send dangling filter via WSLCFilter.
src/windows/service/inc/wslc.idl Updates IDL structs/enums and changes IWSLCSession method signatures for list/prune.
Comments suppressed due to low confidence (1)

src/windows/wslcsession/WSLCSession.cpp:1216

  • ListImages now explicitly rejects any flags outside WSLCListImagesFlagsValid (including the previously-supported dangling flags). There doesn't appear to be a corresponding test ensuring invalid/legacy flag bits return E_INVALIDARG, which is important to lock in the new contract and prevent regressions. Consider adding a test that calls ListImages with an invalid bit (or the removed dangling bits) and verifies it fails with E_INVALIDARG.
}

HRESULT WSLCSession::ListImages(const WSLCListImagesOptions* Options, WSLCImageInformation** Images, ULONG* Count)
try
{
    COMServiceExecutionContext context;

    RETURN_HR_IF_NULL(E_POINTER, Images);

Comment thread src/windows/service/inc/wslc.idl
Copilot AI review requested due to automatic review settings May 19, 2026 21:08
@kvega005
Kevin Vega (kvega005) marked this pull request as ready for review May 19, 2026 21:09
@kvega005
Kevin Vega (kvega005) requested a review from a team as a code owner May 19, 2026 21:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/windows/wslcsession/WSLCSession.cpp:1

  • Similar to ListImages, this calls ParseKeyMultiValuePairs(Filters, FiltersCount) without validating that Filters is non-null when FiltersCount > 0. If RPC/COM callers supply an inconsistent pointer/count pair, this can crash in-process. Add a guard (e.g., reject FiltersCount > 0 && Filters == nullptr) before parsing.
/*++

Comment thread src/windows/wslcsession/WSLCSession.cpp Outdated
Comment thread src/windows/wslcsession/WSLCSession.cpp
Comment thread src/windows/service/inc/wslc.idl
yao-msft
yao-msft previously approved these changes May 20, 2026

@yao-msft yao-msft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess we are leaving the filter key checks to moby engine and let the engine return error on unrecognized keys. Is this the direction we are going?

Copilot AI review requested due to automatic review settings May 22, 2026 17:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment on lines +856 to +857
WSLCFilter filter{.Key = "reference", .Value = "debian"};
WSLCListImagesOptions options{.Flags = WSLCListImagesFlagsNone, .Filters = &filter, .FiltersCount = 1};
OneBlue
Blue (OneBlue) previously approved these changes May 27, 2026

@OneBlue Blue (OneBlue) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. This is much cleaner than the previous approach.

Feel free to resolve the test comment in a followup PR

VERIFY_ARE_EQUAL(
m_defaultSession->PruneImages(&invalidOptions, deletedImages.addressof(), deletedImages.size_address<ULONG>(), &spaceReclaimed),
m_defaultSession->PruneImages(&bogus, 1, deletedImages.addressof(), deletedImages.size_address<ULONG>(), &spaceReclaimed),
E_INVALIDARG);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: We should add a check for the error message when invalid filters are passed (assuming that we get one from docker)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/windows/service/inc/wslc.idl
@kvega005
Kevin Vega (kvega005) merged commit 84284bf into microsoft:master May 29, 2026
9 checks passed
@kvega005
Kevin Vega (kvega005) deleted the imageFilters branch May 29, 2026 17:53
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.

5 participants