Skip to content

Commit b327af6

Browse files
committed
Add fallback for windows platforms without osversion
The background for this change: 1. Windows host-process containers do not have an OS version set 2. Buildx v0.10 started pushing manifest lists by default, but it never has the OSVersion in the platform data (not that there is any way to specify what particular OS version you want). The change means that containerd cannot run images created with the new buildx on Windows because there is no matching OSVersion in the list of manifests. Signed-off-by: Brian Goff <[email protected]> (cherry picked from commit 8442521) Signed-off-by: Brian Goff <[email protected]>
1 parent 4d724f6 commit b327af6

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

platforms/defaults_windows.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ type matchComparer struct {
4646

4747
// Match matches platform with the same windows major, minor
4848
// and build version.
49-
func (m matchComparer) Match(p imagespec.Platform) bool {
50-
if m.defaults.Match(p) {
51-
// TODO(windows): Figure out whether OSVersion is deprecated.
52-
return strings.HasPrefix(p.OSVersion, m.osVersionPrefix)
49+
func (m matchComparer) Match(p specs.Platform) bool {
50+
match := m.defaults.Match(p)
51+
52+
if match && p.OS == "windows" {
53+
if strings.HasPrefix(p.OSVersion, m.osVersionPrefix) {
54+
return true
55+
}
56+
return p.OSVersion == ""
5357
}
5458
return false
5559
}

platforms/defaults_windows_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestMatchComparerMatch(t *testing.T) {
104104
Architecture: "amd64",
105105
OS: "windows",
106106
},
107-
match: false,
107+
match: true,
108108
},
109109
} {
110110
assert.Equal(t, test.match, m.Match(test.platform))
@@ -159,11 +159,11 @@ func TestMatchComparerLess(t *testing.T) {
159159
{
160160
Architecture: "amd64",
161161
OS: "windows",
162-
OSVersion: "10.0.17764.1",
163162
},
164163
{
165164
Architecture: "amd64",
166165
OS: "windows",
166+
OSVersion: "10.0.17764.1",
167167
},
168168
{
169169
Architecture: "amd64",

platforms/platforms_windows_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,23 @@ package platforms
1919
import (
2020
"testing"
2121

22+
specs "github.com/opencontainers/image-spec/specs-go/v1"
2223
"github.com/stretchr/testify/require"
2324
)
2425

2526
func TestNormalize(t *testing.T) {
2627
require.Equal(t, DefaultSpec(), Normalize(DefaultSpec()))
2728
}
29+
30+
func TestFallbackOnOSVersion(t *testing.T) {
31+
p := specs.Platform{
32+
OS: "windows",
33+
Architecture: "amd64",
34+
OSVersion: "99.99.99.99",
35+
}
36+
37+
other := specs.Platform{OS: p.OS, Architecture: p.Architecture}
38+
39+
m := NewMatcher(p)
40+
require.True(t, m.Match(other))
41+
}

0 commit comments

Comments
 (0)