Merge pull request #45122 from vvoland/c8d-upstream-inspect-digest

c8d/inspect: Add digested reference to details
This commit is contained in:
Sebastiaan van Stijn 2023-03-30 22:53:12 +02:00 committed by GitHub
commit 0656059ae7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -99,7 +99,9 @@ func (i *ImageService) GetImage(ctx context.Context, refOrID string, options ima
if err != nil {
return nil, err
}
tags := make([]reference.Named, 0, len(tagged))
// Each image will result in 2 references (named and digested).
refs := make([]reference.Named, 0, len(tagged)*2)
for _, i := range tagged {
if i.UpdatedAt.After(lastUpdated) {
lastUpdated = i.UpdatedAt
@ -121,11 +123,21 @@ func (i *ImageService) GetImage(ctx context.Context, refOrID string, options ima
logrus.WithField("name", name).WithError(err).Error("failed to parse image name as reference")
continue
}
tags = append(tags, name)
refs = append(refs, name)
digested, err := reference.WithDigest(reference.TrimNamed(name), desc.Digest)
if err != nil {
// This could only happen if digest is invalid, but considering that
// we get it from the Descriptor it's highly unlikely.
// Log error just in case.
logrus.WithError(err).Error("failed to create digested reference")
continue
}
refs = append(refs, digested)
}
img.Details = &image.Details{
References: tags,
References: refs,
Size: size,
Metadata: nil,
Driver: i.snapshotter,