From bb77300641e9df03def44a6ac46d60e367b4df54 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Tue, 5 Sep 2017 10:29:17 -0400 Subject: [PATCH] Move everything in libpod into a single package for simplicity Signed-off-by: Matthew Heon --- libpod/{ctr => }/container.go | 24 ++++++++++++------------ libpod/options.go | 8 +++----- libpod/{pod => }/pod.go | 14 +++++++------- libpod/runtime.go | 14 ++++++-------- 4 files changed, 28 insertions(+), 32 deletions(-) rename libpod/{ctr => }/container.go (83%) rename libpod/{pod => }/pod.go (75%) diff --git a/libpod/ctr/container.go b/libpod/container.go similarity index 83% rename from libpod/ctr/container.go rename to libpod/container.go index 3e5ed146..6c12fd58 100644 --- a/libpod/ctr/container.go +++ b/libpod/container.go @@ -1,4 +1,4 @@ -package ctr +package libpod import ( "fmt" @@ -8,7 +8,7 @@ import ( var ( // ErrNotImplemented indicates that functionality is not yet implemented - ErrNotImplemented = fmt.Errorf("NOT IMPLEMENTED") + errNotImplemented = fmt.Errorf("NOT IMPLEMENTED") ) // Container is a single OCI container @@ -18,52 +18,52 @@ type Container struct { // Create creates a container in the OCI runtime func (c *Container) Create() error { - return ErrNotImplemented + return errNotImplemented } // Start starts a container func (c *Container) Start() error { - return ErrNotImplemented + return errNotImplemented } // Stop stops a container func (c *Container) Stop() error { - return ErrNotImplemented + return errNotImplemented } // Kill sends a signal to a container func (c *Container) Kill(signal uint) error { - return ErrNotImplemented + return errNotImplemented } // Exec starts a new process inside the container // Returns fully qualified URL of streaming server for executed process func (c *Container) Exec(cmd []string, tty bool, stdin bool) (string, error) { - return "", ErrNotImplemented + return "", errNotImplemented } // Attach attaches to a container // Returns fully qualified URL of streaming server for the container func (c *Container) Attach(stdin, tty bool) (string, error) { - return "", ErrNotImplemented + return "", errNotImplemented } // Mount mounts a container's filesystem on the host // The path where the container has been mounted is returned func (c *Container) Mount() (string, error) { - return "", ErrNotImplemented + return "", errNotImplemented } // Status gets a container's status // TODO this should return relevant information about container state func (c *Container) Status() error { - return ErrNotImplemented + return errNotImplemented } // Export exports a container's root filesystem as a tar archive // The archive will be saved as a file at the given path func (c *Container) Export(path string) error { - return ErrNotImplemented + return errNotImplemented } // Commit commits the changes between a container and its image, creating a new @@ -73,5 +73,5 @@ func (c *Container) Export(path string) error { // a new base image will be created from the contents of the container's // filesystem func (c *Container) Commit() (*storage.Image, error) { - return nil, ErrNotImplemented + return nil, errNotImplemented } diff --git a/libpod/options.go b/libpod/options.go index ed259e55..b5248869 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -5,13 +5,11 @@ import ( "github.com/containers/storage" "github.com/containers/storage/pkg/idtools" - "github.com/kubernetes-incubator/cri-o/libpod/ctr" - "github.com/kubernetes-incubator/cri-o/libpod/pod" ) var ( errRuntimeFinalized = fmt.Errorf("runtime has already been finalized") - ctrNotImplemented = func(c *ctr.Container) error { + ctrNotImplemented = func(c *Container) error { return fmt.Errorf("NOT IMPLEMENTED") } ) @@ -198,12 +196,12 @@ func WithRootFSFromImage(image string, useImageConfig bool) CtrCreateOption { // be added to the pod. // By default no namespaces are shared. To share a namespace, add the Namespace // string constant to the map as a key -func WithSharedNamespaces(from *ctr.Container, namespaces map[string]string) CtrCreateOption { +func WithSharedNamespaces(from *Container, namespaces map[string]string) CtrCreateOption { return ctrNotImplemented } // WithPod adds the container to a pod -func WithPod(pod *pod.Pod) CtrCreateOption { +func WithPod(pod *Pod) CtrCreateOption { return ctrNotImplemented } diff --git a/libpod/pod/pod.go b/libpod/pod.go similarity index 75% rename from libpod/pod/pod.go rename to libpod/pod.go index b552fefe..775441b7 100644 --- a/libpod/pod/pod.go +++ b/libpod/pod.go @@ -1,4 +1,4 @@ -package pod +package libpod import ( "github.com/kubernetes-incubator/cri-o/libpod/ctr" @@ -11,26 +11,26 @@ type Pod struct { // Start starts all containers within a pod that are not already running func (p *Pod) Start() error { - return ctr.ErrNotImplemented + return errNotImplemented } // Stop stops all containers within a pod that are not already stopped func (p *Pod) Stop() error { - return ctr.ErrNotImplemented + return errNotImplemented } // Kill sends a signal to all running containers within a pod func (p *Pod) Kill(signal uint) error { - return ctr.ErrNotImplemented + return errNotImplemented } // GetContainers retrieves the containers in the pod -func (p *Pod) GetContainers() ([]*ctr.Container, error) { - return nil, ctr.ErrNotImplemented +func (p *Pod) GetContainers() ([]*Container, error) { + return nil, errNotImplemented } // Status gets the status of all containers in the pod // TODO This should return a summary of the states of all containers in the pod func (p *Pod) Status() error { - return ctr.ErrNotImplemented + return errNotImplemented } diff --git a/libpod/runtime.go b/libpod/runtime.go index 05abda40..49068473 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -6,8 +6,6 @@ import ( "github.com/containers/image/types" "github.com/containers/storage" - "github.com/kubernetes-incubator/cri-o/libpod/ctr" - "github.com/kubernetes-incubator/cri-o/libpod/pod" "github.com/kubernetes-incubator/cri-o/server/apparmor" "github.com/kubernetes-incubator/cri-o/server/seccomp" spec "github.com/opencontainers/runtime-spec/specs-go" @@ -136,22 +134,22 @@ func (r *Runtime) Shutdown(force bool) error { // A CtrCreateOption is a functional option which alters the Container created // by NewContainer -type CtrCreateOption func(*ctr.Container) error +type CtrCreateOption func(*Container) error // ContainerFilter is a function to determine whether a container is included // in command output. Containers to be outputted are tested using the function. // A true return will include the container, a false return will exclude it. -type ContainerFilter func(*ctr.Container) bool +type ContainerFilter func(*Container) bool // NewContainer creates a new container from a given OCI config -func (r *Runtime) NewContainer(spec *spec.Spec, options ...CtrCreateOption) (*ctr.Container, error) { +func (r *Runtime) NewContainer(spec *spec.Spec, options ...CtrCreateOption) (*Container, error) { return nil, ctr.ErrNotImplemented } // RemoveContainer removes the given container // If force is specified, the container will be stopped first // Otherwise, RemoveContainer will return an error if the container is running -func (r *Runtime) RemoveContainer(c *ctr.Container, force bool) error { +func (r *Runtime) RemoveContainer(c *Container, force bool) error { return ctr.ErrNotImplemented } @@ -179,7 +177,7 @@ func (r *Runtime) GetContainers(filters ...ContainerFilter) ([]*ctr.Container, e // PodFilter is a function to determine whether a pod is included in command // output. Pods to be outputted are tested using the function. A true return // will include the pod, a false return will exclude it. -type PodFilter func(*pod.Pod) bool +type PodFilter func(*Pod) bool // NewPod makes a new, empty pod func (r *Runtime) NewPod() (*pod.Pod, error) { @@ -190,7 +188,7 @@ func (r *Runtime) NewPod() (*pod.Pod, error) { // If force is specified, all containers in the pod will be stopped first // Otherwise, RemovePod will return an error if any container in the pod is running // Remove acts atomically, removing all containers or no containers -func (r *Runtime) RemovePod(p *pod.Pod, force bool) error { +func (r *Runtime) RemovePod(p *Pod, force bool) error { return ctr.ErrNotImplemented }