diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2020-03-12 09:50:55 +0100 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2020-03-12 09:51:17 +0100 |
commit | 8741eb8a9201b930abb463c1128a48bdbcec70a0 (patch) | |
tree | 1ba576d737fe09905c0c91b6cb8b5e6a30a7264c | |
parent | 60e9e7ca9c9081f31f6b37c922f0058f82b989ad (diff) | |
download | podman-8741eb8a9201b930abb463c1128a48bdbcec70a0.tar.gz podman-8741eb8a9201b930abb463c1128a48bdbcec70a0.tar.bz2 podman-8741eb8a9201b930abb463c1128a48bdbcec70a0.zip |
create: do not calculate image size
calculating the image size can be an expensive operation. Avoid doing
it when creating a new container since the size is not needed.
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
-rw-r--r-- | cmd/podman/shared/create.go | 2 | ||||
-rw-r--r-- | libpod/image/image.go | 33 | ||||
-rw-r--r-- | libpod/runtime_pod_infra_linux.go | 2 |
3 files changed, 27 insertions, 10 deletions
diff --git a/cmd/podman/shared/create.go b/cmd/podman/shared/create.go index 08d32df18..5adac7e1f 100644 --- a/cmd/podman/shared/create.go +++ b/cmd/podman/shared/create.go @@ -101,7 +101,7 @@ func CreateContainer(ctx context.Context, c *GenericCLIResults, runtime *libpod. if err != nil { return nil, nil, err } - imageData, err = newImage.Inspect(ctx) + imageData, err = newImage.InspectNoSize(ctx) if err != nil { return nil, nil, err } diff --git a/libpod/image/image.go b/libpod/image/image.go index 43fd52a1a..5f914ed79 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -916,12 +916,7 @@ func (i *Image) imageInspectInfo(ctx context.Context) (*types.ImageInspectInfo, return i.inspectInfo, nil } -// Inspect returns an image's inspect data -func (i *Image) Inspect(ctx context.Context) (*inspect.ImageData, error) { - span, _ := opentracing.StartSpanFromContext(ctx, "imageInspect") - span.SetTag("type", "image") - defer span.Finish() - +func (i *Image) inspect(ctx context.Context, calculateSize bool) (*inspect.ImageData, error) { ociv1Img, err := i.ociv1Image(ctx) if err != nil { ociv1Img = &ociv1.Image{} @@ -936,8 +931,10 @@ func (i *Image) Inspect(ctx context.Context) (*inspect.ImageData, error) { } size := int64(-1) - if usize, err := i.Size(ctx); err == nil { - size = int64(*usize) + if calculateSize { + if usize, err := i.Size(ctx); err == nil { + size = int64(*usize) + } } repoTags, err := i.RepoTags() @@ -1002,6 +999,26 @@ func (i *Image) Inspect(ctx context.Context) (*inspect.ImageData, error) { return data, nil } +// Inspect returns an image's inspect data +func (i *Image) Inspect(ctx context.Context) (*inspect.ImageData, error) { + span, _ := opentracing.StartSpanFromContext(ctx, "imageInspect") + + span.SetTag("type", "image") + defer span.Finish() + + return i.inspect(ctx, true) +} + +// InspectNoSize returns an image's inspect data without calculating the size for the image +func (i *Image) InspectNoSize(ctx context.Context) (*inspect.ImageData, error) { + span, _ := opentracing.StartSpanFromContext(ctx, "imageInspectNoSize") + + span.SetTag("type", "image") + defer span.Finish() + + return i.inspect(ctx, false) +} + // Import imports and image into the store and returns an image func (ir *Runtime) Import(ctx context.Context, path, reference string, writer io.Writer, signingOptions SigningOptions, imageConfig ociv1.Image) (*Image, error) { src, err := tarball.Transport.ParseReference(path) diff --git a/libpod/runtime_pod_infra_linux.go b/libpod/runtime_pod_infra_linux.go index da46f03e8..be590a5c8 100644 --- a/libpod/runtime_pod_infra_linux.go +++ b/libpod/runtime_pod_infra_linux.go @@ -147,7 +147,7 @@ func (r *Runtime) createInfraContainer(ctx context.Context, p *Pod) (*Container, return nil, err } - data, err := newImage.Inspect(ctx) + data, err := newImage.InspectNoSize(ctx) if err != nil { return nil, err } |