From 1fc19772e0ac7da45c17e5044fa1ed88010fed57 Mon Sep 17 00:00:00 2001 From: Djordje Lukic Date: Tue, 30 May 2023 10:20:41 +0200 Subject: [PATCH] Make sure the image is unpacked for the current snapshotter Switching snapshotter implementations would result in an error when preparing a snapshot, check that the image is indeed unpacked for the current snapshot before trying to prepare a snapshot. Signed-off-by: Djordje Lukic (cherry picked from commit ed32f5e241264a4dc7555f3fe4b301840133ade0) Signed-off-by: Sebastiaan van Stijn --- daemon/containerd/image_snapshot.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/daemon/containerd/image_snapshot.go b/daemon/containerd/image_snapshot.go index 35c0816c473c0..a2152505c15c7 100644 --- a/daemon/containerd/image_snapshot.go +++ b/daemon/containerd/image_snapshot.go @@ -3,6 +3,7 @@ package containerd import ( "context" + "github.com/containerd/containerd" containerdimages "github.com/containerd/containerd/images" "github.com/containerd/containerd/leases" "github.com/containerd/containerd/platforms" @@ -12,7 +13,7 @@ import ( // PrepareSnapshot prepares a snapshot from a parent image for a container func (i *ImageService) PrepareSnapshot(ctx context.Context, id string, parentImage string, platform *ocispec.Platform) error { - desc, err := i.resolveDescriptor(ctx, parentImage) + img, err := i.resolveImage(ctx, parentImage) if err != nil { return err } @@ -24,7 +25,19 @@ func (i *ImageService) PrepareSnapshot(ctx context.Context, id string, parentIma matcher = platforms.Only(*platform) } - desc, err = containerdimages.Config(ctx, cs, desc, matcher) + platformImg := containerd.NewImageWithPlatform(i.client, img, matcher) + unpacked, err := platformImg.IsUnpacked(ctx, i.snapshotter) + if err != nil { + return err + } + + if !unpacked { + if err := platformImg.Unpack(ctx, i.snapshotter); err != nil { + return err + } + } + + desc, err := containerdimages.Config(ctx, cs, img.Target, matcher) if err != nil { return err }