platforms.Normalize(): do not reset OSVersion and OSFeatures

Commit fb0688362c 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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-02-01 17:08:12 +01:00
parent 52b8ca5545
commit bec6e4dd67
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 5 additions and 5 deletions

View File

@ -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
}

View File

@ -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()))
}