Skip to content

Commit 6b0b64a

Browse files
committed
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 <[email protected]>
1 parent 44d5a7e commit 6b0b64a

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

images/archive/importer.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/containerd/containerd/errdefs"
3333
"github.com/containerd/containerd/images"
3434
"github.com/containerd/containerd/log"
35+
"github.com/containerd/containerd/platforms"
3536
digest "github.com/opencontainers/go-digest"
3637
specs "github.com/opencontainers/image-spec/specs-go"
3738
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
186187
return ocispec.Descriptor{}, errors.Wrap(err, "write docker manifest")
187188
}
188189

189-
platforms, err := images.Platforms(ctx, store, desc)
190+
imgPlatforms, err := images.Platforms(ctx, store, desc)
190191
if err != nil {
191192
return ocispec.Descriptor{}, errors.Wrap(err, "unable to resolve platform")
192193
}
193-
if len(platforms) > 0 {
194+
if len(imgPlatforms) > 0 {
194195
// Only one platform can be resolved from non-index manifest,
195196
// The platform can only come from the config included above,
196197
// if the config has no platform it can be safely omitted.
197-
desc.Platform = &platforms[0]
198+
desc.Platform = &imgPlatforms[0]
199+
200+
// If the image we've just imported is a Windows image without the OSVersion set,
201+
// we could just assume it matches this host's OS Version. Without this, the
202+
// children labels might not be set on the image content, leading to it being
203+
// garbage collected, breaking the image.
204+
// See: https://github.com/containerd/containerd/issues/5690
205+
if desc.Platform.OS == "windows" && desc.Platform.OSVersion == "" {
206+
platform := platforms.DefaultSpec()
207+
desc.Platform.OSVersion = platform.OSVersion
208+
}
198209
}
199210

200211
if len(mfst.RepoTags) == 0 {

0 commit comments

Comments
 (0)