@@ -21,10 +21,8 @@ import (
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/containers"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/docker/docker/pkg/chrootarchive"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/opencontainers/image-spec/identity"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -35,19 +33,13 @@ func WithImageUnpack(i containerd.Image) containerd.NewContainerOpts {
|
||||
if c.Snapshotter == "" {
|
||||
return errors.New("no snapshotter set for container")
|
||||
}
|
||||
snapshotter := client.SnapshotService(c.Snapshotter)
|
||||
diffIDs, err := i.RootFS(ctx)
|
||||
unpacked, err := i.IsUnpacked(ctx, c.Snapshotter)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get image diff IDs")
|
||||
return errors.Wrap(err, "fail to check if image is unpacked")
|
||||
}
|
||||
chainID := identity.ChainID(diffIDs)
|
||||
_, err = snapshotter.Stat(ctx, chainID.String())
|
||||
if err == nil {
|
||||
if unpacked {
|
||||
return nil
|
||||
}
|
||||
if !errdefs.IsNotFound(err) {
|
||||
return errors.Wrap(err, "stat snapshot")
|
||||
}
|
||||
// Unpack the snapshot.
|
||||
if err := i.Unpack(ctx, c.Snapshotter); err != nil {
|
||||
return errors.Wrap(err, "unpack snapshot")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user