Skip to content

Commit

Permalink
platform matcher: use compat matrix
Browse files Browse the repository at this point in the history
Use the entire compatibility matrix when matching the platform of a
specific image to possible candidates.

Context: github.com/containers/podman/issues/9637
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
  • Loading branch information
vrothberg committed Mar 12, 2021
1 parent 9c64ce5 commit 08f2e05
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
20 changes: 8 additions & 12 deletions internal/pkg/platform/platform_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ var compatibility = map[string][]string{
"arm64": {"v8"},
}

// baseVariants contains, for a specified architecture, a variant that is known to be
// supported by _all_ machines using that architecture.
// Architectures that don’t have variants, or where there are possible versions without
// an established variant name, should not have an entry here.
var baseVariants = map[string]string{
"arm64": "v8",
}

// WantedPlatforms returns all compatible platforms with the platform specifics possibly overridden by user,
// the most compatible platform is first.
// If some option (arch, os, variant) is not present, a value from current platform is detected.
Expand Down Expand Up @@ -158,6 +150,8 @@ func WantedPlatforms(ctx *types.SystemContext) ([]imgspecv1.Platform, error) {

var variants []string = nil
if wantedVariant != "" {
// If the user requested a specific variant, we'll walk down
// the list from most to least compatible.
if compatibility[wantedArch] != nil {
variantOrder := compatibility[wantedArch]
for i, v := range variantOrder {
Expand All @@ -171,12 +165,14 @@ func WantedPlatforms(ctx *types.SystemContext) ([]imgspecv1.Platform, error) {
// user wants a variant which we know nothing about - not even compatibility
variants = []string{wantedVariant}
}
// Make sure to have a candidate with an empty variant as well.
variants = append(variants, "")
} else {
variants = append(variants, "") // No variant specified, use a “no variant specified” image if present
if baseVariant, ok := baseVariants[wantedArch]; ok {
// But also accept an image with the “base” variant for the architecture, if it exists.
variants = append(variants, baseVariant)
// Make sure to have a candidate with an empty variant as well.
variants = append(variants, "")
// If available add the entire compatibility matrix for the specific architecture.
if possibleVariants, ok := compatibility[wantedArch]; ok {
variants = append(variants, possibleVariants...)
}
}

Expand Down
12 changes: 11 additions & 1 deletion internal/pkg/platform/platform_matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@ func TestWantedPlatforms(t *testing.T) {
{OS: "linux", Architecture: "amd64", Variant: ""},
},
},
{ // ARM
{ // ARM with variant
types.SystemContext{ArchitectureChoice: "arm", OSChoice: "linux", VariantChoice: "v6"},
[]imgspecv1.Platform{
{OS: "linux", Architecture: "arm", Variant: "v6"},
{OS: "linux", Architecture: "arm", Variant: "v5"},
{OS: "linux", Architecture: "arm", Variant: ""},
},
},
{ // ARM without variant
types.SystemContext{ArchitectureChoice: "arm", OSChoice: "linux"},
[]imgspecv1.Platform{
{OS: "linux", Architecture: "arm", Variant: ""},
{OS: "linux", Architecture: "arm", Variant: "v8"},
{OS: "linux", Architecture: "arm", Variant: "v7"},
{OS: "linux", Architecture: "arm", Variant: "v6"},
{OS: "linux", Architecture: "arm", Variant: "v5"},
},
},
{ // ARM64 has a base variant
types.SystemContext{ArchitectureChoice: "arm64", OSChoice: "linux"},
[]imgspecv1.Platform{
Expand Down

0 comments on commit 08f2e05

Please sign in to comment.