소스 검색

image/cache: Require Major and Minor match for Windows OSVersion

The platform comparison was backported from the branch that vendors
containerd 1.7.

In this branch the vendored containerd version is older and doesn't have
the same comparison logic for Windows specific OSVersion.

Require both major and minor components of Windows OSVersion to match.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit b3888ed89951e568c1bf33b5223e3e515019e87f)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski 1 년 전
부모
커밋
d10756f356
2개의 변경된 파일7개의 추가작업 그리고 6개의 파일을 삭제
  1. 7 0
      image/cache/compare.go
  2. 0 6
      image/cache/compare_test.go

+ 7 - 0
image/cache/compare.go

@@ -26,6 +26,13 @@ func comparePlatform(builderPlatform, imagePlatform ocispec.Platform) bool {
 		builderParts := strings.Split(builderPlatform.OSVersion, ".")
 		builderParts := strings.Split(builderPlatform.OSVersion, ".")
 		imageParts := strings.Split(imagePlatform.OSVersion, ".")
 		imageParts := strings.Split(imagePlatform.OSVersion, ".")
 
 
+		// Major and minor must match.
+		for i := 0; i < 2; i++ {
+			if len(builderParts) > i && len(imageParts) > i && builderParts[i] != imageParts[i] {
+				return false
+			}
+		}
+
 		if len(builderParts) >= 3 && len(imageParts) >= 3 {
 		if len(builderParts) >= 3 && len(imageParts) >= 3 {
 			// Keep only Major & Minor.
 			// Keep only Major & Minor.
 			builderParts[0] = imageParts[0]
 			builderParts[0] = imageParts[0]

+ 0 - 6
image/cache/compare_test.go

@@ -193,12 +193,6 @@ func TestPlatformCompare(t *testing.T) {
 		},
 		},
 	} {
 	} {
 		tc := tc
 		tc := tc
-		// OSVersion comparison is only performed by containerd platform
-		// matcher if built on Windows.
-		if (tc.image.OSVersion != "" || tc.builder.OSVersion != "") && runtime.GOOS != "windows" {
-			continue
-		}
-
 		t.Run(tc.name, func(t *testing.T) {
 		t.Run(tc.name, func(t *testing.T) {
 			assert.Check(t, is.Equal(comparePlatform(tc.builder, tc.image), tc.expected))
 			assert.Check(t, is.Equal(comparePlatform(tc.builder, tc.image), tc.expected))
 		})
 		})