|
| 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 | +} |
0 commit comments