Skip to content

containerd integration: add support for since,before,labels images filters#43816

Merged
thaJeztah merged 2 commits intomoby:masterfrom
thaJeztah:image_filters
Jul 21, 2022
Merged

containerd integration: add support for since,before,labels images filters#43816
thaJeztah merged 2 commits intomoby:masterfrom
thaJeztah:image_filters

Conversation

@thaJeztah
Copy link
Member

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added this to the v-next milestone Jul 15, 2022
@thaJeztah thaJeztah force-pushed the image_filters branch 2 times, most recently from c0e6854 to 49e8b7d Compare July 19, 2022 07:52
@thaJeztah thaJeztah marked this pull request as ready for review July 19, 2022 07:53
@thaJeztah
Copy link
Member Author

Rebased, because #43815 was merged

Copy link
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

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

I was looking at https://github.com/moby/moby/blob/2fbc30739b437d91f7a444f49143305e5f0a303e/daemon/images/image_list.go hoping we could have some overlapping implementation here but saw quickly that the filtering is integral to the list generation itself over there, so I guess not so much. 😅

I do wonder (as a user of many systems with an extremely prolific number of images on them) how well this implementation will scale -- I guess the other way to put that is that this is probably somewhere the containerd API perhaps needs some changes for batching/streaming/"iterator" of the image list instead of returning the full list of objects in a single call. 😇 🙈

@thaJeztah
Copy link
Member Author

I guess the other way to put that is that this is probably somewhere the containerd API perhaps needs some changes for batching/streaming/"iterator" of the image list instead of returning the full list of objects in a single call. 😇 🙈

Yes, I think we should look if this can be implemented in upstream containerd somehow; I agree that the current approach is not ideal (sending a lot of info over the wire, and filtering after the fact)

@thaJeztah
Copy link
Member Author

@corhere @cpuguy83 PTAL


// Images returns a filtered list of images.
func (i *ImageService) Images(ctx context.Context, opts types.ImageListOptions) ([]*types.ImageSummary, error) {
imgs, err := i.client.ListImages(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

You can probably do the filters as fieldpaths in this call.

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/containerd/containerd/blob/main/filters/filter.go

Doing the date comparison is not possible today, but most things should be.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that looks interesting indeed. Will have to dig into that a bit to see how to integrate it (I'm mostly upstreaming patches here 😂)

what's your preference? trying to make that work before we merge this, or improve in a follow-up?

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with it as is, let's maybe make sure to note though that the implementation needs work.

Copy link
Member Author

Choose a reason for hiding this comment

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

return ret, nil
}

func (i *ImageService) setupFilters(ctx context.Context, opts types.ImageListOptions) ([]imageFilterFunc, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (i *ImageService) setupFilters(ctx context.Context, opts types.ImageListOptions) ([]imageFilterFunc, error) {
func (i *ImageService) setupFilters(ctx context.Context, opts types.ImageListOptions) (imageFilterFunc, error) {
return func(image containerd.Image) bool {
        for _, filter := range filters {
                if !filter(image) {
                    return false
                }
        }
        return true
}, nil

There is only one filter. It may have more than one clause, but they're all logically parts of one filter. The caller of setupFilters shouldn't need to care how the filter is implemented; returning a slice of filter clauses just opens up opportunities for the calling code to evaluate the filter incorrectly (e.g. by ORing the clauses when they should be ANDed).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion; I was also looking at that.

  • I updated the function as suggested
  • Changed the signature to accept filters.Args instead of the whole ImageListOptions
  • I moved the i.setupFilters() invocation to the start of the function, as parsing the filters should be less work than first fetching all images (only to return an error if there's an issue with constructing the filters)
  • I added a second commit to validate the filters (as not all filters are implemented yet)
  • Created some tracking issues for that; see containerd integration: add support for since,before,labels images filters #43816 (comment)

ndeloof and others added 2 commits July 21, 2022 11:14
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Not all filters are implemented yet, so make sure an error
is returned if a not-yet implemented filter is used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
Copy link
Member Author

Interesting failure on Windows (could be just a hiccup) https://github.com/moby/moby/runs/7446210210?check_suite_focus=true

Install-Package : No match was found for the specified search criteria and 
package name '7Zip4PowerShell'. Try Get-PackageSource to see all available 
registered package sources.
At line:1 char:3109
+ ... ownloading containerd; Install-Package -Force 7Zip4PowerShell; $locat ...
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPacka 
   ge:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.Pac 
   kageManagement.Cmdlets.InstallPackage

@thaJeztah
Copy link
Member Author

I'm gonna ignore the TestRunInteractiveWithRestartPolicy failure on windows as we know it's unrelated and flaky

@thaJeztah thaJeztah merged commit e3a18e1 into moby:master Jul 21, 2022
@thaJeztah thaJeztah deleted the image_filters branch July 21, 2022 19:45
crazy-max pushed a commit to crazy-max/moby that referenced this pull request Sep 29, 2022
containerd integration: add support for since,before,labels images filters
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/images Image Distribution containerd-integration Issues and PRs related to containerd integration status/2-code-review

Projects

Development

Successfully merging this pull request may close these issues.

5 participants