Skip to content

refactor: extract main logic of image.List#1923

Merged
Zheaoli merged 1 commit into
containerd:mainfrom
davidhsingyuchen:reuse-image-list
Feb 20, 2023
Merged

refactor: extract main logic of image.List#1923
Zheaoli merged 1 commit into
containerd:mainfrom
davidhsingyuchen:reuse-image-list

Conversation

@davidhsingyuchen
Copy link
Copy Markdown
Contributor

@davidhsingyuchen davidhsingyuchen commented Jan 24, 2023

Fix #1855.

The naming pattern of ListCommandHandler (i.e., called by cmd/nerdctl) and List (i.e., contains "main logic") come from #1855 (comment). If this PR makes sense to you, to make the naming consistent, I can create a one-shot PR to rename all functions to be XXXCommandHandler according to #1855 (comment).

Notes:

  • The function comment of List comes from command reference. Not 100% sure about the comment of nameAndRefFilter, please let me know if it's inaccurate, thanks!

Signed-off-by: Hsing-Yu (David) Chen davidhsingyuchen@gmail.com

@davidhsingyuchen davidhsingyuchen marked this pull request as ready for review January 24, 2023 21:03
Comment thread pkg/cmd/image/list.go
Comment on lines +54 to +53
imageList, err := List(ctx, client, options.Filters, options.NameAndRefFilter)
if err != nil {
return err
}
return printImages(ctx, client, imageList, options)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given that line 49-53 (client creation) will be moved to cmd side, I wonder if we should just export printImages (i.e. -> PrintImages) and let cmd.imagesAction first call List below and then call PrintImages to print.

I'm also okay to have the ListCommandHandler (naming wise, maybe just ListHandler, or ListAndPrint?) as a wrapper of the two logic (list and print).

WDYT @Zheaoli @AkihiroSuda

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

and then call PrintImages to print.

If we take this route, maybe we also want to make it consistent across all the commands (i.e., if there's anything to print, cmd/nerdctl/X_Y.go should call PrintXXX exported by pkd/cmd/X/Y.go to do so).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

let cmd.imagesAction first call List below and then call PrintImages to print.

Also, if there's no single entrypoint for cmd.imagesAction to call, should we pass the whole types.ImageListOptions to both List and PrintImages? Some fields in types.ImageListOptions are only relevant to List, and some of them are only relevant to PrintImages.

@davidhsingyuchen davidhsingyuchen force-pushed the reuse-image-list branch 2 times, most recently from 776e9ff to e7342d0 Compare January 27, 2023 21:55
@davidhsingyuchen
Copy link
Copy Markdown
Contributor Author

Rebased on main to resolve merge conflicts and updated PR description accordingly.

Comment thread pkg/cmd/image/list.go
func List(ctx context.Context, client *containerd.Client, options types.ImageListOptions) error {
var imageStore = client.ImageService()
imageList, err := imageStore.List(ctx, options.NameAndRefFilter...)
func ListCommandHandler(ctx context.Context, client *containerd.Client, options types.ImageListOptions) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a comment here? Something like

// ListCommandHandler `List` and print images matching filters in `options`.

Signed-off-by: Hsing-Yu (David) Chen <davidhsingyuchen@gmail.com>
@djdongjin djdongjin requested a review from AkihiroSuda February 2, 2023 01:45
@djdongjin djdongjin requested a review from Zheaoli February 16, 2023 16:58
Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda added this to the v1.2.1 milestone Feb 18, 2023
Copy link
Copy Markdown
Member

@Zheaoli Zheaoli left a comment

Choose a reason for hiding this comment

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

LGTM

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants