Skip to content

Image filters#40584

Open
kvega005 wants to merge 18 commits into
microsoft:masterfrom
kvega005:imageFilters
Open

Image filters#40584
kvega005 wants to merge 18 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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 on lines 714 to 718

// Image management.
HRESULT PullImage([in] LPCSTR Image, [in, unique] LPCSTR RegistryAuthenticationInformation, [in, unique] IProgressCallback* ProgressCallback);
HRESULT BuildImage([in] const WSLCBuildImageOptions* Options, [in, unique] IProgressCallback* ProgressCallback, [in, unique, system_handle(sh_event)] HANDLE CancelEvent);
HRESULT LoadImage([in] WSLCHandle ImageHandle, [in, unique] IProgressCallback* ProgressCallback, [in] ULONGLONG ContentLength);
Copilot AI review requested due to automatic review settings May 19, 2026 21:08
@kvega005 kvega005 marked this pull request as ready for review May 19, 2026 21:09
@kvega005 kvega005 requested a review from a team as a code owner May 19, 2026 21:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.
/*++

THROW_HR_IF_MSG(
E_INVALIDARG,
WI_IsAnyFlagSet(static_cast<WSLCListImagesFlags>(Options->Flags), ~WSLCListImagesFlagsValid),
"Invalid flags: 0x%x",
Comment thread src/windows/wslcsession/WSLCSession.cpp
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.

2 participants