Merge pull request #379 from yanxuean/unpack

Use image.IsUnpacked
This commit is contained in:
Lantao Liu
2017-11-01 07:50:12 +01:00
committed by GitHub
27 changed files with 174 additions and 256 deletions

View File

@@ -28,7 +28,6 @@ import (
"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"
@@ -99,7 +98,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(), c.client.SnapshotService(c.config.ContainerdConfig.Snapshotter))
images, err := loadImages(ctx, cImages, c.client.ContentStore(), c.config.ContainerdConfig.Snapshotter)
if err != nil {
return fmt.Errorf("failed to load images: %v", err)
}
@@ -329,7 +328,7 @@ func loadSandbox(ctx context.Context, cntr containerd.Container) (sandboxstore.S
// 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,
snapshotter snapshot.Snapshotter) ([]imagestore.Image, error) {
snapshotter string) ([]imagestore.Image, error) {
// Group images by image id.
imageMap := make(map[string][]containerd.Image)
for _, i := range cImages {
@@ -355,6 +354,16 @@ func loadImages(ctx context.Context, cImages []containerd.Image, provider conten
glog.Warningf("The image content readiness for %q is not ok", i.Name())
continue
}
// Checking existence of top-level snapshot for each image being recovered.
unpacked, err := i.IsUnpacked(ctx, snapshotter)
if err != nil {
glog.Warningf("Failed to Check whether image is unpacked for image %s: %v", i.Name(), err)
continue
}
if !unpacked {
glog.Warningf("The image %s is not unpacked.", i.Name())
// TODO(random-liu): Consider whether we should try unpack here.
}
info, err := getImageInfo(ctx, i, provider)
if err != nil {
@@ -387,12 +396,6 @@ 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)
// TODO(random-liu): Consider whether we should try unpack here.
}
images = append(images, image)
}
return images, nil