Explorar el Código

c8d: use the container's configured snapshotter where possible

While we currently do not provide an option to specify the snapshotter to use
for individual containers (we may want to add this option in future), currently
it already is possible to configure the snapshotter in the daemon configuration,
which could (likely) cause issues when changing and restarting the daemon.

This patch updates some code-paths that have the container available to use
the snapshotter that's configured for the container (instead of the default
snapshotter configured).

There are still code-paths to be looked into, and a tracking ticket as well as
some TODO's were added for those.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn hace 2 años
padre
commit
465cbccdaf

+ 1 - 1
daemon/containerd/image_changes.go

@@ -40,7 +40,7 @@ func (i *ImageService) Changes(ctx context.Context, container *container.Contain
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	snapshotter := i.client.SnapshotService(i.snapshotter)
+	snapshotter := i.client.SnapshotService(container.Driver)
 
 
 	diffIDs := image.RootFS.DiffIDs
 	diffIDs := image.RootFS.DiffIDs
 	parent, err := snapshotter.View(ctx, rnd.String(), identity.ChainID(diffIDs).String())
 	parent, err := snapshotter.View(ctx, rnd.String(), identity.ChainID(diffIDs).String())

+ 2 - 2
daemon/containerd/image_commit.go

@@ -61,7 +61,7 @@ func (i *ImageService) CommitImage(ctx context.Context, cc backend.CommitConfig)
 
 
 	var (
 	var (
 		differ = i.client.DiffService()
 		differ = i.client.DiffService()
-		sn     = i.client.SnapshotService(i.snapshotter)
+		sn     = i.client.SnapshotService(container.Driver)
 	)
 	)
 
 
 	// Don't gc me and clean the dirty data after 1 hour!
 	// Don't gc me and clean the dirty data after 1 hour!
@@ -87,7 +87,7 @@ func (i *ImageService) CommitImage(ctx context.Context, cc backend.CommitConfig)
 	}
 	}
 
 
 	layers := append(manifest.Layers, diffLayerDesc)
 	layers := append(manifest.Layers, diffLayerDesc)
-	commitManifestDesc, err := writeContentsForImage(ctx, i.snapshotter, cs, imageConfig, layers)
+	commitManifestDesc, err := writeContentsForImage(ctx, container.Driver, cs, imageConfig, layers)
 	if err != nil {
 	if err != nil {
 		return "", err
 		return "", err
 	}
 	}

+ 1 - 1
daemon/containerd/image_exporter.go

