From 94a8cf9aaecbc0135442eced53234019a5f504ed Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 11 Sep 2026 12:17:37 +0200 Subject: [PATCH 1/2] go fix, and simplify Windows compatibility release lookup Use slices.Backward, as suggested by go fix, to iterate over LTSC releases in reverse order. Default the compatibility floor to the first release and update it only when the matching release has a predecessor. Adjust the comments to describe the fallback. Compatibility behavior is unchanged. Signed-off-by: Sebastiaan van Stijn --- platform_windows_compat.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/platform_windows_compat.go b/platform_windows_compat.go index 4aa162a..bed579b 100644 --- a/platform_windows_compat.go +++ b/platform_windows_compat.go @@ -82,7 +82,7 @@ func checkWindowsHostAndContainerCompat(host, ctr windowsOSVersion) bool { return false } - // If host is < WS 2022, exact version match is required + // Before WS2022, exact build matching is required. if host.Build < ltsc2022 { return host.Build == ctr.Build } @@ -91,20 +91,16 @@ func checkWindowsHostAndContainerCompat(host, ctr windowsOSVersion) bool { // ABI policy, every host from LTSC N up to (but not including) LTSC N+1 can // run containers from LTSC N-1 up to the host build. // - // So we find the largest LTSC <= host.Build, then step one entry back to + // Find the largest LTSC <= host.Build, then step one entry back to // get the floor. If host.Build is past the latest LTSC in the list // (e.g. a 26200 host, which is in the WS2025 generation), the floor is // still the previous LTSC (20348), not the latest LTSC itself. // - // If host is the very first LTSC (or no entry matches, which is impossible - // here since we already checked host.Build >= ltsc2022), use that LTSC as - // the floor. - var supportedLTSCRelease uint16 = ltsc2022 - for i := len(compatLTSCReleases) - 1; i >= 0; i-- { - if host.Build >= compatLTSCReleases[i] { - if i == 0 { - supportedLTSCRelease = compatLTSCReleases[i] - } else { + // Default to the first LTSC when the matching release has no predecessor. + supportedLTSCRelease := compatLTSCReleases[0] + for i, release := range slices.Backward(compatLTSCReleases) { + if host.Build >= release { + if i > 0 { supportedLTSCRelease = compatLTSCReleases[i-1] } break From 5c22cb30be2930cb7b8d4bbe5314547d6c18453a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 11 Sep 2026 12:25:04 +0200 Subject: [PATCH 2/2] fix minor linting issues Signed-off-by: Sebastiaan van Stijn --- compare_test.go | 16 +++++----------- cpuinfo_linux_test.go | 7 +++---- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/compare_test.go b/compare_test.go index 1968e51..a84e3e9 100644 --- a/compare_test.go +++ b/compare_test.go @@ -23,7 +23,7 @@ import ( ) func TestOnly(t *testing.T) { - for _, tc := range []struct { + for _, testcase := range []struct { platform string matches map[bool][]string }{ @@ -299,7 +299,6 @@ func TestOnly(t *testing.T) { }, }, } { - testcase := tc t.Run(testcase.platform, func(t *testing.T) { p, err := Parse(testcase.platform) if err != nil { @@ -322,7 +321,7 @@ func TestOnly(t *testing.T) { } func TestOnlyStrict(t *testing.T) { - for _, tc := range []struct { + for _, testcase := range []struct { platform string matches map[bool][]string }{ @@ -573,7 +572,6 @@ func TestOnlyStrict(t *testing.T) { }, }, } { - testcase := tc t.Run(testcase.platform, func(t *testing.T) { p, err := Parse(testcase.platform) if err != nil { @@ -596,7 +594,7 @@ func TestOnlyStrict(t *testing.T) { } func TestOnlyOS(t *testing.T) { - for _, tc := range []struct { + for _, testcase := range []struct { platform string matches map[bool][]string }{ @@ -643,7 +641,6 @@ func TestOnlyOS(t *testing.T) { }, }, } { - testcase := tc t.Run(testcase.platform, func(t *testing.T) { p, err := Parse(testcase.platform) if err != nil { @@ -666,7 +663,7 @@ func TestOnlyOS(t *testing.T) { } func TestOnlyOSLess(t *testing.T) { - for _, tc := range []struct { + for _, testcase := range []struct { platform string platforms []string expected []string @@ -690,7 +687,6 @@ func TestOnlyOSLess(t *testing.T) { expected: []string{"linux/amd64", "linux/arm64", "windows/amd64", "darwin/amd64"}, }, } { - testcase := tc t.Run(testcase.platform, func(t *testing.T) { p, err := Parse(testcase.platform) if err != nil { @@ -716,7 +712,7 @@ func TestOnlyOSLess(t *testing.T) { } func TestCompareOSFeatures(t *testing.T) { - for _, tc := range []struct { + for _, testcase := range []struct { platform string platforms []string expected []string @@ -753,7 +749,6 @@ func TestCompareOSFeatures(t *testing.T) { []string{"linux(+other)/amd64", "linux(7.2+other)/amd64", "linux/amd64", "linux(7.1)/amd64"}, }, } { - testcase := tc t.Run(testcase.platform, func(t *testing.T) { t.Parallel() p, err := Parse(testcase.platform) @@ -783,7 +778,6 @@ func TestCompareOSFeatures(t *testing.T) { }, } { mc := stc.mc - testcase := testcase t.Run(stc.name, func(t *testing.T) { p, err := ParseAll(testcase.platforms) if err != nil { diff --git a/cpuinfo_linux_test.go b/cpuinfo_linux_test.go index 59a8198..55e50c3 100644 --- a/cpuinfo_linux_test.go +++ b/cpuinfo_linux_test.go @@ -121,10 +121,9 @@ func TestGetCPUVariantFromArch(t *testing.T) { if err == nil { if testcase.expectedErr != nil { t.Fatalf("Expect to get error: %v, however no error got", testcase.expectedErr) - } else { - if variant != testcase.output { - t.Fatalf("Expect to get variant: %v, however %v returned", testcase.output, variant) - } + } + if variant != testcase.output { + t.Fatalf("Expect to get variant: %v, however %v returned", testcase.output, variant) } } else { if !errors.Is(err, testcase.expectedErr) {