add optional check that snapshotter supports the image platform when unpacking

Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
This commit is contained in:
Kathryn Baldauf
2019-08-29 15:57:12 -07:00
parent 1e624fa3de
commit f8992f451c
7 changed files with 150 additions and 6 deletions

View File

@@ -31,6 +31,7 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/snapshots"
"github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/identity"
@@ -93,6 +94,17 @@ func (u *unpacker) unpack(
return errors.Errorf("number of layers and diffIDs don't match: %d != %d", len(layers), len(diffIDs))
}
if u.config.CheckPlatformSupported {
imgPlatform := platforms.Normalize(ocispec.Platform{OS: i.OS, Architecture: i.Architecture})
snapshotterPlatformMatcher, err := u.c.GetSnapshotterSupportedPlatforms(ctx, u.snapshotter)
if err != nil {
return errors.Wrapf(err, "failed to find supported platforms for snapshotter %s", u.snapshotter)
}
if !snapshotterPlatformMatcher.Match(imgPlatform) {
return fmt.Errorf("snapshotter %s does not support platform %s for image %s", u.snapshotter, imgPlatform, config.Digest)
}
}
var (
sn = u.c.SnapshotService(u.snapshotter)
a = u.c.DiffService()