MCPcopy Create free account
hub / github.com/containerd/containerd / CheckImages

Method CheckImages

internal/cri/server/images/check.go:32–74  ·  view source on GitHub ↗

CheckImages checks all existing images to ensure they are ready to be used for CRI. It may try to recover images which are not ready but will only log errors, not return any.

(ctx context.Context)

Source from the content-addressed store, hash-verified

30// be used for CRI. It may try to recover images which are not ready
31// but will only log errors, not return any.
32func (c *CRIImageService) CheckImages(ctx context.Context) error {
33 // TODO: Move way from `client.ListImages` to directly using image store
34 cImages, err := c.client.ListImages(ctx)
35 if err != nil {
36 return fmt.Errorf("unable to list images: %w", err)
37 }
38
39 // TODO: Support all snapshotter
40 snapshotter := c.config.Snapshotter
41 var wg sync.WaitGroup
42 for _, i := range cImages {
43 wg.Go(func() {
44 // TODO: Check platform/snapshot combination. Snapshot check should come first
45 ok, _, _, _, err := images.Check(ctx, i.ContentStore(), i.Target(), platforms.Default())
46 if err != nil {
47 log.G(ctx).WithError(err).Errorf("Failed to check image content readiness for %q", i.Name())
48 return
49 }
50 if !ok {
51 log.G(ctx).Warnf("The image content readiness for %q is not ok", i.Name())
52 return
53 }
54 // Checking existence of top-level snapshot for each image being recovered.
55 // TODO: This logic should be done elsewhere and owned by the image service
56 unpacked, err := i.IsUnpacked(ctx, snapshotter)
57 if err != nil {
58 log.G(ctx).WithError(err).Warnf("Failed to check whether image is unpacked for image %s", i.Name())
59 return
60 }
61 if !unpacked {
62 log.G(ctx).Warnf("The image %s is not unpacked.", i.Name())
63 // TODO(random-liu): Consider whether we should try unpack here.
64 }
65 if err := c.UpdateImage(ctx, i.Name()); err != nil {
66 log.G(ctx).WithError(err).Warnf("Failed to update reference for image %q", i.Name())
67 return
68 }
69 log.G(ctx).Debugf("Loaded image %q", i.Name())
70 })
71 }
72 wg.Wait()
73 return nil
74}

Callers

nothing calls this directly

Calls 8

UpdateImageMethod · 0.95
CheckFunction · 0.92
ListImagesMethod · 0.65
ContentStoreMethod · 0.65
TargetMethod · 0.65
NameMethod · 0.65
IsUnpackedMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected