Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #345 from yanxuean/imagereadiness
Browse files Browse the repository at this point in the history
check image readiness when recover
  • Loading branch information
Random-Liu committed Oct 23, 2017
2 parents 70023a3 + 9d06ac0 commit 698f0ea
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions pkg/server/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import (
"github.com/containerd/containerd"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
containerdimages "github.com/containerd/containerd/images"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/snapshot"
"github.com/containerd/typeurl"
"github.com/docker/distribution/reference"
"github.com/docker/docker/pkg/system"
Expand Down Expand Up @@ -96,7 +99,7 @@ func (c *criContainerdService) recover(ctx context.Context) error {
if err != nil {
return fmt.Errorf("failed to list images: %v", err)
}
images, err := loadImages(ctx, cImages, c.client.ContentStore())
images, err := loadImages(ctx, cImages, c.client.ContentStore(), c.client.SnapshotService(c.config.ContainerdConfig.Snapshotter))
if err != nil {
return fmt.Errorf("failed to load images: %v", err)
}
Expand Down Expand Up @@ -325,7 +328,8 @@ func loadSandbox(ctx context.Context, cntr containerd.Container) (sandboxstore.S
// loadImages loads images from containerd.
// TODO(random-liu): Check whether image is unpacked, because containerd put image reference
// into store before image is unpacked.
func loadImages(ctx context.Context, cImages []containerd.Image, provider content.Provider) ([]imagestore.Image, error) {
func loadImages(ctx context.Context, cImages []containerd.Image, provider content.Provider,
snapshotter snapshot.Snapshotter) ([]imagestore.Image, error) {
// Group images by image id.
imageMap := make(map[string][]containerd.Image)
for _, i := range cImages {
Expand All @@ -342,6 +346,16 @@ func loadImages(ctx context.Context, cImages []containerd.Image, provider conten
// imgs len must be > 0, or else the entry will not be created in
// previous loop.
i := imgs[0]
ok, _, _, _, err := containerdimages.Check(ctx, provider, i.Target(), platforms.Default())
if err != nil {
glog.Errorf("Failed to check image content readiness for %q: %v", i.Name(), err)
continue
}
if !ok {
glog.Warningf("The image content readiness for %q is not ok", i.Name())
continue
}

info, err := getImageInfo(ctx, i, provider)
if err != nil {
glog.Warningf("Failed to get image info for %q: %v", i.Name(), err)
Expand Down Expand Up @@ -373,6 +387,12 @@ func loadImages(ctx context.Context, cImages []containerd.Image, provider conten
glog.Warningf("Invalid image reference %q", name)
}
}

// Checking existence of top-level snapshot for each image being recovered.
if _, err := snapshotter.Stat(ctx, image.ChainID); err != nil {
glog.Warningf("Failed to stat the top-level snapshot for image %+v: %v", image, err)
continue
}
images = append(images, image)
}
return images, nil
Expand Down

0 comments on commit 698f0ea

Please sign in to comment.