Skip to content

Commit 8542d0e

Browse files
authored
Merge pull request #9069 from kiashok/portStableAbi-1.7
[release/1.7] Invoke Stable ABI compatibility function in windows platform matcher
2 parents 78874ec + c7a35cc commit 8542d0e

6 files changed

Lines changed: 153 additions & 3 deletions

File tree

pkg/transfer/streaming/stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func ReceiveStream(ctx context.Context, stream streaming.Stream) io.Reader {
164164
}
165165
any, err := stream.Recv()
166166
if err != nil {
167-
if errors.Is(err, io.EOF) {
167+
if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) {
168168
err = nil
169169
} else {
170170
err = fmt.Errorf("received failed: %w", err)

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)

platforms/platforms.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ func Parse(specifier string) (specs.Platform, error) {
196196
p.Variant = cpuVariant()
197197
}
198198

199+
if p.OS == "windows" {
200+
p.OSVersion = GetWindowsOsVersion()
201+
}
202+
199203
return p, nil
200204
}
201205

@@ -218,6 +222,10 @@ func Parse(specifier string) (specs.Platform, error) {
218222
p.Variant = ""
219223
}
220224

225+
if p.OS == "windows" {
226+
p.OSVersion = GetWindowsOsVersion()
227+
}
228+
221229
return p, nil
222230
case 3:
223231
// we have a fully specified variant, this is rare
@@ -227,6 +235,10 @@ func Parse(specifier string) (specs.Platform, error) {
227235
p.Variant = "v8"
228236
}
229237

238+
if p.OS == "windows" {
239+
p.OSVersion = GetWindowsOsVersion()
240+
}
241+
230242
return p, nil
231243
}
232244

platforms/platforms_other.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ func newDefaultMatcher(platform specs.Platform) Matcher {
2828
Platform: Normalize(platform),
2929
}
3030
}
31+
32+
func GetWindowsOsVersion() string {
33+
return ""
34+
}

platforms/platforms_windows.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
package platforms
1818

1919
import (
20+
"fmt"
21+
2022
specs "github.com/opencontainers/image-spec/specs-go/v1"
23+
"golang.org/x/sys/windows"
2124
)
2225

2326
// NewMatcher returns a Windows matcher that will match on osVersionPrefix if
@@ -32,3 +35,8 @@ func newDefaultMatcher(platform specs.Platform) Matcher {
3235
},
3336
}
3437
}
38+
39+
func GetWindowsOsVersion() string {
40+
major, minor, build := windows.RtlGetNtVersionNumbers()
41+
return fmt.Sprintf("%d.%d.%d", major, minor, build)
42+
}

0 commit comments

Comments
 (0)