List queries containerd client to get image list and only returns those matching given filters. Supported filters: - before= [: ]: Images created before given image (exclusive) - since= [: ]: Images created after given image (exclusive) - label= [= ]: Matches images ba
(ctx context.Context, client *containerd.Client, filters, nameAndRefFilter []string)
| 71 | // while the remaining filters are only applied after getting images from containerd, |
| 72 | // which means that having nameAndRefFilter may speed up the process if there are a lot of images in containerd. |
| 73 | func List(ctx context.Context, client *containerd.Client, filters, nameAndRefFilter []string) ([]images.Image, error) { |
| 74 | var imageStore = client.ImageService() |
| 75 | imageList, err := imageStore.List(ctx, nameAndRefFilter...) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | if len(filters) > 0 { |
| 80 | f, err := imgutil.ParseFilters(filters) |
| 81 | if err != nil { |
| 82 | return nil, err |
| 83 | } |
| 84 | |
| 85 | filters := []imgutil.Filter{} |
| 86 | if f.Dangling != nil && *f.Dangling { |
| 87 | filters = append(filters, imgutil.FilterDanglingImages()) |
| 88 | } else if f.Dangling != nil { |
| 89 | filters = append(filters, imgutil.FilterTaggedImages()) |
| 90 | } |
| 91 | |
| 92 | if len(f.Labels) > 0 { |
| 93 | filters = append(filters, imgutil.FilterByLabel(ctx, client, f.Labels)) |
| 94 | } |
| 95 | |
| 96 | if len(f.Reference) > 0 { |
| 97 | filters = append(filters, imgutil.FilterByReference(f.Reference)) |
| 98 | } |
| 99 | |
| 100 | if len(f.Before) > 0 || len(f.Since) > 0 { |
| 101 | filters = append(filters, imgutil.FilterByCreatedAt(ctx, client, f.Before, f.Since)) |
| 102 | } |
| 103 | |
| 104 | imageList, err = imgutil.ApplyFilters(imageList, filters...) |
| 105 | if err != nil { |
| 106 | return []images.Image{}, err |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | sort.Slice(imageList, func(i, j int) bool { |
| 111 | return imageList[i].CreatedAt.After(imageList[j].CreatedAt) |
| 112 | }) |
| 113 | return imageList, nil |
| 114 | } |
| 115 | |
| 116 | type imagePrintable struct { |
| 117 | // TODO: "Containers" |
no test coverage detected
searching dependent graphs…