Skip to content

how to reuse only the "get images" logic of image.List #1855

@davidhsingyuchen

Description

@davidhsingyuchen

What is the problem you're trying to solve

Currently image.List contains 2 steps:

  1. Get the images according to the filters.
  2. Print the images.

It'd be nice to have an exported function that only does the first step. The detailed rationale is very similar to #1837 (comment), and this time instead of directly creating a PR, I think opening an issue first probably makes more sense.

Describe the solution you'd like

Looking at the fields of types.ImageListCommandOptions, many of them are only needed by 2. Print the images, so maybe we can create a new function and make it only depend on the things it needs:

func ListTheNewFunc(ctx context.Context, namespace, address string, Filters, NameAndRefFilter []string) ([]images.Image, error)

or maybe it can just take a *containerd.Client as the caller of this function can be potentially a long-running process, and it can call clientutil.NewClient itself to instantiate the client only once during process initialization:

func ListTheNewFunc(ctx context.Context, client *containerd.Client, Filters, NameAndRefFilter []string) ([]images.Image, error)

I don't have a perfect name in mind for the new function, so I just use ListTheNewFunc as a placeholder, and I'm not even sure if creating a new function makes sense to you, and I appreciate any suggestion, thanks!

Additional context

I'm more than happy to work on this as long as the community reaches a consensus on the approach.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions