Begin converting kpod pull to use libpod/runtime

We want to drop brute force mechainism for handling image
movement, this patch experiments with moving kpod pull
to use new libpod interfaces.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh 2017-09-06 14:28:59 +00:00
parent e18e962238
commit 9f282717da
5 changed files with 31 additions and 30 deletions

View file

@ -8,7 +8,9 @@ import (
"github.com/containers/storage"
"github.com/fatih/camelcase"
"github.com/kubernetes-incubator/cri-o/libkpod"
"github.com/kubernetes-incubator/cri-o/libpod"
"github.com/kubernetes-incubator/cri-o/server"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@ -32,6 +34,22 @@ func getStore(c *libkpod.Config) (storage.Store, error) {
return store, nil
}
func getRuntime(c *cli.Context) (*libpod.Runtime, error) {
config, err := getConfig(c)
if err != nil {
return nil, errors.Wrapf(err, "could not get config")
}
options := storage.DefaultStoreOptions
options.GraphRoot = config.Root
options.RunRoot = config.RunRoot
options.GraphDriverName = config.Storage
options.GraphDriverOptions = config.StorageOptions
return libpod.NewRuntime(libpod.WithStorageConfig(options))
}
func shutdownStores() {
for store := range stores {
if _, err := store.Shutdown(false); err != nil {

View file

@ -1,8 +1,8 @@
package main
import (
"github.com/kubernetes-incubator/cri-o/libkpod/common"
"github.com/kubernetes-incubator/cri-o/libpod/images"
"os"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
@ -45,21 +45,11 @@ func pullCmd(c *cli.Context) error {
}
image := args[0]
config, err := getConfig(c)
runtime, err := getRuntime(c)
if err != nil {
return errors.Wrapf(err, "could not get config")
return errors.Wrapf(err, "could not create runtime")
}
store, err := getStore(config)
if err != nil {
return err
}
allTags := c.Bool("all-tags")
systemContext := common.GetSystemContext("")
err = images.PullImage(store, image, allTags, false, systemContext)
if err != nil {
if err := runtime.PullImage(image, c.Bool("all-tags"), os.Stdout); err != nil {
return errors.Errorf("error pulling image from %q: %v", image, err)
}
return nil

View file

@ -6,7 +6,7 @@ import (
"github.com/containers/image/types"
"github.com/containers/storage/pkg/archive"
"github.com/kubernetes-incubator/cri-o/libkpod/common"
"github.com/kubernetes-incubator/cri-o/libpod/common"
"github.com/kubernetes-incubator/cri-o/libpod/images"
"github.com/pkg/errors"
"github.com/urfave/cli"
@ -103,7 +103,7 @@ func pushCmd(c *cli.Context) error {
return err
}
options := libkpodimage.CopyOptions{
options := images.CopyOptions{
Compression: archive.Uncompressed,
SignaturePolicyPath: signaturePolicy,
Store: store,

View file

@ -33,11 +33,6 @@ type CopyOptions struct {
// layer blobs. The default is to not use compression, but
// archive.Gzip is recommended.
Compression archive.Compression
// ReportWriter is an io.Writer which will be used to log the writing
// of the new image.
ReportWriter io.Writer
// Store is the local storage store which holds the source image.
Store storage.Store
// DockerRegistryOptions encapsulates settings that affect how we
// connect or authenticate to a remote registry to which we want to
// push the image.
@ -60,7 +55,7 @@ type ImageFilter func(*storage.Image) bool
// pulled. If allTags is true, all tags for the requested image will be pulled.
// Signature validation will be performed if the Runtime has been appropriately
// configured
func (r *Runtime) PullImage(imgName string, allTags bool) error {
func (r *Runtime) PullImage(imgName string, allTags bool, reportWriter io.Writer) error {
// PullImage copies the image from the source to the destination
var (
images []string
@ -123,7 +118,7 @@ func (r *Runtime) PullImage(imgName string, allTags bool) error {
}
defer policyContext.Destroy()
copyOptions := common.GetCopyOptions(r.output, "", nil, nil, common.SigningOptions{})
copyOptions := common.GetCopyOptions(reportWriter, "", nil, nil, common.SigningOptions{})
for _, image := range images {
destRef, err := is.Transport.ParseStoreReference(r.store, image)
@ -138,7 +133,7 @@ func (r *Runtime) PullImage(imgName string, allTags bool) error {
}
// PushImage pushes the given image to a location described by the given path
func (r *Runtime) PushImage(source string, destination string, options CopyOptions) error {
func (r *Runtime) PushImage(source string, destination string, options CopyOptions, reportWriter io.Writer) error {
// PushImage pushes the src image to the destination
//func PushImage(source, destination string, options CopyOptions) error {
if source == "" || destination == "" {
@ -151,9 +146,9 @@ func (r *Runtime) PushImage(source string, destination string, options CopyOptio
return errors.Wrapf(err, "error getting destination imageReference for %q", destination)
}
policyContext, err := common.GetPolicyContext(options.SignaturePolicyPath)
policyContext, err := common.GetPolicyContext(r.GetConfig().SignaturePolicyPath)
if err != nil {
return errors.Wrapf(err, "Could not get default policy context for signature policy path %q", options.SignaturePolicyPath)
return errors.Wrapf(err, "Could not get default policy context for signature policy path %q", r.GetConfig().SignaturePolicyPath)
}
defer policyContext.Destroy()
// Look up the image name and its layer, then build the imagePushData from
@ -176,7 +171,7 @@ func (r *Runtime) PushImage(source string, destination string, options CopyOptio
return errors.Wrapf(err, "error copying layers and metadata")
}
copyOptions := common.GetCopyOptions(options.ReportWriter, options.SignaturePolicyPath, nil, &options.DockerRegistryOptions, options.SigningOptions)
copyOptions := common.GetCopyOptions(reportWriter, r.GetConfig().SignaturePolicyPath, nil, &options.DockerRegistryOptions, options.SigningOptions)
// Copy the image to the remote destination
err = cp.Image(policyContext, dest, src, copyOptions)

View file

@ -2,7 +2,6 @@ package libpod
import (
"fmt"
"io"
"sync"
"github.com/containers/image/types"
@ -29,7 +28,6 @@ type Runtime struct {
seccompEnabled bool
valid bool
lock sync.RWMutex
output io.Writer
}
// RuntimeConfig contains configuration options used to set up the runtime