Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inventory: sort the images based on the sorted tags and not in the hash #251

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/container/set.go
Expand Up @@ -31,6 +31,7 @@ func (a Set) Minus(b Set) Set {
for k := range b {
delete(c, k)
}

return c
}

Expand All @@ -43,6 +44,7 @@ func (a Set) Union(b Set) Set {
for k, v := range b {
c[k] = v
}

return c
}

Expand All @@ -55,5 +57,6 @@ func (a Set) Intersection(b Set) Set {
c[k] = v
}
}

return c
}
3 changes: 3 additions & 0 deletions lib/dockerregistry/grow_manifest.go
Expand Up @@ -293,20 +293,23 @@ func Union(a, b RegInvImage) RegInvImage {
// injection.
if a[imageName] == nil {
a[imageName] = digestTags

continue
}
for digest, tags := range digestTags {
// If a has the image but not this digest, inject just this digest
// and all associated tags.
if a[imageName][digest] == nil {
a[imageName][digest] = tags

continue
}
// If c has the digest already, try to inject those tags in b that
// are not already in a.
tagSlice := TagSlice{}
for tag := range tags.Union(a[imageName][digest]) {
if tag == "latest" {

continue
}
tagSlice = append(tagSlice, tag)
Expand Down
4 changes: 3 additions & 1 deletion lib/dockerregistry/inventory.go
Expand Up @@ -1771,8 +1771,9 @@ func (rii *RegInvImage) ToSorted() []ImageWithDigestSlice {
tags: tags,
})
}
// sort the digest beased on the first tag which was sorted above
sort.Slice(digests, func(i, j int) bool {
return digests[i].hash < digests[j].hash
return digests[i].tags[0] < digests[j].tags[0]
})

images = append(images, ImageWithDigestSlice{
Expand Down Expand Up @@ -2665,6 +2666,7 @@ func (payload GCRPubSubPayload) matchImage(
for _, tag := range tags {
if payload.Tag == tag {
m.TagMatch = true

break
}
}
Expand Down