libimage.NormalizePlatform: normalize default variant as per specified arch
As of now NormalizePlatform ignores normalizing or setting default variants for specific arch types thus producing empty variants in results even when default variants were expected for such cases. Example consider: `linux/armhf` -> `{os:linux, arch: arm, variant: v7}` Signed-off-by: Aditya R <arajan@redhat.com>
This commit is contained in:
parent
13850996f1
commit
0f0e8ef3bc
|
@ -54,6 +54,34 @@ func TestNormalizePlatform(t *testing.T) {
|
||||||
platform{"linux", "aarch64", ""},
|
platform{"linux", "aarch64", ""},
|
||||||
platform{"linux", "arm64", ""},
|
platform{"linux", "arm64", ""},
|
||||||
},
|
},
|
||||||
|
// Verify: https://github.com/containerd/containerd/blob/main/platforms/database.go#L97
|
||||||
|
{
|
||||||
|
platform{"linux", "arm64", "8"},
|
||||||
|
platform{"linux", "arm64", "v8"},
|
||||||
|
},
|
||||||
|
// Verify: https://github.com/containerd/containerd/blob/main/platforms/database.go#L100
|
||||||
|
{
|
||||||
|
platform{"linux", "armhf", ""},
|
||||||
|
platform{"linux", "arm", "v7"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform{"linux", "armhf", "v7"},
|
||||||
|
platform{"linux", "arm", "v7"},
|
||||||
|
},
|
||||||
|
// Verify: https://github.com/containerd/containerd/blob/main/platforms/database.go#L103
|
||||||
|
{
|
||||||
|
platform{"linux", "armel", ""},
|
||||||
|
platform{"linux", "arm", "v6"},
|
||||||
|
},
|
||||||
|
// Verify: https://github.com/containerd/containerd/blob/main/platforms/database.go#L103
|
||||||
|
{
|
||||||
|
platform{"linux", "armel", "v6"},
|
||||||
|
platform{"linux", "arm", "v6"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform{"linux", "armel", ""},
|
||||||
|
platform{"linux", "arm", "v6"},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
os, arch, variant := NormalizePlatform(test.input.os, test.input.arch, test.input.variant)
|
os, arch, variant := NormalizePlatform(test.input.os, test.input.arch, test.input.variant)
|
||||||
assert.Equal(t, test.expected.os, os, test.input)
|
assert.Equal(t, test.expected.os, os, test.input)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/containerd/containerd/platforms"
|
"github.com/containerd/containerd/platforms"
|
||||||
|
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,9 +21,18 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NormalizePlatform normalizes (according to the OCI spec) the specified os,
|
// NormalizePlatform normalizes (according to the OCI spec) the specified os,
|
||||||
// arch and variant. If left empty, the individual item will not be normalized.
|
// arch and variant. If left empty, the individual item will be normalized.
|
||||||
func NormalizePlatform(rawOS, rawArch, rawVariant string) (os, arch, variant string) {
|
func NormalizePlatform(rawOS, rawArch, rawVariant string) (os, arch, variant string) {
|
||||||
rawPlatform := toPlatformString(rawOS, rawArch, rawVariant)
|
platformSpec := v1.Platform{
|
||||||
|
OS: rawOS,
|
||||||
|
Architecture: rawArch,
|
||||||
|
Variant: rawVariant,
|
||||||
|
}
|
||||||
|
normalizedSpec := platforms.Normalize(platformSpec)
|
||||||
|
if normalizedSpec.Variant == "" && rawVariant != "" {
|
||||||
|
normalizedSpec.Variant = rawVariant
|
||||||
|
}
|
||||||
|
rawPlatform := toPlatformString(normalizedSpec.OS, normalizedSpec.Architecture, normalizedSpec.Variant)
|
||||||
normalizedPlatform, err := platforms.Parse(rawPlatform)
|
normalizedPlatform, err := platforms.Parse(rawPlatform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error normalizing platform: %v", err)
|
logrus.Debugf("Error normalizing platform: %v", err)
|
||||||
|
@ -38,7 +48,7 @@ func NormalizePlatform(rawOS, rawArch, rawVariant string) (os, arch, variant str
|
||||||
arch = normalizedPlatform.Architecture
|
arch = normalizedPlatform.Architecture
|
||||||
}
|
}
|
||||||
variant = rawVariant
|
variant = rawVariant
|
||||||
if rawVariant != "" {
|
if rawVariant != "" || (rawVariant == "" && normalizedPlatform.Variant != "") {
|
||||||
variant = normalizedPlatform.Variant
|
variant = normalizedPlatform.Variant
|
||||||
}
|
}
|
||||||
return os, arch, variant
|
return os, arch, variant
|
||||||
|
|
Loading…
Reference in New Issue