Skip to content

Commit f680838

Browse files
committed
Remove hcsshim import from repo
Move windows CheckHostAndContainerCompat() function from hcsshim locally to platform repo itself Signed-off-by: Kirtana Ashok <[email protected]>
1 parent c1438e9 commit f680838

5 files changed

Lines changed: 168 additions & 10 deletions

File tree

defaults_windows.go

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

25-
"github.com/Microsoft/hcsshim/osversion"
2625
specs "github.com/opencontainers/image-spec/specs-go/v1"
2726
"golang.org/x/sys/windows"
2827
)
@@ -56,25 +55,25 @@ func (m windowsmatcher) Match(p specs.Platform) bool {
5655
return true
5756
}
5857

59-
hostOsVersion := GetOsVersion(m.osVersionPrefix)
60-
ctrOsVersion := GetOsVersion(p.OSVersion)
61-
return osversion.CheckHostAndContainerCompat(hostOsVersion, ctrOsVersion)
58+
hostOsVersion := getOSVersion(m.osVersionPrefix)
59+
ctrOsVersion := getOSVersion(p.OSVersion)
60+
return checkHostAndContainerCompat(hostOsVersion, ctrOsVersion)
6261
}
6362

6463
return match
6564
}
6665

67-
func GetOsVersion(osVersionPrefix string) osversion.OSVersion {
66+
func getOSVersion(osVersionPrefix string) osVersion {
6867
parts := strings.Split(osVersionPrefix, ".")
6968
if len(parts) < 3 {
70-
return osversion.OSVersion{}
69+
return osVersion{}
7170
}
7271

7372
majorVersion, _ := strconv.Atoi(parts[0])
7473
minorVersion, _ := strconv.Atoi(parts[1])
7574
buildNumber, _ := strconv.Atoi(parts[2])
7675

77-
return osversion.OSVersion{
76+
return osVersion{
7877
MajorVersion: uint8(majorVersion),
7978
MinorVersion: uint8(minorVersion),
8079
Build: uint16(buildNumber),

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/containerd/platforms
33
go 1.20
44

55
require (
6-
github.com/Microsoft/hcsshim v0.10.0
76
github.com/containerd/log v0.1.0
87
github.com/opencontainers/image-spec v1.1.0-rc5
98
github.com/stretchr/testify v1.8.4

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/Microsoft/hcsshim v0.10.0 h1:PbvoxdUGgXxyirmN5Oncp3POLkxEG5LbWCEBfWmHTGA=
2-
github.com/Microsoft/hcsshim v0.10.0/go.mod h1:3j1trOamcUdi86J5Tr5+1BpqMjSv/QeRWkX2whBF6dY=
31
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
42
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
53
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

platform_compat_windows.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package platforms
18+
19+
// osVersion is a wrapper for Windows version information
20+
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
21+
type osVersion struct {
22+
Version uint32
23+
MajorVersion uint8
24+
MinorVersion uint8
25+
Build uint16
26+
}
27+
28+
// Windows Client and Server build numbers.
29+
//
30+
// See:
31+
// https://learn.microsoft.com/en-us/windows/release-health/release-information
32+
// https://learn.microsoft.com/en-us/windows/release-health/windows-server-release-info
33+
// https://learn.microsoft.com/en-us/windows/release-health/windows11-release-information
34+
const (
35+
// rs5 (version 1809, codename "Redstone 5") corresponds to Windows Server
36+
// 2019 (ltsc2019), and Windows 10 (October 2018 Update).
37+
rs5 = 17763
38+
39+
// v21H2Server corresponds to Windows Server 2022 (ltsc2022).
40+
v21H2Server = 20348
41+
42+
// v22H2Win11 corresponds to Windows 11 (2022 Update).
43+
v22H2Win11 = 22621
44+
)
45+
46+
// List of stable ABI compliant ltsc releases
47+
// Note: List must be sorted in ascending order
48+
var compatLTSCReleases = []uint16{
49+
v21H2Server,
50+
}
51+
52+
// CheckHostAndContainerCompat checks if given host and container
53+
// OS versions are compatible.
54+
// It includes support for stable ABI compliant versions as well.
55+
// Every release after WS 2022 will support the previous ltsc
56+
// container image. Stable ABI is in preview mode for windows 11 client.
57+
// Refer: https://learn.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility?tabs=windows-server-2022%2Cwindows-10#windows-server-host-os-compatibility
58+
func checkHostAndContainerCompat(host, ctr osVersion) bool {
59+
// check major minor versions of host and guest
60+
if host.MajorVersion != ctr.MajorVersion ||
61+
host.MinorVersion != ctr.MinorVersion {
62+
return false
63+
}
64+
65+
// If host is < WS 2022, exact version match is required
66+
if host.Build < v21H2Server {
67+
return host.Build == ctr.Build
68+
}
69+
70+
var supportedLtscRelease uint16
71+
for i := len(compatLTSCReleases) - 1; i >= 0; i-- {
72+
if host.Build >= compatLTSCReleases[i] {
73+
supportedLtscRelease = compatLTSCReleases[i]
74+
break
75+
}
76+
}
77+
return ctr.Build >= supportedLtscRelease && ctr.Build <= host.Build
78+
}

platform_compat_windows_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package platforms
18+
19+
import (
20+
"testing"
21+
)
22+
23+
// Test the platform compatibility of the different
24+
// OS Versions considering two ltsc container image
25+
// versions (ltsc2019, ltsc2022)
26+
func Test_PlatformCompat(t *testing.T) {
27+
for testName, tc := range map[string]struct {
28+
hostOs uint16
29+
ctrOs uint16
30+
shouldRun bool
31+
}{
32+
"RS5Host_ltsc2019": {
33+
hostOs: rs5,
34+
ctrOs: rs5,
35+
shouldRun: true,
36+
},
37+
"RS5Host_ltsc2022": {
38+
hostOs: rs5,
39+
ctrOs: v21H2Server,
40+
shouldRun: false,
41+
},
42+
"WS2022Host_ltsc2019": {
43+
hostOs: v21H2Server,
44+
ctrOs: rs5,
45+
shouldRun: false,
46+
},
47+
"WS2022Host_ltsc2022": {
48+
hostOs: v21H2Server,
49+
ctrOs: v21H2Server,
50+
shouldRun: true,
51+
},
52+
"Wind11Host_ltsc2019": {
53+
hostOs: v22H2Win11,
54+
ctrOs: rs5,
55+
shouldRun: false,
56+
},
57+
"Wind11Host_ltsc2022": {
58+
hostOs: v22H2Win11,
59+
ctrOs: v21H2Server,
60+
shouldRun: true,
61+
},
62+
} {
63+
// Check if ltsc2019/ltsc2022 guest images are compatible on
64+
// the given host OS versions
65+
//
66+
hostOSVersion := osVersion{
67+
MajorVersion: 10,
68+
MinorVersion: 0,
69+
Build: tc.hostOs,
70+
}
71+
ctrOSVersion := osVersion{
72+
MajorVersion: 10,
73+
MinorVersion: 0,
74+
Build: tc.ctrOs,
75+
}
76+
if checkHostAndContainerCompat(hostOSVersion, ctrOSVersion) != tc.shouldRun {
77+
var expectedResultStr string
78+
if !tc.shouldRun {
79+
expectedResultStr = " NOT"
80+
}
81+
t.Fatalf("Failed %v: host %v should%s be able to run guest %v", testName, tc.hostOs, expectedResultStr, tc.ctrOs)
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)