From 605cc35dc620fc84e70d95589da2cb30cc2134fe Mon Sep 17 00:00:00 2001 From: John Stephens Date: Thu, 28 Jun 2018 20:30:41 -0700 Subject: [PATCH] LCOW: Prefer Windows over Linux in a manifest list When a manifest list contains both Linux and Windows images, always prefer Windows when the platform OS is unspecified. Also, filter out any Windows images with a higher build than the host, since they cannot run. Signed-off-by: John Stephens (cherry picked from commit ddcdb7255d960a4b2049439245a4f887b26af891) Signed-off-by: Sebastiaan van Stijn --- distribution/pull_v2_windows.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/distribution/pull_v2_windows.go b/distribution/pull_v2_windows.go index 3c9645883f3a5..1ae167ef777d0 100644 --- a/distribution/pull_v2_windows.go +++ b/distribution/pull_v2_windows.go @@ -74,11 +74,14 @@ func filterManifests(manifests []manifestlist.ManifestDescriptor, p specs.Platfo if (manifestDescriptor.Platform.Architecture == runtime.GOARCH) && ((p.OS != "" && manifestDescriptor.Platform.OS == p.OS) || // Explicit user request for an OS we know we support (p.OS == "" && system.IsOSSupported(manifestDescriptor.Platform.OS))) { // No user requested OS, but one we can support - matches = append(matches, manifestDescriptor) - logrus.Debugf("found match %s/%s %s with media type %s, digest %s", manifestDescriptor.Platform.OS, runtime.GOARCH, manifestDescriptor.Platform.OSVersion, manifestDescriptor.MediaType, manifestDescriptor.Digest.String()) if strings.EqualFold("windows", manifestDescriptor.Platform.OS) { + if err := checkImageCompatibility("windows", manifestDescriptor.Platform.OSVersion); err != nil { + continue + } foundWindowsMatch = true } + matches = append(matches, manifestDescriptor) + logrus.Debugf("found match %s/%s %s with media type %s, digest %s", manifestDescriptor.Platform.OS, runtime.GOARCH, manifestDescriptor.Platform.OSVersion, manifestDescriptor.MediaType, manifestDescriptor.Digest.String()) } else { logrus.Debugf("ignoring %s/%s %s with media type %s, digest %s", manifestDescriptor.Platform.OS, manifestDescriptor.Platform.Architecture, manifestDescriptor.Platform.OSVersion, manifestDescriptor.MediaType, manifestDescriptor.Digest.String()) } @@ -103,7 +106,8 @@ func (mbv manifestsByVersion) Less(i, j int) bool { // TODO: Split version by parts and compare // TODO: Prefer versions which have a greater version number // Move compatible versions to the top, with no other ordering changes - return versionMatch(mbv.list[i].Platform.OSVersion, mbv.version) && !versionMatch(mbv.list[j].Platform.OSVersion, mbv.version) + return (strings.EqualFold("windows", mbv.list[i].Platform.OS) && !strings.EqualFold("windows", mbv.list[j].Platform.OS)) || + (versionMatch(mbv.list[i].Platform.OSVersion, mbv.version) && !versionMatch(mbv.list[j].Platform.OSVersion, mbv.version)) } func (mbv manifestsByVersion) Len() int {