diff options
author | baude <bbaude@redhat.com> | 2018-08-04 10:12:27 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-08-05 10:43:32 +0000 |
commit | a1e3e542fff562d885354c55f04e0b7f5097a39b (patch) | |
tree | 7209d164b97252913bd8533a4326d53629e7566d /pkg/varlinkapi/images.go | |
parent | debf23c72ae1638a7efb294b6df9497224978d01 (diff) | |
download | podman-a1e3e542fff562d885354c55f04e0b7f5097a39b.tar.gz podman-a1e3e542fff562d885354c55f04e0b7f5097a39b.tar.bz2 podman-a1e3e542fff562d885354c55f04e0b7f5097a39b.zip |
Make one runtime for the varlink service
Rather than making a runtime each time a client hits a varlink endpoint, we now
make a single runtime when the varlink service starts up. This fixes a problem
where we hit a max inotify limit from CNI.
Resolves: #1211
Signed-off-by: baude <bbaude@redhat.com>
Closes: #1215
Approved by: rhatdan
Diffstat (limited to 'pkg/varlinkapi/images.go')
-rw-r--r-- | pkg/varlinkapi/images.go | 90 |
1 files changed, 18 insertions, 72 deletions
diff --git a/pkg/varlinkapi/images.go b/pkg/varlinkapi/images.go index 385c7c1bc..f4ba8cbf3 100644 --- a/pkg/varlinkapi/images.go +++ b/pkg/varlinkapi/images.go @@ -17,7 +17,6 @@ import ( "github.com/pkg/errors" "github.com/projectatomic/buildah" "github.com/projectatomic/buildah/imagebuildah" - "github.com/projectatomic/libpod/cmd/podman/libpodruntime" "github.com/projectatomic/libpod/cmd/podman/varlink" "github.com/projectatomic/libpod/libpod" "github.com/projectatomic/libpod/libpod/image" @@ -28,11 +27,7 @@ import ( // ListImages lists all the images in the store // It requires no inputs. func (i *LibpodAPI) ListImages(call ioprojectatomicpodman.VarlinkCall) error { - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - images, err := runtime.ImageRuntime().GetImages() + images, err := i.Runtime.ImageRuntime().GetImages() if err != nil { return call.ReplyErrorOccurred(fmt.Sprintf("unable to get list of images %q", err)) } @@ -60,11 +55,7 @@ func (i *LibpodAPI) ListImages(call ioprojectatomicpodman.VarlinkCall) error { // GetImage returns a single image in the form of a ImageInList func (i *LibpodAPI) GetImage(call ioprojectatomicpodman.VarlinkCall, name string) error { - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - newImage, err := runtime.ImageRuntime().NewFromLocal(name) + newImage, err := i.Runtime.ImageRuntime().NewFromLocal(name) if err != nil { return call.ReplyErrorOccurred(err.Error()) } @@ -101,14 +92,9 @@ func (i *LibpodAPI) BuildImage(call ioprojectatomicpodman.VarlinkCall, config io memoryLimit int64 memorySwap int64 namespace []buildah.NamespaceOption + err error ) - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - defer runtime.Shutdown(false) - systemContext := types.SystemContext{} dockerfiles := config.Dockerfile contextDir := "" @@ -215,7 +201,7 @@ func (i *LibpodAPI) BuildImage(call ioprojectatomicpodman.VarlinkCall, config io call.Continues = true } - c := build(runtime, options, config.Dockerfile) + c := build(i.Runtime, options, config.Dockerfile) var log []string done := false for { @@ -249,7 +235,7 @@ func (i *LibpodAPI) BuildImage(call ioprojectatomicpodman.VarlinkCall, config io } } call.Continues = false - newImage, err := runtime.ImageRuntime().NewFromLocal(config.Tags[0]) + newImage, err := i.Runtime.ImageRuntime().NewFromLocal(config.Tags[0]) if err != nil { return call.ReplyErrorOccurred(err.Error()) } @@ -280,11 +266,7 @@ func (i *LibpodAPI) CreateImage(call ioprojectatomicpodman.VarlinkCall) error { // InspectImage returns an image's inspect information as a string that can be serialized. // Requires an image ID or name func (i *LibpodAPI) InspectImage(call ioprojectatomicpodman.VarlinkCall, name string) error { - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - newImage, err := runtime.ImageRuntime().NewFromLocal(name) + newImage, err := i.Runtime.ImageRuntime().NewFromLocal(name) if err != nil { return call.ReplyImageNotFound(name) } @@ -299,11 +281,7 @@ func (i *LibpodAPI) InspectImage(call ioprojectatomicpodman.VarlinkCall, name st // HistoryImage returns the history of the image's layers // Requires an image or name func (i *LibpodAPI) HistoryImage(call ioprojectatomicpodman.VarlinkCall, name string) error { - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - newImage, err := runtime.ImageRuntime().NewFromLocal(name) + newImage, err := i.Runtime.ImageRuntime().NewFromLocal(name) if err != nil { return call.ReplyImageNotFound(name) } @@ -329,11 +307,7 @@ func (i *LibpodAPI) HistoryImage(call ioprojectatomicpodman.VarlinkCall, name st // PushImage pushes an local image to registry // TODO We need to add options for signing, credentials, tls, and multi-tag func (i *LibpodAPI) PushImage(call ioprojectatomicpodman.VarlinkCall, name, tag string, tlsVerify bool) error { - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - newImage, err := runtime.ImageRuntime().NewFromLocal(name) + newImage, err := i.Runtime.ImageRuntime().NewFromLocal(name) if err != nil { return call.ReplyImageNotFound(err.Error()) } @@ -356,11 +330,7 @@ func (i *LibpodAPI) PushImage(call ioprojectatomicpodman.VarlinkCall, name, tag // TagImage accepts an image name and tag as strings and tags an image in the local store. func (i *LibpodAPI) TagImage(call ioprojectatomicpodman.VarlinkCall, name, tag string) error { - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - newImage, err := runtime.ImageRuntime().NewFromLocal(name) + newImage, err := i.Runtime.ImageRuntime().NewFromLocal(name) if err != nil { return call.ReplyImageNotFound(name) } @@ -374,15 +344,11 @@ func (i *LibpodAPI) TagImage(call ioprojectatomicpodman.VarlinkCall, name, tag s // remove the image even if being used by stopped containers func (i *LibpodAPI) RemoveImage(call ioprojectatomicpodman.VarlinkCall, name string, force bool) error { ctx := getContext() - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - newImage, err := runtime.ImageRuntime().NewFromLocal(name) + newImage, err := i.Runtime.ImageRuntime().NewFromLocal(name) if err != nil { return call.ReplyImageNotFound(name) } - _, err = runtime.RemoveImage(ctx, newImage, force) + _, err = i.Runtime.RemoveImage(ctx, newImage, force) if err != nil { return call.ReplyErrorOccurred(err.Error()) } @@ -420,11 +386,7 @@ func (i *LibpodAPI) SearchImage(call ioprojectatomicpodman.VarlinkCall, name str // DeleteUnusedImages deletes any images that do not have containers associated with it. // TODO Filters are not implemented func (i *LibpodAPI) DeleteUnusedImages(call ioprojectatomicpodman.VarlinkCall) error { - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - images, err := runtime.ImageRuntime().GetImages() + images, err := i.Runtime.ImageRuntime().GetImages() if err != nil { return call.ReplyErrorOccurred(err.Error()) } @@ -446,17 +408,13 @@ func (i *LibpodAPI) DeleteUnusedImages(call ioprojectatomicpodman.VarlinkCall) e // Commit ... func (i *LibpodAPI) Commit(call ioprojectatomicpodman.VarlinkCall, name, imageName string, changes []string, author, message string, pause bool) error { - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - ctr, err := runtime.LookupContainer(name) + ctr, err := i.Runtime.LookupContainer(name) if err != nil { return call.ReplyContainerNotFound(name) } - sc := image.GetSystemContext(runtime.GetConfig().SignaturePolicyPath, "", false) + sc := image.GetSystemContext(i.Runtime.GetConfig().SignaturePolicyPath, "", false) coptions := buildah.CommitOptions{ - SignaturePolicyPath: runtime.GetConfig().SignaturePolicyPath, + SignaturePolicyPath: i.Runtime.GetConfig().SignaturePolicyPath, ReportWriter: nil, SystemContext: sc, PreferredManifestType: buildah.OCIv1ImageManifest, @@ -478,10 +436,6 @@ func (i *LibpodAPI) Commit(call ioprojectatomicpodman.VarlinkCall, name, imageNa // ImportImage imports an image from a tarball to the image store func (i *LibpodAPI) ImportImage(call ioprojectatomicpodman.VarlinkCall, source, reference, message string, changes []string) error { - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } configChanges, err := util.GetImageConfig(changes) if err != nil { return call.ReplyErrorOccurred(err.Error()) @@ -493,7 +447,7 @@ func (i *LibpodAPI) ImportImage(call ioprojectatomicpodman.VarlinkCall, source, Config: configChanges, History: history, } - newImage, err := runtime.ImageRuntime().Import(getContext(), source, reference, nil, image.SigningOptions{}, config) + newImage, err := i.Runtime.ImageRuntime().Import(getContext(), source, reference, nil, image.SigningOptions{}, config) if err != nil { return call.ReplyErrorOccurred(err.Error()) } @@ -503,11 +457,7 @@ func (i *LibpodAPI) ImportImage(call ioprojectatomicpodman.VarlinkCall, source, // ExportImage exports an image to the provided destination // destination must have the transport type!! func (i *LibpodAPI) ExportImage(call ioprojectatomicpodman.VarlinkCall, name, destination string, compress bool, tags []string) error { - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - newImage, err := runtime.ImageRuntime().NewFromLocal(name) + newImage, err := i.Runtime.ImageRuntime().NewFromLocal(name) if err != nil { return call.ReplyImageNotFound(name) } @@ -526,11 +476,7 @@ func (i *LibpodAPI) ExportImage(call ioprojectatomicpodman.VarlinkCall, name, de // PullImage pulls an image from a registry to the image store. // TODO This implementation is incomplete func (i *LibpodAPI) PullImage(call ioprojectatomicpodman.VarlinkCall, name string) error { - runtime, err := libpodruntime.GetRuntime(i.Cli) - if err != nil { - return call.ReplyRuntimeError(err.Error()) - } - newImage, err := runtime.ImageRuntime().New(getContext(), name, "", "", nil, &image.DockerRegistryOptions{}, image.SigningOptions{}, true, false) + newImage, err := i.Runtime.ImageRuntime().New(getContext(), name, "", "", nil, &image.DockerRegistryOptions{}, image.SigningOptions{}, true, false) if err != nil { return call.ReplyErrorOccurred(fmt.Sprintf("unable to pull %s: %s", name, err.Error())) } |