Browse code

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 authored on 2023/04/05 21:09:21
Showing 7 changed files
... ...
@@ -40,7 +40,7 @@ func (i *ImageService) Changes(ctx context.Context, container *container.Contain
40 40
 		return nil, err
41 41
 	}
42 42
 
43
-	snapshotter := i.client.SnapshotService(i.snapshotter)
43
+	snapshotter := i.client.SnapshotService(container.Driver)
44 44
 
45 45
 	diffIDs := image.RootFS.DiffIDs
46 46
 	parent, err := snapshotter.View(ctx, rnd.String(), identity.ChainID(diffIDs).String())
... ...
@@ -61,7 +61,7 @@ func (i *ImageService) CommitImage(ctx context.Context, cc backend.CommitConfig)
61 61
 
62 62
 	var (
63 63
 		differ = i.client.DiffService()
64
-		sn     = i.client.SnapshotService(i.snapshotter)
64
+		sn     = i.client.SnapshotService(container.Driver)
65 65
 	)
66 66
 
67 67
 	// 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)
87 87
 	}
88 88
 
89 89
 	layers := append(manifest.Layers, diffLayerDesc)
90
-	commitManifestDesc, err := writeContentsForImage(ctx, i.snapshotter, cs, imageConfig, layers)
90
+	commitManifestDesc, err := writeContentsForImage(ctx, container.Driver, cs, imageConfig, layers)
91 91
 	if err != nil {
92 92
 		return "", err
93 93
 	}
... ...
@@ -22,7 +22,7 @@ import (
22 22
 )
23 23
 
24 24
 func (i *ImageService) PerformWithBaseFS(ctx context.Context, c *container.Container, fn func(root string) error) error {
25
-	snapshotter := i.client.SnapshotService(i.snapshotter)
25
+	snapshotter := i.client.SnapshotService(c.Driver)
26 26
 	mounts, err := snapshotter.Mounts(ctx, c.ID)
27 27
 	if err != nil {
28 28
 		return err
... ...
@@ -50,6 +50,7 @@ func (i *ImageService) Images(ctx context.Context, opts types.ImageListOptions)
50 50
 		return nil, err
51 51
 	}
52 52
 
53
+	// TODO(thaJeztah): do we need to take multiple snapshotters into account? See https://github.com/moby/moby/issues/45273
53 54
 	snapshotter := i.client.SnapshotService(i.snapshotter)
54 55
 	sizeCache := make(map[digest.Digest]int64)
55 56
 	snapshotSizeFn := func(d digest.Digest) (int64, error) {
... ...
@@ -177,6 +178,8 @@ func (i *ImageService) singlePlatformImage(ctx context.Context, contentStore con
177 177
 	if err != nil {
178 178
 		return nil, nil, err
179 179
 	}
180
+
181
+	// TODO(thaJeztah): do we need to take multiple snapshotters into account? See https://github.com/moby/moby/issues/45273
180 182
 	snapshotter := i.client.SnapshotService(i.snapshotter)
181 183
 	sizeCache := make(map[digest.Digest]int64)
182 184
 
... ...
@@ -62,6 +62,7 @@ func (i *ImageService) PullImage(ctx context.Context, image, tagOrDigest string,
62 62
 	defer finishProgress()
63 63
 
64 64
 	opts = append(opts, containerd.WithPullUnpack)
65
+	// 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
65 66
 	opts = append(opts, containerd.WithPullSnapshotter(i.snapshotter))
66 67
 
67 68
 	// AppendInfoHandlerWrapper will annotate the image with basic information like manifest and layer digests as labels;
... ...
@@ -13,7 +13,7 @@ import (
13 13
 // Mount mounts the container filesystem in a temporary location, use defer imageService.Unmount
14 14
 // to unmount the filesystem when calling this
15 15
 func (i *ImageService) Mount(ctx context.Context, container *container.Container) error {
16
-	snapshotter := i.client.SnapshotService(i.snapshotter)
16
+	snapshotter := i.client.SnapshotService(container.Driver)
17 17
 	mounts, err := snapshotter.Mounts(ctx, container.ID)
18 18
 	if err != nil {
19 19
 		return err
... ...
@@ -128,6 +128,7 @@ func (i *ImageService) ReleaseLayer(rwlayer layer.RWLayer) error {
128 128
 // called from disk_usage.go
129 129
 func (i *ImageService) LayerDiskUsage(ctx context.Context) (int64, error) {
130 130
 	var allLayersSize int64
131
+	// TODO(thaJeztah): do we need to take multiple snapshotters into account? See https://github.com/moby/moby/issues/45273
131 132
 	snapshotter := i.client.SnapshotService(i.snapshotter)
132 133
 	snapshotter.Walk(ctx, func(ctx context.Context, info snapshots.Info) error {
133 134
 		usage, err := snapshotter.Usage(ctx, info.Name)
... ...
@@ -179,7 +180,7 @@ func (i *ImageService) GetContainerLayerSize(ctx context.Context, containerID st
179 179
 		return 0, 0, err
180 180
 	}
181 181
 
182
-	snapshotter := i.client.SnapshotService(i.snapshotter)
182
+	snapshotter := i.client.SnapshotService(ctr.Driver)
183 183
 	usage, err := snapshotter.Usage(ctx, containerID)
184 184
 	if err != nil {
185 185
 		return 0, 0, err