Avoid parsing image metadata

Avoid parsing metadata that the image library keeps in order to find an
image's top layer and creation date; instead, use the values which the
storage library now makes available, which will be correct once we merge
PR #654 or something like it.

Instead of assuming the last blob which was added for the image was the
manifest, read it directly and compute its digest ourselves.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai 2017-07-25 15:33:41 -04:00
parent 7e9ac9700b
commit cb0bb94c68
4 changed files with 33 additions and 91 deletions

View file

@ -7,6 +7,7 @@ import (
"github.com/containers/storage"
"github.com/kubernetes-incubator/cri-o/cmd/kpod/docker"
"github.com/kubernetes-incubator/cri-o/libkpod/driver"
digest "github.com/opencontainers/go-digest"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)
@ -17,6 +18,7 @@ type ImageData struct {
ID string
Tags []string
Digests []string
Digest digest.Digest
Parent string
Comment string
Created *time.Time
@ -32,11 +34,6 @@ type ImageData struct {
RootFS ociv1.RootFS
}
type rootFS struct {
Type string
Layers []string
}
// ParseImageNames parses the names we've stored with an image into a list of
// tagged references and a list of references which contain digests.
func ParseImageNames(names []string) (tags, digests []string, err error) {
@ -85,10 +82,7 @@ func GetImageData(store storage.Store, name string) (*ImageData, error) {
return nil, err
}
topLayerID, err := GetTopLayerID(*img)
if err != nil {
return nil, err
}
topLayerID := img.TopLayer
driverMetadata, err := driver.GetDriverMetadata(store, topLayerID)
if err != nil {
@ -104,7 +98,7 @@ func GetImageData(store storage.Store, name string) (*ImageData, error) {
return nil, err
}
virtualSize, err := Size(store, *img)
digest, virtualSize, err := DigestAndSize(store, *img)
if err != nil {
return nil, err
}
@ -113,6 +107,7 @@ func GetImageData(store storage.Store, name string) (*ImageData, error) {
ID: img.ID,
Tags: tags,
Digests: digests,
Digest: digest,
Parent: string(cid.Docker.Parent),
Comment: cid.OCIv1.History[0].Comment,
Created: cid.OCIv1.Created,