Skip to content

Commit 62b234c

Browse files
committed
Add WS2025 to Windows matcher and code optimizations
Signed-off-by: Kirtana Ashok <[email protected]>
1 parent e3566b8 commit 62b234c

File tree

2 files changed

+93
-54
lines changed

2 files changed

+93
-54
lines changed

platform_windows_compat.go

+32-11
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,31 @@ type windowsOSVersion struct {
4141
const (
4242
// rs5 (version 1809, codename "Redstone 5") corresponds to Windows Server
4343
// 2019 (ltsc2019), and Windows 10 (October 2018 Update).
44-
rs5 = 17763
44+
RS5 = 17763
45+
// LTSC2019 (Windows Server 2019) is an alias for [RS5].
46+
LTSC2019 = RS5
4547

46-
// v21H2Server corresponds to Windows Server 2022 (ltsc2022).
47-
v21H2Server = 20348
48+
// V21H2Server corresponds to Windows Server 2022 (ltsc2022).
49+
V21H2Server = 20348
50+
// LTSC2022 (Windows Server 2022) is an alias for [V21H2Server]
51+
LTSC2022 = V21H2Server
4852

49-
// v22H2Win11 corresponds to Windows 11 (2022 Update).
50-
v22H2Win11 = 22621
53+
// V22H2Win11 corresponds to Windows 11 (2022 Update).
54+
V22H2Win11 = 22621
55+
56+
// V23H2 is the 23H2 release in the Windows Server annual channel.
57+
V23H2 = 25398
58+
59+
// Windows Server 2025 build 26100
60+
V25H1Server = 26100
61+
LTSC2025 = V25H1Server
5162
)
5263

5364
// List of stable ABI compliant ltsc releases
5465
// Note: List must be sorted in ascending order
5566
var compatLTSCReleases = []uint16{
56-
v21H2Server,
67+
LTSC2022,
68+
LTSC2025,
5769
}
5870

5971
// CheckHostAndContainerCompat checks if given host and container
@@ -70,18 +82,27 @@ func checkWindowsHostAndContainerCompat(host, ctr windowsOSVersion) bool {
7082
}
7183

7284
// If host is < WS 2022, exact version match is required
73-
if host.Build < v21H2Server {
85+
if host.Build < LTSC2022 {
7486
return host.Build == ctr.Build
7587
}
7688

77-
var supportedLtscRelease uint16
89+
// Find the latest LTSC version that is earlier than the host version.
90+
// This is the earliest version of container that the host can run.
91+
//
92+
// If the host version is an LTSC, then it supports compatibility with
93+
// everything from the previous LTSC up to itself, so we want supportedLTSCRelease
94+
// to be the previous entry.
95+
//
96+
// If no match is found, then we know that the host is LTSC2022 exactly,
97+
// since we already checked that it's not less than LTSC2022.
98+
var supportedLTSCRelease uint16 = LTSC2022
7899
for i := len(compatLTSCReleases) - 1; i >= 0; i-- {
79-
if host.Build >= compatLTSCReleases[i] {
80-
supportedLtscRelease = compatLTSCReleases[i]
100+
if host.Build > compatLTSCReleases[i] {
101+
supportedLTSCRelease = compatLTSCReleases[i]
81102
break
82103
}
83104
}
84-
return ctr.Build >= supportedLtscRelease && ctr.Build <= host.Build
105+
return supportedLTSCRelease <= ctr.Build && ctr.Build <= host.Build
85106
}
86107

87108
func getWindowsOSVersion(osVersionPrefix string) windowsOSVersion {

platform_windows_compat_test.go

+61-43
Original file line numberDiff line numberDiff line change
@@ -17,68 +17,86 @@
1717
package platforms
1818

1919
import (
20+
"fmt"
2021
"testing"
2122
)
2223

23-
// Test the platform compatibility of the different
24-
// OS Versions considering two ltsc container image
25-
// versions (ltsc2019, ltsc2022)
24+
// Test the platform compatibility of the different OS Versions
2625
func Test_PlatformCompat(t *testing.T) {
27-
for testName, tc := range map[string]struct {
28-
hostOs uint16
29-
ctrOs uint16
26+
for _, tc := range []struct {
27+
hostOS uint16
28+
ctrOS uint16
3029
shouldRun bool
3130
}{
32-
"RS5Host_ltsc2019": {
33-
hostOs: rs5,
34-
ctrOs: rs5,
31+
{
32+
hostOS: LTSC2019,
33+
ctrOS: LTSC2019,
3534
shouldRun: true,
3635
},
37-
"RS5Host_ltsc2022": {
38-
hostOs: rs5,
39-
ctrOs: v21H2Server,
36+
{
37+
hostOS: LTSC2019,
38+
ctrOS: LTSC2022,
4039
shouldRun: false,
4140
},
42-
"WS2022Host_ltsc2019": {
43-
hostOs: v21H2Server,
44-
ctrOs: rs5,
41+
{
42+
hostOS: LTSC2022,
43+
ctrOS: LTSC2019,
4544
shouldRun: false,
4645
},
47-
"WS2022Host_ltsc2022": {
48-
hostOs: v21H2Server,
49-
ctrOs: v21H2Server,
46+
{
47+
hostOS: LTSC2022,
48+
ctrOS: LTSC2022,
5049
shouldRun: true,
5150
},
52-
"Wind11Host_ltsc2019": {
53-
hostOs: v22H2Win11,
54-
ctrOs: rs5,
51+
{
52+
hostOS: V22H2Win11,
53+
ctrOS: LTSC2019,
5554
shouldRun: false,
5655
},
57-
"Wind11Host_ltsc2022": {
58-
hostOs: v22H2Win11,
59-
ctrOs: v21H2Server,
56+
{
57+
hostOS: V22H2Win11,
58+
ctrOS: LTSC2022,
59+
shouldRun: true,
60+
},
61+
{
62+
hostOS: LTSC2025,
63+
ctrOS: LTSC2022,
64+
shouldRun: true,
65+
},
66+
{
67+
hostOS: LTSC2022,
68+
ctrOS: LTSC2025,
69+
shouldRun: false,
70+
},
71+
{
72+
hostOS: LTSC2022,
73+
ctrOS: V22H2Win11,
74+
shouldRun: false,
75+
},
76+
{
77+
hostOS: LTSC2025,
78+
ctrOS: V22H2Win11,
6079
shouldRun: true,
6180
},
6281
} {
63-
// Check if ltsc2019/ltsc2022 guest images are compatible on
64-
// the given host OS versions
65-
//
66-
hostOSVersion := windowsOSVersion{
67-
MajorVersion: 10,
68-
MinorVersion: 0,
69-
Build: tc.hostOs,
70-
}
71-
ctrOSVersion := windowsOSVersion{
72-
MajorVersion: 10,
73-
MinorVersion: 0,
74-
Build: tc.ctrOs,
75-
}
76-
if checkWindowsHostAndContainerCompat(hostOSVersion, ctrOSVersion) != tc.shouldRun {
77-
var expectedResultStr string
78-
if !tc.shouldRun {
79-
expectedResultStr = " NOT"
82+
t.Run(fmt.Sprintf("Host_%d_Ctr_%d", tc.hostOS, tc.ctrOS), func(t *testing.T) {
83+
hostOSVersion := windowsOSVersion{
84+
MajorVersion: 10,
85+
MinorVersion: 0,
86+
Build: tc.hostOS,
87+
}
88+
ctrOSVersion := windowsOSVersion{
89+
MajorVersion: 10,
90+
MinorVersion: 0,
91+
Build: tc.ctrOS,
92+
}
93+
if checkWindowsHostAndContainerCompat(hostOSVersion, ctrOSVersion) != tc.shouldRun {
94+
var expectedResultStr string
95+
if !tc.shouldRun {
96+
expectedResultStr = " NOT"
97+
}
98+
t.Fatalf("host %v should%s be able to run guest %v", tc.hostOS, expectedResultStr, tc.ctrOS)
8099
}
81-
t.Fatalf("Failed %v: host %v should%s be able to run guest %v", testName, tc.hostOs, expectedResultStr, tc.ctrOs)
82-
}
100+
})
83101
}
84102
}

0 commit comments

Comments
 (0)