Fix snapshotter getter in client code
Fixes #3312 Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
cbb108e228
commit
41e1bb8328
@ -43,6 +43,7 @@ import (
|
|||||||
"github.com/containerd/containerd/content"
|
"github.com/containerd/containerd/content"
|
||||||
contentproxy "github.com/containerd/containerd/content/proxy"
|
contentproxy "github.com/containerd/containerd/content/proxy"
|
||||||
"github.com/containerd/containerd/defaults"
|
"github.com/containerd/containerd/defaults"
|
||||||
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/events"
|
"github.com/containerd/containerd/events"
|
||||||
"github.com/containerd/containerd/images"
|
"github.com/containerd/containerd/images"
|
||||||
"github.com/containerd/containerd/leases"
|
"github.com/containerd/containerd/leases"
|
||||||
@ -655,6 +656,14 @@ func (c *Client) Version(ctx context.Context) (Version, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) getSnapshotter(name string) (snapshots.Snapshotter, error) {
|
||||||
|
s := c.SnapshotService(name)
|
||||||
|
if s == nil {
|
||||||
|
return nil, errors.Wrapf(errdefs.ErrNotFound, "snapshotter %s was not found", name)
|
||||||
|
}
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
// CheckRuntime returns true if the current runtime matches the expected
|
// CheckRuntime returns true if the current runtime matches the expected
|
||||||
// runtime. Providing various parts of the runtime schema will match those
|
// runtime. Providing various parts of the runtime schema will match those
|
||||||
// parts of the expected runtime
|
// parts of the expected runtime
|
||||||
|
@ -233,7 +233,11 @@ func (c *container) NewTask(ctx context.Context, ioCreate cio.Creator, opts ...N
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the rootfs from the snapshotter and add it to the request
|
// get the rootfs from the snapshotter and add it to the request
|
||||||
mounts, err := c.client.SnapshotService(r.Snapshotter).Mounts(ctx, r.SnapshotKey)
|
s, err := c.client.getSnapshotter(r.Snapshotter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mounts, err := s.Mounts(ctx, r.SnapshotKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,11 @@ func WithSnapshot(id string) NewContainerOpts {
|
|||||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
setSnapshotterIfEmpty(ctx, client, c)
|
setSnapshotterIfEmpty(ctx, client, c)
|
||||||
// check that the snapshot exists, if not, fail on creation
|
// check that the snapshot exists, if not, fail on creation
|
||||||
if _, err := client.SnapshotService(c.Snapshotter).Mounts(ctx, id); err != nil {
|
s, err := client.getSnapshotter(c.Snapshotter)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := s.Mounts(ctx, id); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.SnapshotKey = id
|
c.SnapshotKey = id
|
||||||
@ -138,7 +142,11 @@ func WithNewSnapshot(id string, i Image, opts ...snapshots.Opt) NewContainerOpts
|
|||||||
}
|
}
|
||||||
setSnapshotterIfEmpty(ctx, client, c)
|
setSnapshotterIfEmpty(ctx, client, c)
|
||||||
parent := identity.ChainID(diffIDs).String()
|
parent := identity.ChainID(diffIDs).String()
|
||||||
if _, err := client.SnapshotService(c.Snapshotter).Prepare(ctx, id, parent, opts...); err != nil {
|
s, err := client.getSnapshotter(c.Snapshotter)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := s.Prepare(ctx, id, parent, opts...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.SnapshotKey = id
|
c.SnapshotKey = id
|
||||||
@ -153,7 +161,11 @@ func WithSnapshotCleanup(ctx context.Context, client *Client, c containers.Conta
|
|||||||
if c.Snapshotter == "" {
|
if c.Snapshotter == "" {
|
||||||
return errors.Wrapf(errdefs.ErrInvalidArgument, "container.Snapshotter must be set to cleanup rootfs snapshot")
|
return errors.Wrapf(errdefs.ErrInvalidArgument, "container.Snapshotter must be set to cleanup rootfs snapshot")
|
||||||
}
|
}
|
||||||
return client.SnapshotService(c.Snapshotter).Remove(ctx, c.SnapshotKey)
|
s, err := client.getSnapshotter(c.Snapshotter)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return s.Remove(ctx, c.SnapshotKey)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -168,7 +180,11 @@ func WithNewSnapshotView(id string, i Image, opts ...snapshots.Opt) NewContainer
|
|||||||
}
|
}
|
||||||
setSnapshotterIfEmpty(ctx, client, c)
|
setSnapshotterIfEmpty(ctx, client, c)
|
||||||
parent := identity.ChainID(diffIDs).String()
|
parent := identity.ChainID(diffIDs).String()
|
||||||
if _, err := client.SnapshotService(c.Snapshotter).View(ctx, id, parent, opts...); err != nil {
|
s, err := client.getSnapshotter(c.Snapshotter)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := s.View(ctx, id, parent, opts...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.SnapshotKey = id
|
c.SnapshotKey = id
|
||||||
|
@ -53,10 +53,13 @@ func withRemappedSnapshotBase(id string, i Image, uid, gid uint32, readonly bool
|
|||||||
setSnapshotterIfEmpty(ctx, client, c)
|
setSnapshotterIfEmpty(ctx, client, c)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
snapshotter = client.SnapshotService(c.Snapshotter)
|
parent = identity.ChainID(diffIDs).String()
|
||||||
parent = identity.ChainID(diffIDs).String()
|
usernsID = fmt.Sprintf("%s-%d-%d", parent, uid, gid)
|
||||||
usernsID = fmt.Sprintf("%s-%d-%d", parent, uid, gid)
|
|
||||||
)
|
)
|
||||||
|
snapshotter, err := client.getSnapshotter(c.Snapshotter)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if _, err := snapshotter.Stat(ctx, usernsID); err == nil {
|
if _, err := snapshotter.Stat(ctx, usernsID); err == nil {
|
||||||
if _, err := snapshotter.Prepare(ctx, id, usernsID); err == nil {
|
if _, err := snapshotter.Prepare(ctx, id, usernsID); err == nil {
|
||||||
c.SnapshotKey = id
|
c.SnapshotKey = id
|
||||||
|
10
image.go
10
image.go
@ -108,7 +108,10 @@ func (i *image) Config(ctx context.Context) (ocispec.Descriptor, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *image) IsUnpacked(ctx context.Context, snapshotterName string) (bool, error) {
|
func (i *image) IsUnpacked(ctx context.Context, snapshotterName string) (bool, error) {
|
||||||
sn := i.client.SnapshotService(snapshotterName)
|
sn, err := i.client.getSnapshotter(snapshotterName)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
cs := i.client.ContentStore()
|
cs := i.client.ContentStore()
|
||||||
|
|
||||||
diffs, err := i.i.RootFS(ctx, cs, i.platform)
|
diffs, err := i.i.RootFS(ctx, cs, i.platform)
|
||||||
@ -140,13 +143,16 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
sn = i.client.SnapshotService(snapshotterName)
|
|
||||||
a = i.client.DiffService()
|
a = i.client.DiffService()
|
||||||
cs = i.client.ContentStore()
|
cs = i.client.ContentStore()
|
||||||
|
|
||||||
chain []digest.Digest
|
chain []digest.Digest
|
||||||
unpacked bool
|
unpacked bool
|
||||||
)
|
)
|
||||||
|
sn, err := i.client.getSnapshotter(snapshotterName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for _, layer := range layers {
|
for _, layer := range layers {
|
||||||
unpacked, err = rootfs.ApplyLayer(ctx, layer, chain, sn, a)
|
unpacked, err = rootfs.ApplyLayer(ctx, layer, chain, sn, a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user