aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2018-04-18 16:48:35 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-19 14:08:47 +0000
commit27107fdac1d75f97caab47cd13efb1d9900cf350 (patch)
treef5edafbb52505829b15e19ea6a9e66f4440e862b /libpod
parent6a9dbf3305e93e5e1c3bff09402a9b801c935fbd (diff)
downloadpodman-27107fdac1d75f97caab47cd13efb1d9900cf350.tar.gz
podman-27107fdac1d75f97caab47cd13efb1d9900cf350.tar.bz2
podman-27107fdac1d75f97caab47cd13efb1d9900cf350.zip
Vendor in latest containers/image and contaners/storage
Made necessary changes to functions to include contex.Context wherever needed Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #640 Approved by: baude
Diffstat (limited to 'libpod')
-rw-r--r--libpod/buildah/buildah.go17
-rw-r--r--libpod/buildah/commit.go9
-rw-r--r--libpod/buildah/image.go18
-rw-r--r--libpod/container_api.go17
-rw-r--r--libpod/container_commit.go7
-rw-r--r--libpod/container_internal.go25
-rw-r--r--libpod/image/filters.go5
-rw-r--r--libpod/image/image.go73
-rw-r--r--libpod/image/image_test.go9
-rw-r--r--libpod/image/pull.go13
-rw-r--r--libpod/pod.go13
-rw-r--r--libpod/runtime_ctr.go5
-rw-r--r--libpod/storage.go5
13 files changed, 114 insertions, 102 deletions
diff --git a/libpod/buildah/buildah.go b/libpod/buildah/buildah.go
index b560f99a1..8f4b95ac8 100644
--- a/libpod/buildah/buildah.go
+++ b/libpod/buildah/buildah.go
@@ -1,6 +1,7 @@
package buildah
import (
+ "context"
"encoding/json"
"path/filepath"
@@ -128,11 +129,11 @@ type ImportOptions struct {
// ImportBuilder creates a new build configuration using an already-present
// container.
-func ImportBuilder(store storage.Store, options ImportOptions) (*Builder, error) {
- return importBuilder(store, options)
+func ImportBuilder(ctx context.Context, store storage.Store, options ImportOptions) (*Builder, error) {
+ return importBuilder(ctx, store, options)
}
-func importBuilder(store storage.Store, options ImportOptions) (*Builder, error) {
+func importBuilder(ctx context.Context, store storage.Store, options ImportOptions) (*Builder, error) {
if options.Container == "" {
return nil, errors.Errorf("container name must be specified")
}
@@ -144,7 +145,7 @@ func importBuilder(store storage.Store, options ImportOptions) (*Builder, error)
systemContext := getSystemContext(&types.SystemContext{}, options.SignaturePolicyPath)
- builder, err := importBuilderDataFromImage(store, systemContext, c.ImageID, options.Container, c.ID)
+ builder, err := importBuilderDataFromImage(ctx, store, systemContext, c.ImageID, options.Container, c.ID)
if err != nil {
return nil, err
}
@@ -168,7 +169,7 @@ func importBuilder(store storage.Store, options ImportOptions) (*Builder, error)
return builder, nil
}
-func importBuilderDataFromImage(store storage.Store, systemContext *types.SystemContext, imageID, containerName, containerID string) (*Builder, error) {
+func importBuilderDataFromImage(ctx context.Context, store storage.Store, systemContext *types.SystemContext, imageID, containerName, containerID string) (*Builder, error) {
manifest := []byte{}
config := []byte{}
imageName := ""
@@ -178,16 +179,16 @@ func importBuilderDataFromImage(store storage.Store, systemContext *types.System
if err != nil {
return nil, errors.Wrapf(err, "no such image %q", imageID)
}
- src, err2 := ref.NewImage(systemContext)
+ src, err2 := ref.NewImage(ctx, systemContext)
if err2 != nil {
return nil, errors.Wrapf(err2, "error instantiating image")
}
defer src.Close()
- config, err = src.ConfigBlob()
+ config, err = src.ConfigBlob(ctx)
if err != nil {
return nil, errors.Wrapf(err, "error reading image configuration")
}
- manifest, _, err = src.Manifest()
+ manifest, _, err = src.Manifest(ctx)
if err != nil {
return nil, errors.Wrapf(err, "error reading image manifest")
}
diff --git a/libpod/buildah/commit.go b/libpod/buildah/commit.go
index b862031d2..537f9edbf 100644
--- a/libpod/buildah/commit.go
+++ b/libpod/buildah/commit.go
@@ -1,6 +1,7 @@
package buildah
import (
+ "context"
"fmt"
"io"
"time"
@@ -74,7 +75,7 @@ type PushOptions struct {
// Commit writes the contents of the container, along with its updated
// configuration, to a new image in the specified location, and if we know how,
// add any additional tags that were specified.
-func (b *Builder) Commit(dest types.ImageReference, options CommitOptions) error {
+func (b *Builder) Commit(ctx context.Context, dest types.ImageReference, options CommitOptions) error {
policy, err := signature.DefaultPolicy(getSystemContext(options.SystemContext, options.SignaturePolicyPath))
if err != nil {
return errors.Wrapf(err, "error obtaining default signature policy")
@@ -96,7 +97,7 @@ func (b *Builder) Commit(dest types.ImageReference, options CommitOptions) error
return errors.Wrapf(err, "error computing layer digests and building metadata")
}
// "Copy" our image to where it needs to be.
- err = cp.Image(policyContext, dest, src, getCopyOptions(options.ReportWriter, nil, options.SystemContext, ""))
+ err = cp.Image(ctx, policyContext, dest, src, getCopyOptions(options.ReportWriter, nil, options.SystemContext, ""))
if err != nil {
return errors.Wrapf(err, "error copying layers and metadata")
}
@@ -120,7 +121,7 @@ func (b *Builder) Commit(dest types.ImageReference, options CommitOptions) error
}
// Push copies the contents of the image to a new location.
-func Push(image string, dest types.ImageReference, options PushOptions) error {
+func Push(ctx context.Context, image string, dest types.ImageReference, options PushOptions) error {
systemContext := getSystemContext(options.SystemContext, options.SignaturePolicyPath)
policy, err := signature.DefaultPolicy(systemContext)
if err != nil {
@@ -136,7 +137,7 @@ func Push(image string, dest types.ImageReference, options PushOptions) error {
return errors.Wrapf(err, "error parsing reference to image %q", image)
}
// Copy everything.
- err = cp.Image(policyContext, dest, src, getCopyOptions(options.ReportWriter, nil, options.SystemContext, options.ManifestType))
+ err = cp.Image(ctx, policyContext, dest, src, getCopyOptions(options.ReportWriter, nil, options.SystemContext, options.ManifestType))
if err != nil {
return errors.Wrapf(err, "error copying layers and metadata")
}
diff --git a/libpod/buildah/image.go b/libpod/buildah/image.go
index 656c39201..7232d53ad 100644
--- a/libpod/buildah/image.go
+++ b/libpod/buildah/image.go
@@ -65,12 +65,12 @@ type containerImageSource struct {
exporting bool
}
-func (i *containerImageRef) NewImage(sc *types.SystemContext) (types.ImageCloser, error) {
- src, err := i.NewImageSource(sc)
+func (i *containerImageRef) NewImage(ctx context.Context, sc *types.SystemContext) (types.ImageCloser, error) {
+ src, err := i.NewImageSource(ctx, sc)
if err != nil {
return nil, err
}
- return image.FromSource(sc, src)
+ return image.FromSource(ctx, sc, src)
}
func expectedOCIDiffIDs(image v1.Image) int {
@@ -93,7 +93,7 @@ func expectedDockerDiffIDs(image docker.V2Image) int {
return expected
}
-func (i *containerImageRef) NewImageSource(sc *types.SystemContext) (src types.ImageSource, err error) {
+func (i *containerImageRef) NewImageSource(ctx context.Context, sc *types.SystemContext) (src types.ImageSource, err error) {
// Decide which type of manifest and configuration output we're going to provide.
manifestType := i.preferredManifestType
// If it's not a format we support, return an error.
@@ -392,7 +392,7 @@ func (i *containerImageRef) NewImageSource(sc *types.SystemContext) (src types.I
return src, nil
}
-func (i *containerImageRef) NewImageDestination(sc *types.SystemContext) (types.ImageDestination, error) {
+func (i *containerImageRef) NewImageDestination(ctx context.Context, sc *types.SystemContext) (types.ImageDestination, error) {
return nil, errors.Errorf("can't write to a container")
}
@@ -407,7 +407,7 @@ func (i *containerImageRef) StringWithinTransport() string {
return ""
}
-func (i *containerImageRef) DeleteImage(*types.SystemContext) error {
+func (i *containerImageRef) DeleteImage(context.Context, *types.SystemContext) error {
// we were never here
return nil
}
@@ -443,18 +443,18 @@ func (i *containerImageSource) GetSignatures(ctx context.Context, instanceDigest
return nil, nil
}
-func (i *containerImageSource) GetManifest(instanceDigest *digest.Digest) ([]byte, string, error) {
+func (i *containerImageSource) GetManifest(ctx context.Context, instanceDigest *digest.Digest) ([]byte, string, error) {
if instanceDigest != nil && *instanceDigest != digest.FromBytes(i.manifest) {
return nil, "", errors.Errorf("TODO")
}
return i.manifest, i.manifestType, nil
}
-func (i *containerImageSource) LayerInfosForCopy() ([]types.BlobInfo, error) {
+func (i *containerImageSource) LayerInfosForCopy(context.Context) ([]types.BlobInfo, error) {
return nil, nil
}
-func (i *containerImageSource) GetBlob(blob types.BlobInfo) (reader io.ReadCloser, size int64, err error) {
+func (i *containerImageSource) GetBlob(ctx context.Context, blob types.BlobInfo) (reader io.ReadCloser, size int64, err error) {
if blob.Digest == i.configDigest {
logrus.Debugf("start reading config")
reader := bytes.NewReader(i.config)
diff --git a/libpod/container_api.go b/libpod/container_api.go
index b038787f5..aa1e7966f 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -1,6 +1,7 @@
package libpod
import (
+ "context"
"io/ioutil"
"os"
"strconv"
@@ -18,7 +19,7 @@ import (
)
// Init creates a container in the OCI runtime
-func (c *Container) Init() (err error) {
+func (c *Container) Init(ctx context.Context) (err error) {
if !c.batched {
c.lock.Lock()
defer c.lock.Unlock()
@@ -52,7 +53,7 @@ func (c *Container) Init() (err error) {
}
}()
- return c.init()
+ return c.init(ctx)
}
// Start starts a container
@@ -61,7 +62,7 @@ func (c *Container) Init() (err error) {
// started
// Stopped containers will be deleted and re-created in runc, undergoing a fresh
// Init()
-func (c *Container) Start() (err error) {
+func (c *Container) Start(ctx context.Context) (err error) {
if !c.batched {
c.lock.Lock()
defer c.lock.Unlock()
@@ -100,12 +101,12 @@ func (c *Container) Start() (err error) {
if c.state.State == ContainerStateStopped {
// Reinitialize the container if we need to
- if err := c.reinit(); err != nil {
+ if err := c.reinit(ctx); err != nil {
return err
}
} else if c.state.State == ContainerStateConfigured {
// Or initialize it for the first time if necessary
- if err := c.init(); err != nil {
+ if err := c.init(ctx); err != nil {
return err
}
}
@@ -124,7 +125,7 @@ func (c *Container) Start() (err error) {
// attach call.
// The channel will be closed automatically after the result of attach has been
// sent
-func (c *Container) StartAndAttach(streams *AttachStreams, keys string, resize <-chan remotecommand.TerminalSize) (attachResChan <-chan error, err error) {
+func (c *Container) StartAndAttach(ctx context.Context, streams *AttachStreams, keys string, resize <-chan remotecommand.TerminalSize) (attachResChan <-chan error, err error) {
if !c.batched {
c.lock.Lock()
defer c.lock.Unlock()
@@ -163,12 +164,12 @@ func (c *Container) StartAndAttach(streams *AttachStreams, keys string, resize <
if c.state.State == ContainerStateStopped {
// Reinitialize the container if we need to
- if err := c.reinit(); err != nil {
+ if err := c.reinit(ctx); err != nil {
return nil, err
}
} else if c.state.State == ContainerStateConfigured {
// Or initialize it for the first time if necessary
- if err := c.init(); err != nil {
+ if err := c.init(ctx); err != nil {
return nil, err
}
}
diff --git a/libpod/container_commit.go b/libpod/container_commit.go
index bfdfb6ce4..e136f96a4 100644
--- a/libpod/container_commit.go
+++ b/libpod/container_commit.go
@@ -1,6 +1,7 @@
package libpod
import (
+ "context"
"strings"
is "github.com/containers/image/storage"
@@ -24,7 +25,7 @@ type ContainerCommitOptions struct {
// Commit commits the changes between a container and its image, creating a new
// image
-func (c *Container) Commit(destImage string, options ContainerCommitOptions) (*image.Image, error) {
+func (c *Container) Commit(ctx context.Context, destImage string, options ContainerCommitOptions) (*image.Image, error) {
if !c.batched {
c.lock.Lock()
defer c.lock.Unlock()
@@ -55,7 +56,7 @@ func (c *Container) Commit(destImage string, options ContainerCommitOptions) (*i
ReportWriter: options.ReportWriter,
SystemContext: sc,
}
- importBuilder, err := buildah.ImportBuilder(c.runtime.store, builderOptions)
+ importBuilder, err := buildah.ImportBuilder(ctx, c.runtime.store, builderOptions)
if err != nil {
return nil, err
}
@@ -96,7 +97,7 @@ func (c *Container) Commit(destImage string, options ContainerCommitOptions) (*i
return nil, err
}
- if err = importBuilder.Commit(imageRef, commitOptions); err != nil {
+ if err = importBuilder.Commit(ctx, imageRef, commitOptions); err != nil {
return nil, err
}
return c.runtime.imageRuntime.NewFromLocal(imageRef.DockerReference().String())
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 414def120..32f8d2aec 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -1,6 +1,7 @@
package libpod
import (
+ "context"
"encoding/json"
"fmt"
"io"
@@ -176,7 +177,7 @@ func newContainer(rspec *spec.Spec, lockDir string) (*Container, error) {
}
// Create container root filesystem for use
-func (c *Container) setupStorage() error {
+func (c *Container) setupStorage(ctx context.Context) error {
if !c.valid {
return errors.Wrapf(ErrCtrRemoved, "container %s is not valid", c.ID())
}
@@ -190,7 +191,7 @@ func (c *Container) setupStorage() error {
return errors.Wrapf(ErrInvalidArg, "must provide image ID and image name to use an image")
}
- containerInfo, err := c.runtime.storageService.CreateContainerStorage(c.runtime.imageContext, c.config.RootfsImageName, c.config.RootfsImageID, c.config.Name, c.config.ID, c.config.MountLabel)
+ containerInfo, err := c.runtime.storageService.CreateContainerStorage(ctx, c.runtime.imageContext, c.config.RootfsImageName, c.config.RootfsImageID, c.config.Name, c.config.ID, c.config.MountLabel)
if err != nil {
return errors.Wrapf(err, "error creating container storage")
}
@@ -412,13 +413,13 @@ func (c *Container) checkDependenciesRunningLocked(depCtrs map[string]*Container
}
// Initialize a container, creating it in the runtime
-func (c *Container) init() error {
+func (c *Container) init(ctx context.Context) error {
if err := c.makeBindMounts(); err != nil {
return err
}
// Generate the OCI spec
- spec, err := c.generateSpec()
+ spec, err := c.generateSpec(ctx)
if err != nil {
return err
}
@@ -443,7 +444,7 @@ func (c *Container) init() error {
// Reinitialize a container
// Deletes and recreates a container in the runtime
// Should only be done on ContainerStateStopped containers
-func (c *Container) reinit() error {
+func (c *Container) reinit(ctx context.Context) error {
logrus.Debugf("Recreating container %s in OCI runtime", c.ID())
// If necessary, delete attach and ctl files
@@ -468,13 +469,13 @@ func (c *Container) reinit() error {
logrus.Debugf("Successfully cleaned up container %s", c.ID())
// Initialize the container again
- return c.init()
+ return c.init(ctx)
}
// Initialize (if necessary) and start a container
// Performs all necessary steps to start a container that is not running
// Does not lock or check validity
-func (c *Container) initAndStart() (err error) {
+func (c *Container) initAndStart(ctx context.Context) (err error) {
// If we are ContainerStateUnknown, throw an error
if c.state.State == ContainerStateUnknown {
return errors.Wrapf(ErrCtrStateInvalid, "container %s is in an unknown state", c.ID())
@@ -527,7 +528,7 @@ func (c *Container) initAndStart() (err error) {
// If we are ContainerStateConfigured we need to init()
if c.state.State == ContainerStateConfigured {
- if err := c.init(); err != nil {
+ if err := c.init(ctx); err != nil {
return err
}
}
@@ -910,7 +911,7 @@ func (c *Container) generateHosts() (string, error) {
// Generate spec for a container
// Accepts a map of the container's dependencies
-func (c *Container) generateSpec() (*spec.Spec, error) {
+func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
g := generate.NewFromSpec(c.config.Spec)
// If network namespace was requested, add it now
@@ -939,7 +940,7 @@ func (c *Container) generateSpec() (*spec.Spec, error) {
}
// Bind builtin image volumes
if c.config.ImageVolumes {
- if err := c.addImageVolumes(&g); err != nil {
+ if err := c.addImageVolumes(ctx, &g); err != nil {
return nil, errors.Wrapf(err, "error mounting image volumes")
}
}
@@ -1059,7 +1060,7 @@ func (c *Container) addNamespaceContainer(g *generate.Generator, ns LinuxNS, ctr
return nil
}
-func (c *Container) addImageVolumes(g *generate.Generator) error {
+func (c *Container) addImageVolumes(ctx context.Context, g *generate.Generator) error {
mountPoint := c.state.Mountpoint
if !c.state.Mounted {
return errors.Wrapf(ErrInternal, "container is not mounted")
@@ -1068,7 +1069,7 @@ func (c *Container) addImageVolumes(g *generate.Generator) error {
if err != nil {
return err
}
- imageData, err := newImage.Inspect()
+ imageData, err := newImage.Inspect(ctx)
if err != nil {
return err
}
diff --git a/libpod/image/filters.go b/libpod/image/filters.go
index 20a9efc97..c1dd1e5cd 100644
--- a/libpod/image/filters.go
+++ b/libpod/image/filters.go
@@ -1,6 +1,7 @@
package image
import (
+ "context"
"strings"
"time"
@@ -39,7 +40,7 @@ func DanglingFilter() ResultFilter {
}
// LabelFilter allows you to filter by images labels key and/or value
-func LabelFilter(labelfilter string) ResultFilter {
+func LabelFilter(ctx context.Context, labelfilter string) ResultFilter {
// We need to handle both label=key and label=key=value
return func(i *Image) bool {
var value string
@@ -48,7 +49,7 @@ func LabelFilter(labelfilter string) ResultFilter {
if len(splitFilter) > 1 {
value = splitFilter[1]
}
- labels, err := i.Labels()
+ labels, err := i.Labels(ctx)
if err != nil {
return false
}
diff --git a/libpod/image/image.go b/libpod/image/image.go
index cf0c7ec1b..53d69ebe9 100644
--- a/libpod/image/image.go
+++ b/libpod/image/image.go
@@ -1,6 +1,7 @@
package image
import (
+ "context"
"encoding/json"
"fmt"
"io"
@@ -117,7 +118,7 @@ func (ir *Runtime) NewFromLocal(name string) (*Image, error) {
// New creates a new image object where the image could be local
// or remote
-func (ir *Runtime) New(name, signaturePolicyPath, authfile string, writer io.Writer, dockeroptions *DockerRegistryOptions, signingoptions SigningOptions, forcePull, forceSecure bool) (*Image, error) {
+func (ir *Runtime) New(ctx context.Context, name, signaturePolicyPath, authfile string, writer io.Writer, dockeroptions *DockerRegistryOptions, signingoptions SigningOptions, forcePull, forceSecure bool) (*Image, error) {
// We don't know if the image is local or not ... check local first
newImage := Image{
InputName: name,
@@ -137,7 +138,7 @@ func (ir *Runtime) New(name, signaturePolicyPath, authfile string, writer io.Wri
if signaturePolicyPath == "" {
signaturePolicyPath = ir.SignaturePolicyPath
}
- imageName, err := newImage.pullImage(writer, authfile, signaturePolicyPath, signingoptions, dockeroptions, forceSecure)
+ imageName, err := newImage.pullImage(ctx, writer, authfile, signaturePolicyPath, signingoptions, dockeroptions, forceSecure)
if err != nil {
return nil, errors.Errorf("unable to pull %s", name)
}
@@ -254,12 +255,12 @@ func (i *Image) Digest() digest.Digest {
// Manifest returns the image's manifest as a byte array
// and manifest type as a string. The manifest type is
// MediaTypeImageManifest from ociv1.
-func (i *Image) Manifest() ([]byte, string, error) {
- imgRef, err := i.toImageRef()
+func (i *Image) Manifest(ctx context.Context) ([]byte, string, error) {
+ imgRef, err := i.toImageRef(ctx)
if err != nil {
return nil, "", err
}
- return imgRef.Manifest()
+ return imgRef.Manifest(ctx)
}
// Names returns a string array of names associated with the image
@@ -351,8 +352,8 @@ func (ir *Runtime) GetImages() ([]*Image, error) {
// getImageDigest creates an image object and uses the hex value of the digest as the image ID
// for parsing the store reference
-func getImageDigest(src types.ImageReference, ctx *types.SystemContext) (string, error) {
- newImg, err := src.NewImage(ctx)
+func getImageDigest(ctx context.Context, src types.ImageReference, sc *types.SystemContext) (string, error) {
+ newImg, err := src.NewImage(ctx, sc)
if err != nil {
return "", err
}
@@ -408,7 +409,7 @@ func (i *Image) UntagImage(tag string) error {
}
// PushImage pushes the given image to a location described by the given path
-func (i *Image) PushImage(destination, manifestMIMEType, authFile, signaturePolicyPath string, writer io.Writer, forceCompress bool, signingOptions SigningOptions, dockerRegistryOptions *DockerRegistryOptions) error {
+func (i *Image) PushImage(ctx context.Context, destination, manifestMIMEType, authFile, signaturePolicyPath string, writer io.Writer, forceCompress bool, signingOptions SigningOptions, dockerRegistryOptions *DockerRegistryOptions) error {
if destination == "" {
return errors.Wrapf(syscall.EINVAL, "destination image name must be specified")
}
@@ -444,7 +445,7 @@ func (i *Image) PushImage(destination, manifestMIMEType, authFile, signaturePoli
copyOptions := getCopyOptions(writer, signaturePolicyPath, nil, dockerRegistryOptions, signingOptions, authFile, manifestMIMEType, forceCompress)
// Copy the image to the remote destination
- err = cp.Image(policyContext, dest, src, copyOptions)
+ err = cp.Image(ctx, policyContext, dest, src, copyOptions)
if err != nil {
return errors.Wrapf(err, "Error copying image to the remote destination")
}
@@ -477,12 +478,12 @@ func (i *Image) toStorageReference() (types.ImageReference, error) {
// ToImageRef returns an image reference type from an image
// TODO: Hopefully we can remove this exported function for mheon
-func (i *Image) ToImageRef() (types.Image, error) {
- return i.toImageRef()
+func (i *Image) ToImageRef(ctx context.Context) (types.Image, error) {
+ return i.toImageRef(ctx)
}
// toImageRef returns an Image Reference type from an image
-func (i *Image) toImageRef() (types.Image, error) {
+func (i *Image) toImageRef(ctx context.Context) (types.Image, error) {
if i == nil {
return nil, errors.Errorf("cannot convert nil image to image reference")
}
@@ -491,7 +492,7 @@ func (i *Image) toImageRef() (types.Image, error) {
if err != nil {
return nil, errors.Wrapf(err, "error parsing reference to image %q", i.ID())
}
- imgRef, err := ref.NewImage(nil)
+ imgRef, err := ref.NewImage(ctx, nil)
if err != nil {
return nil, errors.Wrapf(err, "error reading image %q", i.ID())
}
@@ -506,13 +507,13 @@ type sizer interface {
}
//Size returns the size of the image
-func (i *Image) Size() (*uint64, error) {
+func (i *Image) Size(ctx context.Context) (*uint64, error) {
storeRef, err := is.Transport.ParseStoreReference(i.imageruntime.store, i.ID())
if err != nil {
return nil, err
}
systemContext := &types.SystemContext{}
- img, err := storeRef.NewImageSource(systemContext)
+ img, err := storeRef.NewImageSource(ctx, systemContext)
if err != nil {
return nil, err
}
@@ -540,12 +541,12 @@ func (i *Image) Layer() (*storage.Layer, error) {
}
// History gets the history of an image and information about its layers
-func (i *Image) History() ([]ociv1.History, []types.BlobInfo, error) {
- img, err := i.toImageRef()
+func (i *Image) History(ctx context.Context) ([]ociv1.History, []types.BlobInfo, error) {
+ img, err := i.toImageRef(ctx)
if err != nil {
return nil, nil, err
}
- oci, err := img.OCIConfig()
+ oci, err := img.OCIConfig(ctx)
if err != nil {
return nil, nil, err
}
@@ -558,8 +559,8 @@ func (i *Image) Dangling() bool {
}
// Labels returns the image's labels
-func (i *Image) Labels() (map[string]string, error) {
- imgInspect, err := i.imageInspectInfo()
+func (i *Image) Labels(ctx context.Context) (map[string]string, error) {
+ imgInspect, err := i.imageInspectInfo(ctx)
if err != nil {
return nil, nil
}
@@ -567,8 +568,8 @@ func (i *Image) Labels() (map[string]string, error) {
}
// Annotations returns the annotations of an image
-func (i *Image) Annotations() (map[string]string, error) {
- manifest, manifestType, err := i.Manifest()
+func (i *Image) Annotations(ctx context.Context) (map[string]string, error) {
+ manifest, manifestType, err := i.Manifest(ctx)
if err != nil {
return nil, err
}
@@ -587,25 +588,25 @@ func (i *Image) Annotations() (map[string]string, error) {
// ociv1Image converts and image to an imgref and then an
// ociv1 image type
-func (i *Image) ociv1Image() (*ociv1.Image, error) {
- imgRef, err := i.toImageRef()
+func (i *Image) ociv1Image(ctx context.Context) (*ociv1.Image, error) {
+ imgRef, err := i.toImageRef(ctx)
if err != nil {
return nil, err
}
- return imgRef.OCIConfig()
+ return imgRef.OCIConfig(ctx)
}
-func (i *Image) imageInspectInfo() (*types.ImageInspectInfo, error) {
+func (i *Image) imageInspectInfo(ctx context.Context) (*types.ImageInspectInfo, error) {
if i.inspectInfo == nil {
sr, err := i.toStorageReference()
if err != nil {
return nil, err
}
- ic, err := sr.NewImage(&types.SystemContext{})
+ ic, err := sr.NewImage(ctx, &types.SystemContext{})
if err != nil {
return nil, err
}
- imgInspect, err := ic.Inspect()
+ imgInspect, err := ic.Inspect(ctx)
if err != nil {
return nil, err
}
@@ -615,21 +616,21 @@ func (i *Image) imageInspectInfo() (*types.ImageInspectInfo, error) {
}
// Inspect returns an image's inspect data
-func (i *Image) Inspect() (*inspect.ImageData, error) {
- ociv1Img, err := i.ociv1Image()
+func (i *Image) Inspect(ctx context.Context) (*inspect.ImageData, error) {
+ ociv1Img, err := i.ociv1Image(ctx)
if err != nil {
return nil, err
}
- info, err := i.imageInspectInfo()
+ info, err := i.imageInspectInfo(ctx)
if err != nil {
return nil, err
}
- annotations, err := i.Annotations()
+ annotations, err := i.Annotations(ctx)
if err != nil {
return nil, err
}
- size, err := i.Size()
+ size, err := i.Size(ctx)
if err != nil {
return nil, err
}
@@ -670,7 +671,7 @@ func (i *Image) Inspect() (*inspect.ImageData, error) {
}
// Import imports and image into the store and returns an image
-func (ir *Runtime) Import(path, reference string, writer io.Writer, signingOptions SigningOptions, imageConfig ociv1.Image) (*Image, error) {
+func (ir *Runtime) Import(ctx context.Context, path, reference string, writer io.Writer, signingOptions SigningOptions, imageConfig ociv1.Image) (*Image, error) {
file := TarballTransport + ":" + path
src, err := alltransports.ParseImageName(file)
if err != nil {
@@ -694,7 +695,7 @@ func (ir *Runtime) Import(path, reference string, writer io.Writer, signingOptio
// if reference not given, get the image digest
if reference == "" {
- reference, err = getImageDigest(src, sc)
+ reference, err = getImageDigest(ctx, src, sc)
if err != nil {
return nil, err
}
@@ -709,7 +710,7 @@ func (ir *Runtime) Import(path, reference string, writer io.Writer, signingOptio
if err != nil {
errors.Wrapf(err, "error getting image reference for %q", reference)
}
- if err = cp.Image(policyContext, dest, src, copyOptions); err != nil {
+ if err = cp.Image(ctx, policyContext, dest, src, copyOptions); err != nil {
return nil, err
}
return ir.NewFromLocal(reference)
diff --git a/libpod/image/image_test.go b/libpod/image/image_test.go
index f160a14a4..71beed495 100644
--- a/libpod/image/image_test.go
+++ b/libpod/image/image_test.go
@@ -1,6 +1,7 @@
package image
import (
+ "context"
"fmt"
"io"
"io/ioutil"
@@ -81,9 +82,9 @@ func TestImage_NewFromLocal(t *testing.T) {
// Need images to be present for this test
ir, err := NewImageRuntimeFromOptions(so)
assert.NoError(t, err)
- bb, err := ir.New("docker.io/library/busybox:latest", "", "", writer, nil, SigningOptions{}, false, false)
+ bb, err := ir.New(context.Background(), "docker.io/library/busybox:latest", "", "", writer, nil, SigningOptions{}, false, false)
assert.NoError(t, err)
- bbglibc, err := ir.New("docker.io/library/busybox:glibc", "", "", writer, nil, SigningOptions{}, false, false)
+ bbglibc, err := ir.New(context.Background(), "docker.io/library/busybox:glibc", "", "", writer, nil, SigningOptions{}, false, false)
assert.NoError(t, err)
tm, err := makeLocalMatrix(bb, bbglibc)
@@ -126,7 +127,7 @@ func TestImage_New(t *testing.T) {
// Iterate over the names and delete the image
// after the pull
for _, img := range names {
- newImage, err := ir.New(img, "", "", writer, nil, SigningOptions{}, false, false)
+ newImage, err := ir.New(context.Background(), img, "", "", writer, nil, SigningOptions{}, false, false)
assert.NoError(t, err)
assert.NotEqual(t, newImage.ID(), "")
err = newImage.Remove(false)
@@ -150,7 +151,7 @@ func TestImage_MatchRepoTag(t *testing.T) {
}
ir, err := NewImageRuntimeFromOptions(so)
assert.NoError(t, err)
- newImage, err := ir.New("busybox", "", "", os.Stdout, nil, SigningOptions{}, false, false)
+ newImage, err := ir.New(context.Background(), "busybox", "", "", os.Stdout, nil, SigningOptions{}, false, false)
assert.NoError(t, err)
err = newImage.TagImage("foo:latest")
assert.NoError(t, err)
diff --git a/libpod/image/pull.go b/libpod/image/pull.go
index b2d32b255..74a773987 100644
--- a/libpod/image/pull.go
+++ b/libpod/image/pull.go
@@ -1,6 +1,7 @@
package image
import (
+ "context"
"fmt"
"io"
"os"
@@ -70,7 +71,7 @@ func (ir *Runtime) getPullStruct(srcRef types.ImageReference, destName string) (
}
// returns a list of pullStruct with the srcRef and DstRef based on the transport being used
-func (ir *Runtime) getPullListFromRef(srcRef types.ImageReference, imgName string, sc *types.SystemContext) ([]*pullStruct, error) {
+func (ir *Runtime) getPullListFromRef(ctx context.Context, srcRef types.ImageReference, imgName string, sc *types.SystemContext) ([]*pullStruct, error) {
var pullStructs []*pullStruct
splitArr := strings.Split(imgName, ":")
archFile := splitArr[len(splitArr)-1]
@@ -89,7 +90,7 @@ func (ir *Runtime) getPullListFromRef(srcRef types.ImageReference, imgName strin
// to pull the first image stored in the tar file
if len(manifest) == 0 {
// use the hex of the digest if no manifest is found
- reference, err := getImageDigest(srcRef, sc)
+ reference, err := getImageDigest(ctx, srcRef, sc)
if err != nil {
return nil, err
}
@@ -104,7 +105,7 @@ func (ir *Runtime) getPullListFromRef(srcRef types.ImageReference, imgName strin
dest = manifest[0].RepoTags[0]
} else {
// If the input image has no repotags, we need to feed it a dest anyways
- dest, err = getImageDigest(srcRef, sc)
+ dest, err = getImageDigest(ctx, srcRef, sc)
if err != nil {
return nil, err
}
@@ -155,7 +156,7 @@ func (ir *Runtime) getPullListFromRef(srcRef types.ImageReference, imgName strin
// pullImage pulls an image from configured registries
// By default, only the latest tag (or a specific tag if requested) will be
// pulled.
-func (i *Image) pullImage(writer io.Writer, authfile, signaturePolicyPath string, signingOptions SigningOptions, dockerOptions *DockerRegistryOptions, forceSecure bool) (string, error) {
+func (i *Image) pullImage(ctx context.Context, writer io.Writer, authfile, signaturePolicyPath string, signingOptions SigningOptions, dockerOptions *DockerRegistryOptions, forceSecure bool) (string, error) {
// pullImage copies the image from the source to the destination
var pullStructs []*pullStruct
sc := GetSystemContext(signaturePolicyPath, authfile, false)
@@ -167,7 +168,7 @@ func (i *Image) pullImage(writer io.Writer, authfile, signaturePolicyPath string
return "", errors.Wrap(err, "error getting default registries to try")
}
} else {
- pullStructs, err = i.imageruntime.getPullListFromRef(srcRef, i.InputName, sc)
+ pullStructs, err = i.imageruntime.getPullListFromRef(ctx, srcRef, i.InputName, sc)
if err != nil {
return "", errors.Wrapf(err, "error getting pullStruct info to pull image %q", i.InputName)
}
@@ -201,7 +202,7 @@ func (i *Image) pullImage(writer io.Writer, authfile, signaturePolicyPath string
if writer != nil && (strings.HasPrefix(DockerTransport, imageInfo.srcRef.Transport().Name()) || imageInfo.srcRef.Transport().Name() == AtomicTransport) {
io.WriteString(writer, fmt.Sprintf("Trying to pull %s...", imageInfo.image))
}
- if err = cp.Image(policyContext, imageInfo.dstRef, imageInfo.srcRef, copyOptions); err != nil {
+ if err = cp.Image(ctx, policyContext, imageInfo.dstRef, imageInfo.srcRef, copyOptions); err != nil {
if writer != nil {
io.WriteString(writer, "Failed\n")
}
diff --git a/libpod/pod.go b/libpod/pod.go
index 2126e9228..3cad3f817 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -1,6 +1,7 @@
package libpod
import (
+ "context"
"path/filepath"
"strings"
@@ -81,7 +82,7 @@ func newPod(lockDir string, runtime *Runtime) (*Pod, error) {
// containers. The container ID is mapped to the error encountered. The error is
// set to ErrCtrExists
// If both error and the map are nil, all containers were started successfully
-func (p *Pod) Start() (map[string]error, error) {
+func (p *Pod) Start(ctx context.Context) (map[string]error, error) {
p.lock.Lock()
defer p.lock.Unlock()
@@ -111,7 +112,7 @@ func (p *Pod) Start() (map[string]error, error) {
// Traverse the graph beginning at nodes with no dependencies
for _, node := range graph.noDepNodes {
- startNode(node, false, ctrErrors, ctrsVisited)
+ startNode(ctx, node, false, ctrErrors, ctrsVisited)
}
return ctrErrors, nil
@@ -119,7 +120,7 @@ func (p *Pod) Start() (map[string]error, error) {
// Visit a node on a container graph and start the container, or set an error if
// a dependency failed to start
-func startNode(node *containerNode, setError bool, ctrErrors map[string]error, ctrsVisited map[string]bool) {
+func startNode(ctx context.Context, node *containerNode, setError bool, ctrErrors map[string]error, ctrsVisited map[string]bool) {
// First, check if we have already visited the node
if ctrsVisited[node.id] {
return
@@ -134,7 +135,7 @@ func startNode(node *containerNode, setError bool, ctrErrors map[string]error, c
// Hit anyone who depends on us, and set errors on them too
for _, successor := range node.dependedOn {
- startNode(successor, true, ctrErrors, ctrsVisited)
+ startNode(ctx, successor, true, ctrErrors, ctrsVisited)
}
return
@@ -187,7 +188,7 @@ func startNode(node *containerNode, setError bool, ctrErrors map[string]error, c
// Start the container (only if it is not running)
if !ctrErrored && node.container.state.State != ContainerStateRunning {
- if err := node.container.initAndStart(); err != nil {
+ if err := node.container.initAndStart(ctx); err != nil {
ctrErrored = true
ctrErrors[node.id] = err
}
@@ -197,7 +198,7 @@ func startNode(node *containerNode, setError bool, ctrErrors map[string]error, c
// Recurse to anyone who depends on us and start them
for _, successor := range node.dependedOn {
- startNode(successor, ctrErrored, ctrErrors, ctrsVisited)
+ startNode(ctx, successor, ctrErrored, ctrErrors, ctrsVisited)
}
return
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index acab219c7..3f27df5b9 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -1,6 +1,7 @@
package libpod
import (
+ "context"
"os"
"path/filepath"
"strings"
@@ -27,7 +28,7 @@ type CtrCreateOption func(*Container) error
type ContainerFilter func(*Container) bool
// NewContainer creates a new container from a given OCI config
-func (r *Runtime) NewContainer(rSpec *spec.Spec, options ...CtrCreateOption) (c *Container, err error) {
+func (r *Runtime) NewContainer(ctx context.Context, rSpec *spec.Spec, options ...CtrCreateOption) (c *Container, err error) {
r.lock.Lock()
defer r.lock.Unlock()
if !r.valid {
@@ -60,7 +61,7 @@ func (r *Runtime) NewContainer(rSpec *spec.Spec, options ...CtrCreateOption) (c
}
// Set up storage for the container
- if err := ctr.setupStorage(); err != nil {
+ if err := ctr.setupStorage(ctx); err != nil {
return nil, err
}
defer func() {
diff --git a/libpod/storage.go b/libpod/storage.go
index 967e9889d..ee9ecbda4 100644
--- a/libpod/storage.go
+++ b/libpod/storage.go
@@ -1,6 +1,7 @@
package libpod
import (
+ "context"
"encoding/json"
"time"
@@ -56,7 +57,7 @@ func (metadata *RuntimeContainerMetadata) SetMountLabel(mountLabel string) {
// CreateContainerStorage creates the storage end of things. We already have the container spec created
// TO-DO We should be passing in an Image object in the future.
-func (r *storageService) CreateContainerStorage(systemContext *types.SystemContext, imageName, imageID, containerName, containerID, mountLabel string) (ContainerInfo, error) {
+func (r *storageService) CreateContainerStorage(ctx context.Context, systemContext *types.SystemContext, imageName, imageID, containerName, containerID, mountLabel string) (ContainerInfo, error) {
var ref types.ImageReference
if imageName == "" && imageID == "" {
return ContainerInfo{}, ErrEmptyID
@@ -74,7 +75,7 @@ func (r *storageService) CreateContainerStorage(systemContext *types.SystemConte
return ContainerInfo{}, err
}
// Pull out a copy of the image's configuration.
- image, err := ref.NewImage(systemContext)
+ image, err := ref.NewImage(ctx, systemContext)
if err != nil {
return ContainerInfo{}, err
}