Skip to content

Commit 38d4e50

Browse files
committed
Invoke Stable ABI compatibility function in windows platform matcher
Signed-off-by: Kirtana Ashok <[email protected]> (cherry picked from commit cfb30a3) Signed-off-by: Kirtana Ashok <[email protected]>
1 parent 7791d75 commit 38d4e50

2 files changed

Lines changed: 128 additions & 2 deletions

File tree

platforms/defaults_windows.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strconv"
2323
"strings"
2424

25+
"github.com/Microsoft/hcsshim/osversion"
2526
specs "github.com/opencontainers/image-spec/specs-go/v1"
2627
"golang.org/x/sys/windows"
2728
)
@@ -50,15 +51,36 @@ func (m windowsmatcher) Match(p specs.Platform) bool {
5051
match := m.defaultMatcher.Match(p)
5152

5253
if match && m.OS == "windows" {
53-
if strings.HasPrefix(p.OSVersion, m.osVersionPrefix) {
54+
// HPC containers do not have OS version filled
55+
if p.OSVersion == "" {
5456
return true
5557
}
56-
return p.OSVersion == ""
58+
59+
hostOsVersion := GetOsVersion(m.osVersionPrefix)
60+
ctrOsVersion := GetOsVersion(p.OSVersion)
61+
return osversion.CheckHostAndContainerCompat(hostOsVersion, ctrOsVersion)
5762
}
5863

5964
return match
6065
}
6166

67+
func GetOsVersion(osVersionPrefix string) osversion.OSVersion {
68+
parts := strings.Split(osVersionPrefix, ".")
69+
if len(parts) < 3 {
70+
return osversion.OSVersion{}
71+
}
72+
73+
majorVersion, _ := strconv.Atoi(parts[0])
74+
minorVersion, _ := strconv.Atoi(parts[1])
75+
buildNumber, _ := strconv.Atoi(parts[2])
76+
77+
return osversion.OSVersion{
78+
MajorVersion: uint8(majorVersion),
79+
MinorVersion: uint8(minorVersion),
80+
Build: uint16(buildNumber),
81+
}
82+
}
83+
6284
// Less sorts matched platforms in front of other platforms.
6385
// For matched platforms, it puts platforms with larger revision
6486
// number in front.

platforms/defaults_windows_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,110 @@ func TestMatchComparerMatch_WCOW(t *testing.T) {
142142
}
143143
}
144144

145+
// TestMatchComparerMatch_ABICheckWCOW checks windows platform matcher
146+
// behavior for stable ABI and non-stable ABI compliant versions
147+
func TestMatchComparerMatch_ABICheckWCOW(t *testing.T) {
148+
platformWS2019 := imagespec.Platform{
149+
Architecture: "amd64",
150+
OS: "windows",
151+
OSVersion: "10.0.17763",
152+
}
153+
platformWS2022 := imagespec.Platform{
154+
Architecture: "amd64",
155+
OS: "windows",
156+
OSVersion: "10.0.20348",
157+
}
158+
platformWindows11 := imagespec.Platform{
159+
Architecture: "amd64",
160+
OS: "windows",
161+
OSVersion: "10.0.22621",
162+
}
163+
matcherWS2019 := windowsmatcher{
164+
Platform: platformWS2019,
165+
osVersionPrefix: platformWS2019.OSVersion,
166+
defaultMatcher: &matcher{
167+
Platform: Normalize(platformWS2019),
168+
},
169+
}
170+
matcherWS2022 := windowsmatcher{
171+
Platform: platformWS2022,
172+
osVersionPrefix: platformWS2022.OSVersion,
173+
defaultMatcher: &matcher{
174+
Platform: Normalize(platformWS2022),
175+
},
176+
}
177+
matcherWindows11 := windowsmatcher{
178+
Platform: platformWindows11,
179+
osVersionPrefix: platformWindows11.OSVersion,
180+
defaultMatcher: &matcher{
181+
Platform: Normalize(platformWindows11),
182+
},
183+
}
184+
185+
for _, test := range []struct {
186+
hostPlatformMatcher windowsmatcher
187+
testPlatform imagespec.Platform
188+
match bool
189+
}{
190+
{
191+
hostPlatformMatcher: matcherWS2019,
192+
testPlatform: imagespec.Platform{
193+
Architecture: "amd64",
194+
OS: "windows",
195+
OSVersion: "10.0.17763",
196+
},
197+
match: true,
198+
},
199+
{
200+
hostPlatformMatcher: matcherWS2019,
201+
testPlatform: imagespec.Platform{
202+
Architecture: "amd64",
203+
OS: "windows",
204+
OSVersion: "10.0.20348",
205+
},
206+
match: false,
207+
},
208+
{
209+
hostPlatformMatcher: matcherWS2022,
210+
testPlatform: imagespec.Platform{
211+
Architecture: "amd64",
212+
OS: "windows",
213+
OSVersion: "10.0.17763",
214+
},
215+
match: false,
216+
},
217+
{
218+
hostPlatformMatcher: matcherWS2022,
219+
testPlatform: imagespec.Platform{
220+
Architecture: "amd64",
221+
OS: "windows",
222+
OSVersion: "10.0.20348",
223+
},
224+
match: true,
225+
},
226+
{
227+
hostPlatformMatcher: matcherWindows11,
228+
testPlatform: imagespec.Platform{
229+
Architecture: "amd64",
230+
OS: "windows",
231+
OSVersion: "10.0.17763",
232+
},
233+
match: false,
234+
},
235+
{
236+
hostPlatformMatcher: matcherWindows11,
237+
testPlatform: imagespec.Platform{
238+
Architecture: "amd64",
239+
OS: "windows",
240+
OSVersion: "10.0.20348",
241+
},
242+
match: true,
243+
},
244+
} {
245+
assert.Equal(t, test.match, test.hostPlatformMatcher.Match(test.testPlatform), "should match: %t, %s to %s", test.match, test.hostPlatformMatcher.Platform, test.testPlatform)
246+
}
247+
}
248+
145249
func TestMatchComparerMatch_LCOW(t *testing.T) {
146250
major, minor, build := windows.RtlGetNtVersionNumbers()
147251
buildStr := fmt.Sprintf("%d.%d.%d", major, minor, build)

0 commit comments

Comments
 (0)