faster image inspection

Vendor the latest HEAD in c/common to pull in changes for a faster
inspection of images.  Previously, only the size computation was
optional, now the one for the parent image is as well.

In many cases, the parent image is not needed but it takes around 10ms
on my local machine.  With this change, we cut off 10ms from many code
paths, most importantly, container creation.

[NO NEW TESTS NEEDED]

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2021-10-08 14:45:19 +02:00
parent 14c0fcc6b7
commit fad14dafe1
13 changed files with 59 additions and 31 deletions

View File

@ -50,19 +50,39 @@ type RootFS struct {
Layers []digest.Digest `json:"Layers"`
}
// Inspect inspects the image. Use `withSize` to also perform the
// comparatively expensive size computation of the image.
func (i *Image) Inspect(ctx context.Context, withSize bool) (*ImageData, error) {
// InspectOptions allow for customizing inspecting images.
type InspectOptions struct {
// Compute the size of the image (expensive).
WithSize bool
// Compute the parent of the image (expensive).
WithParent bool
}
// Inspect inspects the image.
func (i *Image) Inspect(ctx context.Context, options *InspectOptions) (*ImageData, error) {
logrus.Debugf("Inspecting image %s", i.ID())
if options == nil {
options = &InspectOptions{}
}
if i.cached.completeInspectData != nil {
if withSize && i.cached.completeInspectData.Size == int64(-1) {
if options.WithSize && i.cached.completeInspectData.Size == int64(-1) {
size, err := i.Size()
if err != nil {
return nil, err
}
i.cached.completeInspectData.Size = size
}
if options.WithParent && i.cached.completeInspectData.Parent == "" {
parentImage, err := i.Parent(ctx)
if err != nil {
return nil, err
}
if parentImage != nil {
i.cached.completeInspectData.Parent = parentImage.ID()
}
}
return i.cached.completeInspectData, nil
}
@ -75,10 +95,7 @@ func (i *Image) Inspect(ctx context.Context, withSize bool) (*ImageData, error)
if err != nil {
return nil, err
}
parentImage, err := i.Parent(ctx)
if err != nil {
return nil, err
}
repoTags, err := i.RepoTags()
if err != nil {
return nil, err
@ -93,7 +110,7 @@ func (i *Image) Inspect(ctx context.Context, withSize bool) (*ImageData, error)
}
size := int64(-1)
if withSize {
if options.WithSize {
size, err = i.Size()
if err != nil {
return nil, err
@ -124,8 +141,14 @@ func (i *Image) Inspect(ctx context.Context, withSize bool) (*ImageData, error)
NamesHistory: i.NamesHistory(),
}
if parentImage != nil {
data.Parent = parentImage.ID()
if options.WithParent {
parentImage, err := i.Parent(ctx)
if err != nil {
return nil, err
}
if parentImage != nil {
data.Parent = parentImage.ID()
}
}
// Determine the format of the image. How we determine certain data

View File

@ -477,10 +477,10 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
if pullPolicy == config.PullPolicyNever {
if localImage != nil {
logrus.Debugf("Pull policy %q but no local image has been found for %s", pullPolicy, imageName)
logrus.Debugf("Pull policy %q and %s resolved to local image %s", pullPolicy, imageName, resolvedImageName)
return []string{resolvedImageName}, nil
}
logrus.Debugf("Pull policy %q and %s resolved to local image %s", pullPolicy, imageName, resolvedImageName)
logrus.Debugf("Pull policy %q but no local image has been found for %s", pullPolicy, imageName)
return nil, errors.Wrap(storage.ErrImageUnknown, imageName)
}

View File

@ -284,8 +284,9 @@ func searchRepositoryTags(ctx context.Context, sys *types.SystemContext, registr
paramsArr := []SearchResult{}
for i := 0; i < limit; i++ {
params := SearchResult{
Name: imageRef.DockerReference().Name(),
Tag: tags[i],
Name: imageRef.DockerReference().Name(),
Tag: tags[i],
Index: registry,
}
paramsArr = append(paramsArr, params)
}