Skip to content

Commit

Permalink
distribution: remove custom matcher code
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Jun 27, 2018
1 parent f099771 commit 951faae
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions distribution/pull_v2_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekClo
}

func filterManifests(manifests []manifestlist.ManifestDescriptor, p specs.Platform) []manifestlist.ManifestDescriptor {
p = withDefault(p)
p = platforms.Normalize(withDefault(p))
m := platforms.NewMatcher(p)
var matches []manifestlist.ManifestDescriptor
for _, desc := range manifests {
if compareNormalized(toOCIPlatform(desc.Platform), p) {
if m.Match(toOCIPlatform(desc.Platform)) {
matches = append(matches, desc)
logrus.Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
}
}

// deprecated: backwards compatibility with older versions that didn't compare variant
if len(matches) == 0 && p.Architecture == "arm" {
p = normalize(p)
p = platforms.Normalize(p)
for _, desc := range manifests {
if desc.Platform.OS == p.OS && desc.Platform.Architecture == p.Architecture {
matches = append(matches, desc)
Expand Down Expand Up @@ -57,26 +58,3 @@ func withDefault(p specs.Platform) specs.Platform {
}
return p
}

func compareNormalized(p1, p2 specs.Platform) bool {
// remove after https://github.com/containerd/containerd/pull/2414
return p1.OS == p2.OS &&
p1.Architecture == p2.Architecture &&
p1.Variant == p2.Variant
}

func normalize(p specs.Platform) specs.Platform {
p = platforms.Normalize(p)
// remove after https://github.com/containerd/containerd/pull/2414
if p.Architecture == "arm" {
if p.Variant == "" {
p.Variant = "v7"
}
}
if p.Architecture == "arm64" {
if p.Variant == "" {
p.Variant = "v8"
}
}
return p
}

0 comments on commit 951faae

Please sign in to comment.