Merge pull request #803 from rhatdan/libpod

Move libkpod/image libkpod/layer to libpod/images and libpod/layers
This commit is contained in:
Daniel J Walsh 2017-09-07 15:20:31 -04:00 committed by GitHub
commit 3c468b6f51
27 changed files with 288 additions and 119 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

@ -12,7 +12,7 @@ import (
"github.com/containers/storage"
units "github.com/docker/go-units"
"github.com/kubernetes-incubator/cri-o/cmd/kpod/formats"
"github.com/kubernetes-incubator/cri-o/libkpod/common"
"github.com/kubernetes-incubator/cri-o/libpod/common"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"

View file

@ -6,7 +6,7 @@ import (
"github.com/containers/storage"
"github.com/kubernetes-incubator/cri-o/cmd/kpod/formats"
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
libpod "github.com/kubernetes-incubator/cri-o/libpod/images"
digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/urfave/cli"
@ -89,9 +89,9 @@ func imagesCmd(c *cli.Context) error {
return errors.New("'kpod images' requires at most 1 argument")
}
var params *libkpodimage.FilterParams
var params *libpod.FilterParams
if c.IsSet("filter") {
params, err = libkpodimage.ParseFilter(store, c.String("filter"))
params, err = libpod.ParseFilter(store, c.String("filter"))
if err != nil {
return errors.Wrapf(err, "error parsing filter")
}
@ -99,7 +99,7 @@ func imagesCmd(c *cli.Context) error {
params = nil
}
imageList, err := libkpodimage.GetImagesMatchingFilter(store, params, name)
imageList, err := libpod.GetImagesMatchingFilter(store, params, name)
if err != nil {
return errors.Wrapf(err, "could not get list of images matching filter")
}
@ -141,7 +141,7 @@ func outputImages(store storage.Store, images []storage.Image, truncate, digests
names = img.Names
}
info, imageDigest, size, _ := libkpodimage.InfoAndDigestAndSize(store, img)
info, imageDigest, size, _ := libpod.InfoAndDigestAndSize(store, img)
if info != nil {
createdTime = info.Created
}
@ -151,7 +151,7 @@ func outputImages(store storage.Store, images []storage.Image, truncate, digests
Name: names,
Digest: imageDigest,
CreatedAt: createdTime.Format("Jan 2, 2006 15:04"),
Size: libkpodimage.FormattedSize(float64(size)),
Size: libpod.FormattedSize(float64(size)),
}
imageOutput = append(imageOutput, params)
}

View file

@ -3,7 +3,7 @@ package main
import (
"github.com/kubernetes-incubator/cri-o/cmd/kpod/formats"
"github.com/kubernetes-incubator/cri-o/libkpod"
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
"github.com/kubernetes-incubator/cri-o/libpod/images"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@ -85,14 +85,14 @@ func inspectCmd(c *cli.Context) error {
return errors.Wrapf(err, "error parsing container data")
}
case inspectTypeImage:
data, err = libkpodimage.GetData(server.Store(), name)
data, err = images.GetData(server.Store(), name)
if err != nil {
return errors.Wrapf(err, "error parsing image data")
}
case inspectAll:
ctrData, err := server.GetContainerData(name, size)
if err != nil {
imgData, err := libkpodimage.GetData(server.Store(), name)
imgData, err := images.GetData(server.Store(), name)
if err != nil {
return errors.Wrapf(err, "error parsing container or image data")
}

View file

@ -7,8 +7,8 @@ import (
"io/ioutil"
"github.com/containers/storage"
"github.com/kubernetes-incubator/cri-o/libkpod/common"
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
"github.com/kubernetes-incubator/cri-o/libpod/common"
"github.com/kubernetes-incubator/cri-o/libpod/images"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@ -105,5 +105,5 @@ func loadImage(store storage.Store, opts loadOptions) error {
src := dockerArchive + opts.input
return libkpodimage.PullImage(store, src, false, opts.quiet, systemContext)
return images.PullImage(store, src, false, opts.quiet, systemContext)
}

View file

@ -1,8 +1,8 @@
package main
import (
"github.com/kubernetes-incubator/cri-o/libkpod/common"
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
"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 = libkpodimage.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,8 +6,8 @@ import (
"github.com/containers/image/types"
"github.com/containers/storage/pkg/archive"
"github.com/kubernetes-incubator/cri-o/libkpod/common"
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
"github.com/kubernetes-incubator/cri-o/libpod/common"
"github.com/kubernetes-incubator/cri-o/libpod/images"
"github.com/pkg/errors"
"github.com/urfave/cli"
"golang.org/x/crypto/ssh/terminal"
@ -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,
@ -120,5 +120,5 @@ func pushCmd(c *cli.Context) error {
if !c.Bool("quiet") {
options.ReportWriter = os.Stderr
}
return libkpodimage.PushImage(srcName, destName, options)
return images.PushImage(srcName, destName, options)
}

View file

@ -4,7 +4,7 @@ import (
"fmt"
"github.com/containers/storage"
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
"github.com/kubernetes-incubator/cri-o/libpod/images"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@ -49,7 +49,7 @@ func rmiCmd(c *cli.Context) error {
}
for _, id := range args {
image, err := libkpodimage.FindImage(store, id)
image, err := images.FindImage(store, id)
if err != nil {
return errors.Wrapf(err, "could not get image %q", id)
}
@ -68,14 +68,14 @@ func rmiCmd(c *cli.Context) error {
}
}
// If the user supplied an ID, we cannot delete the image if it is referred to by multiple tags
if libkpodimage.MatchesID(image.ID, id) {
if images.MatchesID(image.ID, id) {
if len(image.Names) > 1 && !force {
return fmt.Errorf("unable to delete %s (must force) - image is referred to in multiple tags", image.ID)
}
// If it is forced, we have to untag the image so that it can be deleted
image.Names = image.Names[:0]
} else {
name, err2 := libkpodimage.UntagImage(store, image, id)
name, err2 := images.UntagImage(store, image, id)
if err2 != nil {
return err
}
@ -85,7 +85,7 @@ func rmiCmd(c *cli.Context) error {
if len(image.Names) > 0 {
continue
}
id, err := libkpodimage.RemoveImage(image, store)
id, err := images.RemoveImage(image, store)
if err != nil {
return err
}

View file

@ -4,7 +4,7 @@ import (
"os"
"github.com/containers/storage"
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
"github.com/kubernetes-incubator/cri-o/libpod/images"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
@ -83,7 +83,7 @@ func saveCmd(c *cli.Context) error {
func saveImage(store storage.Store, opts saveOptions) error {
dst := dockerArchive + opts.output
pushOpts := libkpodimage.CopyOptions{
pushOpts := images.CopyOptions{
SignaturePolicyPath: "",
Store: store,
}
@ -92,7 +92,7 @@ func saveImage(store storage.Store, opts saveOptions) error {
// future pull requests will fix this
for _, image := range opts.images {
dest := dst + ":" + image
if err := libkpodimage.PushImage(image, dest, pushOpts); err != nil {
if err := images.PushImage(image, dest, pushOpts); err != nil {
return errors.Wrapf(err, "unable to save %q", image)
}
}

View file

@ -10,7 +10,7 @@ import (
tm "github.com/buger/goterm"
"github.com/kubernetes-incubator/cri-o/libkpod"
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
"github.com/kubernetes-incubator/cri-o/libpod/images"
"github.com/kubernetes-incubator/cri-o/oci"
"github.com/pkg/errors"
"github.com/urfave/cli"
@ -179,7 +179,7 @@ func outputStatsUsingFormatString(stats *libkpod.ContainerStats) {
}
func combineHumanValues(a, b uint64) string {
return fmt.Sprintf("%s / %s", libkpodimage.FormattedSize(float64(a)), libkpodimage.FormattedSize(float64(b)))
return fmt.Sprintf("%s / %s", images.FormattedSize(float64(a)), images.FormattedSize(float64(b)))
}
func floatToPercentString(f float64) string {

View file

@ -3,7 +3,7 @@ package main
import (
"github.com/containers/image/docker/reference"
"github.com/containers/storage"
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
"github.com/kubernetes-incubator/cri-o/libpod/images"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@ -32,7 +32,7 @@ func tagCmd(c *cli.Context) error {
if err != nil {
return err
}
img, err := libkpodimage.FindImage(store, args[0])
img, err := images.FindImage(store, args[0])
if err != nil {
return err
}