From 6b0b64a51a5112954355cc2cb1809bd410e53855 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Thu, 26 Aug 2021 21:51:59 +0000 Subject: [PATCH] ctr: Fixes Windows image import A previous commit made the Windows containerd/platforms.Default stricter by requiring the OS Version to have a similar OS Version as the node's OS Version. However, tar images (from docker save) do not have any OS Version information, causing the containerd/import.Import's images.FilterPlatforms to filter out the image entirely, which means that the images.SetChildrenLabels doesn't get to label any children, which in turn will cause the Garbage Collector to remove content related to the image. This sets a default platform for the imported image if it's a Windows image which doesn't have any OSVersion information, or if there's no platform information at all. Signed-off-by: Claudiu Belu --- images/archive/importer.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/images/archive/importer.go b/images/archive/importer.go index f0de1dc05..2a787e0e7 100644 --- a/images/archive/importer.go +++ b/images/archive/importer.go @@ -32,6 +32,7 @@ import ( "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/images" "github.com/containerd/containerd/log" + "github.com/containerd/containerd/platforms" digest "github.com/opencontainers/go-digest" specs "github.com/opencontainers/image-spec/specs-go" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -186,15 +187,25 @@ func ImportIndex(ctx context.Context, store content.Store, reader io.Reader, opt return ocispec.Descriptor{}, errors.Wrap(err, "write docker manifest") } - platforms, err := images.Platforms(ctx, store, desc) + imgPlatforms, err := images.Platforms(ctx, store, desc) if err != nil { return ocispec.Descriptor{}, errors.Wrap(err, "unable to resolve platform") } - if len(platforms) > 0 { + if len(imgPlatforms) > 0 { // Only one platform can be resolved from non-index manifest, // The platform can only come from the config included above, // if the config has no platform it can be safely omitted. - desc.Platform = &platforms[0] + desc.Platform = &imgPlatforms[0] + + // If the image we've just imported is a Windows image without the OSVersion set, + // we could just assume it matches this host's OS Version. Without this, the + // children labels might not be set on the image content, leading to it being + // garbage collected, breaking the image. + // See: https://github.com/containerd/containerd/issues/5690 + if desc.Platform.OS == "windows" && desc.Platform.OSVersion == "" { + platform := platforms.DefaultSpec() + desc.Platform.OSVersion = platform.OSVersion + } } if len(mfst.RepoTags) == 0 {