pkg/specgen: cache image in generator

To prevent expensive redundant lookups and inspects on the same image,
cache the image in the generator.  Note that once a given image has been
inspected, subsequent calls will use the libimage-internal cache.

[NO TESTS NEEDED] since it is no functional change.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2021-09-30 16:42:45 +02:00
parent 1da364783d
commit 686b7ef7bf
3 changed files with 56 additions and 21 deletions

View File

@ -5,6 +5,7 @@ import (
"strings"
"syscall"
"github.com/containers/common/libimage"
"github.com/containers/image/v5/manifest"
nettypes "github.com/containers/podman/v3/libpod/network/types"
"github.com/containers/storage/types"
@ -512,6 +513,21 @@ type SpecGenerator struct {
ContainerNetworkConfig
ContainerResourceConfig
ContainerHealthCheckConfig
image *libimage.Image `json:"-"`
resolvedImageName string `json:"-"`
}
// SetImage sets the associated for the generator.
func (s *SpecGenerator) SetImage(image *libimage.Image, resolvedImageName string) {
s.image = image
s.resolvedImageName = resolvedImageName
}
// Image returns the associated image for the generator.
// May be nil if no image has been set yet.
func (s *SpecGenerator) GetImage() (*libimage.Image, string) {
return s.image, s.resolvedImageName
}
type Secret struct {