filterImagesByExistence returns the subset of images that exist in the engine store. NOTE: Any transient errors communicating with the API will result in an image being returned as "existing", as this method is exclusively used to find images to remove, so the worst case of being conservative here
(ctx context.Context, imageNames []string)
| 192 | // attempt to remove an image that doesn't exist, which will cause a warning |
| 193 | // but is otherwise harmless. |
| 194 | func (p *ImagePruner) filterImagesByExistence(ctx context.Context, imageNames []string) ([]string, error) { |
| 195 | var mu sync.Mutex |
| 196 | var ret []string |
| 197 | |
| 198 | eg, ctx := errgroup.WithContext(ctx) |
| 199 | for _, img := range imageNames { |
| 200 | eg.Go(func() error { |
| 201 | _, err := p.client.ImageInspect(ctx, img) |
| 202 | if errdefs.IsNotFound(err) { |
| 203 | // err on the side of caution: only skip if we successfully |
| 204 | // queried the API and got back a definitive "not exists" |
| 205 | return nil |
| 206 | } |
| 207 | mu.Lock() |
| 208 | defer mu.Unlock() |
| 209 | ret = append(ret, img) |
| 210 | return nil |
| 211 | }) |
| 212 | } |
| 213 | |
| 214 | if err := eg.Wait(); err != nil { |
| 215 | return nil, err |
| 216 | } |
| 217 | |
| 218 | return ret, nil |
| 219 | } |
| 220 | |
| 221 | // normalizeAndDedupeImages returns the unique set of images after normalization. |
| 222 | func normalizeAndDedupeImages(images []string) []string { |
no test coverage detected