Skip to content

Commit 8df94a3

Browse files
committed
golangci: forbid uses of platforms.DefaultString()
The `platforms.DefaultString()` utility returns a platform-string for the local platform. Starting with [containerd/platforms@38a74d2], a new format is introduced to allow including OS-version, which is relevant for Windows. Versions of `platforms.DefaultString()` after [containerd/platforms@38a74d2] include the OS-version by default, which can be problematic if that string is either parsed by code not yet updated to support the new format, or (in general) when sending the platform to a remote / non-matching host (e.g. a Windows client sending to a Linux machine). Disallow using the `platforms.DefaultString()`, and recommend using `platforms.Format(platforms.DefaultSpec())` instead (which produces the old format without OS-version). Also add a warning about the cross-platform risks of using this function. [containerd/platforms@38a74d2]: containerd/platforms@38a74d2 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 499ac3a commit 8df94a3

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ linters-settings:
6262
- '^ctx\.Err(# use context\.Cause instead)?$'
6363
- '^fmt\.Errorf(# use errors\.Errorf instead)?$'
6464
- '^logrus\.(Trace|Debug|Info|Warn|Warning|Error|Fatal)(f|ln)?(# use bklog\.G or bklog\.L instead of logrus directly)?$'
65+
- '^platforms\.DefaultString(# use platforms\.Format(platforms\.DefaultSpec()) instead\. Be aware that DefaultSpec is for the local platform, so must be avoided when working cross-platform)?$'
6566
importas:
6667
alias:
6768
# Enforce alias to prevent it accidentally being used instead of our

client/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,7 @@ func testBuildExportScratch(t *testing.T, sb integration.Sandbox) {
25542554
imgs, err := testutil.ReadImages(sb.Context(), provider, desc)
25552555
require.NoError(t, err)
25562556
require.Len(t, imgs.Images, 1)
2557-
img := imgs.Find(platforms.DefaultString())
2557+
img := imgs.Find(platforms.Format(platforms.DefaultSpec()))
25582558
require.Empty(t, img.Layers)
25592559
require.Equal(t, platforms.DefaultSpec(), img.Img.Platform)
25602560

0 commit comments

Comments
 (0)