@@ -22,7 +22,7 @@ import (
 )
 )
 
 
 func (i *ImageService) PerformWithBaseFS(ctx context.Context, c *container.Container, fn func(root string) error) error {
 func (i *ImageService) PerformWithBaseFS(ctx context.Context, c *container.Container, fn func(root string) error) error {
-	snapshotter := i.client.SnapshotService(i.snapshotter)
+	snapshotter := i.client.SnapshotService(c.Driver)
 	mounts, err := snapshotter.Mounts(ctx, c.ID)
 	mounts, err := snapshotter.Mounts(ctx, c.ID)
 	if err != nil {
 	if err != nil {
 		return err
 		return err

+ 3 - 0
daemon/containerd/image_list.go

@@ -50,6 +50,7 @@ func (i *ImageService) Images(ctx context.Context, opts types.ImageListOptions)
 		return nil, err
 		return nil, err
 	}
 	}
 
 
+	// TODO(thaJeztah): do we need to take multiple snapshotters into account? See https://github.com/moby/moby/issues/45273
 	snapshotter := i.client.SnapshotService(i.snapshotter)
 	snapshotter := i.client.SnapshotService(i.snapshotter)
 	sizeCache := make(map[digest.Digest]int64)
 	sizeCache := make(map[digest.Digest]int64)
 	snapshotSizeFn := func(d digest.Digest) (int64, error) {
 	snapshotSizeFn := func(d digest.Digest) (int64, error) {
@@ -177,6 +178,8 @@ func (i *ImageService) singlePlatformImage(ctx context.Context, contentStore con
 	if err != nil {
 	if err != nil {
 		return nil, nil, err
 		return nil, nil, err
 	}
 	}
+
+	// TODO(thaJeztah): do we need to take multiple snapshotters into account? See https://github.com/moby/moby/issues/45273
 	snapshotter := i.client.SnapshotService(i.snapshotter)
 	snapshotter := i.client.SnapshotService(i.snapshotter)
 	sizeCache := make(map[digest.Digest]int64)
 	sizeCache := make(map[digest.Digest]int64)
 
 

+ 1 - 0
daemon/containerd/image_pull.go

@@ -62,6 +62,7 @@ func (i *ImageService) PullImage(ctx context.Context, image, tagOrDigest string,
 	defer finishProgress()
 	defer finishProgress()
 
 
 	opts = append(opts, containerd.WithPullUnpack)
 	opts = append(opts, containerd.WithPullUnpack)
+	// TODO(thaJeztah): we may have to pass the snapshotter to use if the pull is part of a "docker run" (container create -> pull image if missing). See https://github.com/moby/moby/issues/45273
 	opts = append(opts, containerd.WithPullSnapshotter(i.snapshotter))
 	opts = append(opts, containerd.WithPullSnapshotter(i.snapshotter))
 
 
 	// AppendInfoHandlerWrapper will annotate the image with basic information like manifest and layer digests as labels;
 	// AppendInfoHandlerWrapper will annotate the image with basic information like manifest and layer digests as labels;

+ 1 - 1
daemon/containerd/mount.go

@@ -13,7 +13,7 @@ import (
 // Mount mounts the container filesystem in a temporary location, use defer imageService.Unmount
 // Mount mounts the container filesystem in a temporary location, use defer imageService.Unmount
 // to unmount the filesystem when calling this
 // to unmount the filesystem when calling this
 func (i *ImageService) Mount(ctx context.Context, container *container.Container) error {
 func (i *ImageService) Mount(ctx context.Context, container *container.Container) error {
-	snapshotter := i.client.SnapshotService(i.snapshotter)
+	snapshotter := i.client.SnapshotService(container.Driver)
 	mounts, err := snapshotter.Mounts(ctx, container.ID)
 	mounts, err := snapshotter.Mounts(ctx, container.ID)
 	if err != nil {
 	if err != nil {
 		return err
 		return err

+ 2 - 1
daemon/containerd/service.go

@@ -128,6 +128,7 @@ func (i *ImageService) ReleaseLayer(rwlayer layer.RWLayer) error {
 // called from disk_usage.go
 // called from disk_usage.go
 func (i *ImageService) LayerDiskUsage(ctx context.Context) (int64, error) {
 func (i *ImageService) LayerDiskUsage(ctx context.Context) (int64, error) {
 	var allLayersSize int64
 	var allLayersSize int64
+	// TODO(thaJeztah): do we need to take multiple snapshotters into account? See https://github.com/moby/moby/issues/45273
 	snapshotter := i.client.SnapshotService(i.snapshotter)
 	snapshotter := i.client.SnapshotService(i.snapshotter)
 	snapshotter.Walk(ctx, func(ctx context.Context, info snapshots.Info) error {
 	snapshotter.Walk(ctx, func(ctx context.Context, info snapshots.Info) error {
 		usage, err := snapshotter.Usage(ctx, info.Name)
 		usage, err := snapshotter.Usage(ctx, info.Name)
@@ -179,7 +180,7 @@ func (i *ImageService) GetContainerLayerSize(ctx context.Context, containerID st
 		return 0, 0, err
 		return 0, 0, err
 	}
 	}
 
 
-	snapshotter := i.client.SnapshotService(i.snapshotter)
+	snapshotter := i.client.SnapshotService(ctr.Driver)
 	usage, err := snapshotter.Usage(ctx, containerID)
 	usage, err := snapshotter.Usage(ctx, containerID)
 	if err != nil {
 	if err != nil {
 		return 0, 0, err
 		return 0, 0, err