Merge pull request #437 from cpuguy83/unpack_on_error_only

Remove explicit unpack on all container creates
This commit is contained in:
Lantao Liu 2017-11-28 13:47:42 -08:00 committed by GitHub
commit 6b8ffc53c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 19 deletions

View File

@ -21,28 +21,27 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/containers" "github.com/containerd/containerd/containers"
"github.com/containerd/containerd/errdefs"
"github.com/docker/docker/pkg/chrootarchive" "github.com/docker/docker/pkg/chrootarchive"
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/pkg/errors" "github.com/pkg/errors"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
// WithImageUnpack guarantees that the image used by the container is unpacked. // WithNewSnapshot wraps `containerd.WithNewSnapshot` so that if creating the
func WithImageUnpack(i containerd.Image) containerd.NewContainerOpts { // snapshot fails we make sure the image is actually unpacked and and retry.
func WithNewSnapshot(id string, i containerd.Image) containerd.NewContainerOpts {
f := containerd.WithNewSnapshot(id, i)
return func(ctx context.Context, client *containerd.Client, c *containers.Container) error { return func(ctx context.Context, client *containerd.Client, c *containers.Container) error {
if c.Snapshotter == "" { if err := f(ctx, client, c); err != nil {
return errors.New("no snapshotter set for container") if !errdefs.IsNotFound(err) {
} return err
unpacked, err := i.IsUnpacked(ctx, c.Snapshotter) }
if err != nil {
return errors.Wrap(err, "fail to check if image is unpacked") if err := i.Unpack(ctx, c.Snapshotter); err != nil {
} return errors.Wrap(err, "error unpacking image")
if unpacked { }
return nil return f(ctx, client, c)
}
// Unpack the snapshot.
if err := i.Unpack(ctx, c.Snapshotter); err != nil {
return errors.Wrap(err, "unpack snapshot")
} }
return nil return nil
} }

View File

@ -152,13 +152,12 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
// Set snapshotter before any other options. // Set snapshotter before any other options.
opts := []containerd.NewContainerOpts{ opts := []containerd.NewContainerOpts{
containerd.WithSnapshotter(c.config.ContainerdConfig.Snapshotter), containerd.WithSnapshotter(c.config.ContainerdConfig.Snapshotter),
customopts.WithImageUnpack(image.Image),
// Prepare container rootfs. This is always writeable even if // Prepare container rootfs. This is always writeable even if
// the container wants a readonly rootfs since we want to give // the container wants a readonly rootfs since we want to give
// the runtime (runc) a chance to modify (e.g. to create mount // the runtime (runc) a chance to modify (e.g. to create mount
// points corresponding to spec.Mounts) before making the // points corresponding to spec.Mounts) before making the
// rootfs readonly (requested by spec.Root.Readonly). // rootfs readonly (requested by spec.Root.Readonly).
containerd.WithNewSnapshot(id, image.Image), customopts.WithNewSnapshot(id, image.Image),
} }
if len(volumeMounts) > 0 { if len(volumeMounts) > 0 {

View File

@ -148,8 +148,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
opts := []containerd.NewContainerOpts{ opts := []containerd.NewContainerOpts{
containerd.WithSnapshotter(c.config.ContainerdConfig.Snapshotter), containerd.WithSnapshotter(c.config.ContainerdConfig.Snapshotter),
customopts.WithImageUnpack(image.Image), customopts.WithNewSnapshot(id, image.Image),
containerd.WithNewSnapshot(id, image.Image),
containerd.WithSpec(spec, specOpts...), containerd.WithSpec(spec, specOpts...),
containerd.WithContainerLabels(sandboxLabels), containerd.WithContainerLabels(sandboxLabels),
containerd.WithContainerExtension(sandboxMetadataExtension, &sandbox.Metadata), containerd.WithContainerExtension(sandboxMetadataExtension, &sandbox.Metadata),