Merge pull request #2164 from baude/wehateruntime

podman-remote enable containers
This commit is contained in:
OpenShift Merge Robot
2019-01-16 00:58:11 -08:00
committed by GitHub
10 changed files with 106 additions and 30 deletions

View File

@ -71,7 +71,7 @@ func imageExistsCmd(c *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Runtime.Shutdown(false)
defer runtime.Shutdown(false)
if _, err := runtime.NewImageFromLocal(args[0]); err != nil {
//TODO we need to ask about having varlink defined errors exposed
//so we can reuse them
@ -88,13 +88,13 @@ func containerExistsCmd(c *cli.Context) error {
if len(args) > 1 || len(args) < 1 {
return errors.New("you may only check for the existence of one container at a time")
}
runtime, err := libpodruntime.GetRuntime(c)
runtime, err := adapter.GetRuntime(c)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
if _, err := runtime.LookupContainer(args[0]); err != nil {
if errors.Cause(err) == libpod.ErrNoSuchCtr {
if errors.Cause(err) == libpod.ErrNoSuchCtr || err.Error() == "io.podman.ContainerNotFound" {
os.Exit(1)
}
return err

View File

@ -1,13 +1,13 @@
package main
import (
"github.com/containers/libpod/libpod/adapter"
"reflect"
"strconv"
"strings"
"time"
"github.com/containers/libpod/cmd/podman/formats"
"github.com/containers/libpod/libpod/adapter"
"github.com/containers/libpod/libpod/image"
"github.com/docker/go-units"
"github.com/pkg/errors"
@ -76,7 +76,7 @@ func historyCmd(c *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Runtime.Shutdown(false)
defer runtime.Shutdown(false)
format := genHistoryFormat(c.String("format"), c.Bool("quiet"))

View File

@ -2,8 +2,6 @@ package main
import (
"context"
"github.com/containers/libpod/cmd/podman/imagefilters"
"github.com/containers/libpod/libpod/adapter"
"reflect"
"sort"
"strings"
@ -11,6 +9,8 @@ import (
"unicode"
"github.com/containers/libpod/cmd/podman/formats"
"github.com/containers/libpod/cmd/podman/imagefilters"
"github.com/containers/libpod/libpod/adapter"
"github.com/containers/libpod/libpod/image"
"github.com/docker/go-units"
"github.com/opencontainers/go-digest"
@ -156,7 +156,7 @@ func imagesCmd(c *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "Could not get runtime")
}
defer runtime.Runtime.Shutdown(false)
defer runtime.Shutdown(false)
if len(c.Args()) == 1 {
newImage, err = runtime.NewImageFromLocal(c.Args().Get(0))
if err != nil {

View File

@ -1,11 +1,11 @@
package main
import (
"github.com/containers/libpod/libpod/adapter"
"runtime"
"github.com/containers/libpod/cmd/podman/formats"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/adapter"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@ -43,9 +43,9 @@ func infoCmd(c *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Runtime.Shutdown(false)
defer runtime.Shutdown(false)
infoArr, err := runtime.Runtime.Info()
infoArr, err := runtime.Info()
if err != nil {
return errors.Wrapf(err, "error getting info")
}

View File

@ -2,7 +2,6 @@ package main
import (
"fmt"
"github.com/containers/libpod/libpod/adapter"
"io"
"os"
"strings"
@ -10,6 +9,7 @@ import (
dockerarchive "github.com/containers/image/docker/archive"
"github.com/containers/image/transports/alltransports"
"github.com/containers/image/types"
"github.com/containers/libpod/libpod/adapter"
image2 "github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
@ -68,7 +68,7 @@ func pullCmd(c *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Runtime.Shutdown(false)
defer runtime.Shutdown(false)
args := c.Args()
if len(args) == 0 {

View File

@ -61,7 +61,7 @@ func rmiCmd(c *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Runtime.Shutdown(false)
defer runtime.Shutdown(false)
args := c.Args()
if len(args) == 0 && !removeAll {

View File

@ -27,7 +27,7 @@ func tagCmd(c *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "could not create runtime")
}
defer runtime.Runtime.Shutdown(false)
defer runtime.Shutdown(false)
newImage, err := runtime.NewImageFromLocal(args[0])
if err != nil {

View File

@ -61,7 +61,7 @@ type ImageSearch (
star_count: int
)
# ListContainer is the returned struct for an individual container
# ListContainerData is the returned struct for an individual container
type ListContainerData (
id: string,
image: string,

View File

@ -15,8 +15,8 @@ import (
// LocalRuntime describes a typical libpod runtime
type LocalRuntime struct {
Runtime *libpod.Runtime
Remote bool
*libpod.Runtime
Remote bool
}
// ContainerImage ...
@ -24,6 +24,11 @@ type ContainerImage struct {
*image.Image
}
// Container ...
type Container struct {
*libpod.Container
}
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
runtime, err := libpodruntime.GetRuntime(c)
@ -85,3 +90,12 @@ func (r *LocalRuntime) New(ctx context.Context, name, signaturePolicyPath, authf
func (r *LocalRuntime) RemoveImage(ctx context.Context, img *ContainerImage, force bool) (string, error) {
return r.Runtime.RemoveImage(ctx, img.Image, force)
}
// LookupContainer ...
func (r *LocalRuntime) LookupContainer(idOrName string) (*Container, error) {
ctr, err := r.Runtime.LookupContainer(idOrName)
if err != nil {
return nil, err
}
return &Container{ctr}, nil
}

View File

@ -22,13 +22,13 @@ type RemoteImageRuntime struct{}
// RemoteRuntime describes a wrapper runtime struct
type RemoteRuntime struct {
Conn *varlink.Connection
Remote bool
}
// LocalRuntime describes a typical libpod runtime
type LocalRuntime struct {
Runtime *RemoteRuntime
Remote bool
Conn *varlink.Connection
*RemoteRuntime
}
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
@ -38,11 +38,14 @@ func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
if err != nil {
return nil, err
}
return &LocalRuntime{
Runtime: &runtime,
Remote: true,
Conn: conn,
}, nil
rr := RemoteRuntime{
Conn: conn,
Remote: true,
}
foo := LocalRuntime{
&rr,
}
return &foo, nil
}
// Shutdown is a bogus wrapper for compat with the libpod runtime
@ -70,6 +73,30 @@ type remoteImage struct {
Runtime *LocalRuntime
}
// Container ...
type Container struct {
remoteContainer
}
// remoteContainer ....
type remoteContainer struct {
ID string
Image string
ImageID string
Command []string
Created time.Time
RunningFor string
Status string
//Ports []ocicni.PortMapping
RootFsSize int64
RWSize int64
Names string
Labels []map[string]string
// Mounts []string
// ContainerRunning bool
//Namespaces []LinuxNameSpace
}
// GetImages returns a slice of containerimages over a varlink connection
func (r *LocalRuntime) GetImages() ([]*ContainerImage, error) {
var newImages []*ContainerImage
@ -213,10 +240,6 @@ func (ci *ContainerImage) TagImage(tag string) error {
return err
}
func (r RemoteRuntime) RemoveImage(force bool) error {
return nil
}
// RemoveImage calls varlink to remove an image
func (r *LocalRuntime) RemoveImage(ctx context.Context, img *ContainerImage, force bool) (string, error) {
return iopodman.RemoveImage().Call(r.Conn, img.InputName, force)
@ -246,3 +269,42 @@ func (ci *ContainerImage) History(ctx context.Context) ([]*image.History, error)
}
return imageHistories, nil
}
// LookupContainer gets basic information about container over a varlink
// connection and then translates it to a *Container
func (r *RemoteRuntime) LookupContainer(idOrName string) (*Container, error) {
container, err := iopodman.GetContainer().Call(r.Conn, idOrName)
if err != nil {
return nil, err
}
return listContainerDataToContainer(container)
}
// listContainerDataToContainer takes a varlink listcontainerData struct and makes
// an "adapted" Container
func listContainerDataToContainer(listData iopodman.ListContainerData) (*Container, error) {
created, err := splitStringDate(listData.Createdat)
if err != nil {
return nil, err
}
rc := remoteContainer{
// TODO commented out attributes will be populated when podman-remote ps
// is implemented. They are not needed yet for basic container operations.
ID: listData.Id,
Image: listData.Image,
ImageID: listData.Imageid,
Command: listData.Command,
Created: created,
RunningFor: listData.Runningfor,
Status: listData.Status,
//ports:
RootFsSize: listData.Rootfssize,
RWSize: listData.Rwsize,
Names: listData.Names,
//Labels:
//Mounts
//ContainerRunning:
//namespaces:
}
return &Container{rc}, nil
}