From bec6e4dd675f6b458d046ad79119a7b7989f2d82 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 1 Feb 2022 17:08:12 +0100 Subject: [PATCH] platforms.Normalize(): do not reset OSVersion and OSFeatures Commit fb0688362cafb5c24cfe6bd4f83765a0515af374 implemented the Normalize() function, but marked these fields as deprecated. It's unclear what the motivation was for this, as the fields are part of the OCI Image spec. On Windows, the OSVersion field specifically is important when matching images (as kernel versions may not be compatible). This patch updates platforms.Normalize() to preserve the OSVersion and OSFeatures fields. As a follow-up, we should look at defining an appropriate string-representation for these fields (possibly as part of the OCI Spec), and update platforms.Parse() accordingly. Signed-off-by: Sebastiaan van Stijn --- platforms/platforms.go | 5 ----- platforms/platforms_test.go | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/platforms/platforms.go b/platforms/platforms.go index 18216522d..8f955d036 100644 --- a/platforms/platforms.go +++ b/platforms/platforms.go @@ -257,10 +257,5 @@ func Format(platform specs.Platform) string { func Normalize(platform specs.Platform) specs.Platform { platform.OS = normalizeOS(platform.OS) platform.Architecture, platform.Variant = normalizeArch(platform.Architecture, platform.Variant) - - // these fields are deprecated, remove them - platform.OSFeatures = nil - platform.OSVersion = "" - return platform } diff --git a/platforms/platforms_test.go b/platforms/platforms_test.go index c070ddae1..fb24eab77 100644 --- a/platforms/platforms_test.go +++ b/platforms/platforms_test.go @@ -23,6 +23,7 @@ import ( "testing" specs "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/stretchr/testify/require" ) func TestParseSelector(t *testing.T) { @@ -364,3 +365,7 @@ func TestParseSelectorInvalid(t *testing.T) { }) } } + +func TestNormalize(t *testing.T) { + require.Equal(t, DefaultSpec(), Normalize(DefaultSpec())) +}