Merge pull request #4891 from tianon/generic-arm-vector
Refactor platforms.Only with a "platformVector" helper
This commit is contained in:
commit
9067796ce4
@ -113,7 +113,7 @@ func TestImagePullWithDistSourceLabel(t *testing.T) {
|
|||||||
key := fmt.Sprintf("containerd.io/distribution.source.%s", source)
|
key := fmt.Sprintf("containerd.io/distribution.source.%s", source)
|
||||||
|
|
||||||
// only check the target platform
|
// only check the target platform
|
||||||
childrenHandler := images.FilterPlatforms(images.ChildrenHandler(cs), pMatcher)
|
childrenHandler := images.LimitManifests(images.ChildrenHandler(cs), pMatcher, 1)
|
||||||
|
|
||||||
checkLabelHandler := func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
checkLabelHandler := func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
||||||
children, err := childrenHandler(ctx, desc)
|
children, err := childrenHandler(ctx, desc)
|
||||||
|
@ -16,7 +16,12 @@
|
|||||||
|
|
||||||
package platforms
|
package platforms
|
||||||
|
|
||||||
import specs "github.com/opencontainers/image-spec/specs-go/v1"
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
|
)
|
||||||
|
|
||||||
// MatchComparer is able to match and compare platforms to
|
// MatchComparer is able to match and compare platforms to
|
||||||
// filter and sort platforms.
|
// filter and sort platforms.
|
||||||
@ -26,103 +31,37 @@ type MatchComparer interface {
|
|||||||
Less(specs.Platform, specs.Platform) bool
|
Less(specs.Platform, specs.Platform) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only returns a match comparer for a single platform
|
// platformVector returns an (ordered) vector of appropriate specs.Platform
|
||||||
// using default resolution logic for the platform.
|
// objects to try matching for the given platform object (see platforms.Only).
|
||||||
//
|
func platformVector(platform specs.Platform) []specs.Platform {
|
||||||
// For ARMv8, will also match ARMv7, ARMv6 and ARMv5 (for 32bit runtimes)
|
vector := []specs.Platform{platform}
|
||||||
// For ARMv7, will also match ARMv6 and ARMv5
|
|
||||||
// For ARMv6, will also match ARMv5
|
switch platform.Architecture {
|
||||||
func Only(platform specs.Platform) MatchComparer {
|
case "arm":
|
||||||
platform = Normalize(platform)
|
if armVersion, err := strconv.Atoi(strings.TrimPrefix(platform.Variant, "v")); err == nil && armVersion > 5 {
|
||||||
if platform.Architecture == "arm" {
|
for armVersion--; armVersion >= 5; armVersion-- {
|
||||||
if platform.Variant == "v8" {
|
vector = append(vector, specs.Platform{
|
||||||
return orderedPlatformComparer{
|
|
||||||
matchers: []Matcher{
|
|
||||||
&matcher{
|
|
||||||
Platform: platform,
|
|
||||||
},
|
|
||||||
&matcher{
|
|
||||||
Platform: specs.Platform{
|
|
||||||
Architecture: platform.Architecture,
|
Architecture: platform.Architecture,
|
||||||
OS: platform.OS,
|
OS: platform.OS,
|
||||||
OSVersion: platform.OSVersion,
|
OSVersion: platform.OSVersion,
|
||||||
OSFeatures: platform.OSFeatures,
|
OSFeatures: platform.OSFeatures,
|
||||||
Variant: "v7",
|
Variant: "v" + strconv.Itoa(armVersion),
|
||||||
},
|
})
|
||||||
},
|
|
||||||
&matcher{
|
|
||||||
Platform: specs.Platform{
|
|
||||||
Architecture: platform.Architecture,
|
|
||||||
OS: platform.OS,
|
|
||||||
OSVersion: platform.OSVersion,
|
|
||||||
OSFeatures: platform.OSFeatures,
|
|
||||||
Variant: "v6",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
&matcher{
|
|
||||||
Platform: specs.Platform{
|
|
||||||
Architecture: platform.Architecture,
|
|
||||||
OS: platform.OS,
|
|
||||||
OSVersion: platform.OSVersion,
|
|
||||||
OSFeatures: platform.OSFeatures,
|
|
||||||
Variant: "v5",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if platform.Variant == "v7" {
|
|
||||||
return orderedPlatformComparer{
|
|
||||||
matchers: []Matcher{
|
|
||||||
&matcher{
|
|
||||||
Platform: platform,
|
|
||||||
},
|
|
||||||
&matcher{
|
|
||||||
Platform: specs.Platform{
|
|
||||||
Architecture: platform.Architecture,
|
|
||||||
OS: platform.OS,
|
|
||||||
OSVersion: platform.OSVersion,
|
|
||||||
OSFeatures: platform.OSFeatures,
|
|
||||||
Variant: "v6",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
&matcher{
|
|
||||||
Platform: specs.Platform{
|
|
||||||
Architecture: platform.Architecture,
|
|
||||||
OS: platform.OS,
|
|
||||||
OSVersion: platform.OSVersion,
|
|
||||||
OSFeatures: platform.OSFeatures,
|
|
||||||
Variant: "v5",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if platform.Variant == "v6" {
|
|
||||||
return orderedPlatformComparer{
|
|
||||||
matchers: []Matcher{
|
|
||||||
&matcher{
|
|
||||||
Platform: platform,
|
|
||||||
},
|
|
||||||
&matcher{
|
|
||||||
Platform: specs.Platform{
|
|
||||||
Architecture: platform.Architecture,
|
|
||||||
OS: platform.OS,
|
|
||||||
OSVersion: platform.OSVersion,
|
|
||||||
OSFeatures: platform.OSFeatures,
|
|
||||||
Variant: "v5",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return singlePlatformComparer{
|
return vector
|
||||||
Matcher: &matcher{
|
|
||||||
Platform: platform,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only returns a match comparer for a single platform
|
||||||
|
// using default resolution logic for the platform.
|
||||||
|
//
|
||||||
|
// For arm/v8, will also match arm/v7, arm/v6 and arm/v5
|
||||||
|
// For arm/v7, will also match arm/v6 and arm/v5
|
||||||
|
// For arm/v6, will also match arm/v5
|
||||||
|
func Only(platform specs.Platform) MatchComparer {
|
||||||
|
return Ordered(platformVector(Normalize(platform))...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ordered returns a platform MatchComparer which matches any of the platforms
|
// Ordered returns a platform MatchComparer which matches any of the platforms
|
||||||
@ -153,14 +92,6 @@ func Any(platforms ...specs.Platform) MatchComparer {
|
|||||||
// with preference for ordering.
|
// with preference for ordering.
|
||||||
var All MatchComparer = allPlatformComparer{}
|
var All MatchComparer = allPlatformComparer{}
|
||||||
|
|
||||||
type singlePlatformComparer struct {
|
|
||||||
Matcher
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c singlePlatformComparer) Less(p1, p2 specs.Platform) bool {
|
|
||||||
return c.Match(p1) && !c.Match(p2)
|
|
||||||
}
|
|
||||||
|
|
||||||
type orderedPlatformComparer struct {
|
type orderedPlatformComparer struct {
|
||||||
matchers []Matcher
|
matchers []Matcher
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user