Skip to content

Commit

Permalink
[release/0.9] Add support for platform compatibility check for window…
Browse files Browse the repository at this point in the history
…s + add windows builds (#1843)

* Add windows versions to windows builds

Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>

* Add support for platform compatibility check for windows (#1821)

Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
(cherry picked from commit 640a560)
Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>

---------

Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
  • Loading branch information
kiashok authored Jul 20, 2023
1 parent 43468fc commit 9cd2a01
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
35 changes: 35 additions & 0 deletions osversion/platform_compat_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package osversion

// List of stable ABI compliant ltsc releases
// Note: List must be sorted in ascending order
var compatLTSCReleases = []uint16{
V21H2Server,
}

// CheckHostAndContainerCompat checks if given host and container
// OS versions are compatible.
// It includes support for stable ABI compliant versions as well.
// Every release after WS 2022 will support the previous ltsc
// container image. Stable ABI is in preview mode for windows 11 client.
// Refer: https://learn.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility?tabs=windows-server-2022%2Cwindows-10#windows-server-host-os-compatibility
func CheckHostAndContainerCompat(host, ctr OSVersion) bool {
// check major minor versions of host and guest
if host.MajorVersion != ctr.MajorVersion ||
host.MinorVersion != ctr.MinorVersion {
return false
}

// If host is < WS 2022, exact version match is required
if host.Build < V21H2Server {
return host.Build == ctr.Build
}

var supportedLtscRelease uint16
for i := len(compatLTSCReleases) - 1; i >= 0; i-- {
if host.Build >= compatLTSCReleases[i] {
supportedLtscRelease = compatLTSCReleases[i]
break
}
}
return ctr.Build >= supportedLtscRelease && ctr.Build <= host.Build
}
68 changes: 68 additions & 0 deletions osversion/platform_compat_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package osversion

import (
"testing"
)

// Test the platform compatibility of the different
// OS Versions considering two ltsc container image
// versions (ltsc2019, ltsc2022)
func Test_PlatformCompat(t *testing.T) {
for testName, tc := range map[string]struct {
hostOs uint16
ctrOs uint16
shouldRun bool
}{
"RS5Host_ltsc2019": {
hostOs: RS5,
ctrOs: RS5,
shouldRun: true,
},
"RS5Host_ltsc2022": {
hostOs: RS5,
ctrOs: V21H2Server,
shouldRun: false,
},
"WS2022Host_ltsc2019": {
hostOs: V21H2Server,
ctrOs: RS5,
shouldRun: false,
},
"WS2022Host_ltsc2022": {
hostOs: V21H2Server,
ctrOs: V21H2Server,
shouldRun: true,
},
"Wind11Host_ltsc2019": {
hostOs: V22H2Win11,
ctrOs: RS5,
shouldRun: false,
},
"Wind11Host_ltsc2022": {
hostOs: V22H2Win11,
ctrOs: V21H2Server,
shouldRun: true,
},
} {
// Check if ltsc2019/ltsc2022 guest images are compatible on
// the given host OS versions
//
hostOSVersion := OSVersion{
MajorVersion: 10,
MinorVersion: 0,
Build: tc.hostOs,
}
ctrOSVersion := OSVersion{
MajorVersion: 10,
MinorVersion: 0,
Build: tc.ctrOs,
}
if CheckHostAndContainerCompat(hostOSVersion, ctrOSVersion) != tc.shouldRun {
var expectedResultStr string
if !tc.shouldRun {
expectedResultStr = " NOT"
}
t.Fatalf("Failed %v: host %v should%s be able to run guest %v", testName, tc.hostOs, expectedResultStr, tc.ctrOs)
}
}
}
8 changes: 8 additions & 0 deletions osversion/windowsbuilds.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ const (

// V21H2Server corresponds to Windows Server 2022 (ltsc2022).
V21H2Server = 20348
// LTSC2022 (Windows Server 2022) is an alias for [V21H2Server]
LTSC2022 = V21H2Server

// V21H2Win11 corresponds to Windows 11 (original release).
V21H2Win11 = 22000

// V22H2Win10 corresponds to Windows 10 (2022 Update).
V22H2Win10 = 19045

// V22H2Win11 corresponds to Windows 11 (2022 Update).
V22H2Win11 = 22621
)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9cd2a01

Please sign in to comment.