From bde30191f498667f24721b411671a237da06c118 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 5 Dec 2016 14:33:31 -0800 Subject: [PATCH] Move service to execution package Signed-off-by: Michael Crosby --- cmd/containerd/main.go | 2 +- execution/executors/executors.go | 13 ------------- execution/executors/oci/oci.go | 6 ------ {services/execution => execution}/service.go | 17 +++++++---------- 4 files changed, 8 insertions(+), 30 deletions(-) delete mode 100644 execution/executors/executors.go rename {services/execution => execution}/service.go (91%) diff --git a/cmd/containerd/main.go b/cmd/containerd/main.go index e36c141..78159ee 100644 --- a/cmd/containerd/main.go +++ b/cmd/containerd/main.go @@ -13,7 +13,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/containerd" api "github.com/docker/containerd/api/execution" - "github.com/docker/containerd/services/execution" + "github.com/docker/containerd/execution" // metrics "github.com/docker/go-metrics" "github.com/urfave/cli" ) diff --git a/execution/executors/executors.go b/execution/executors/executors.go deleted file mode 100644 index d5fa393..0000000 --- a/execution/executors/executors.go +++ /dev/null @@ -1,13 +0,0 @@ -package executors - -import "github.com/docker/containerd/execution" - -var executors = make(map[string]func() execution.Executor) - -func Register(name string, e func() execution.Executor) { - executors[name] = e -} - -func Get(name string) func() execution.Executor { - return executors[name] -} diff --git a/execution/executors/oci/oci.go b/execution/executors/oci/oci.go index 22e8246..532348f 100644 --- a/execution/executors/oci/oci.go +++ b/execution/executors/oci/oci.go @@ -10,16 +10,10 @@ import ( "github.com/crosbymichael/go-runc" "github.com/docker/containerd/execution" - "github.com/docker/containerd/executors" ) var ErrRootEmpty = errors.New("oci: runtime root cannot be an empty string") -func init() { - executors.Register("oci", New) - executors.Register("runc", New) -} - func New(root string) *OCIRuntime { return &OCIRuntime{ root: root, diff --git a/services/execution/service.go b/execution/service.go similarity index 91% rename from services/execution/service.go rename to execution/service.go index a1502b8..c3262f6 100644 --- a/services/execution/service.go +++ b/execution/service.go @@ -4,35 +4,32 @@ import ( "fmt" api "github.com/docker/containerd/api/execution" - "github.com/docker/containerd/execution" - "github.com/docker/containerd/execution/executors" google_protobuf "github.com/golang/protobuf/ptypes/empty" "github.com/opencontainers/runtime-spec/specs-go" "golang.org/x/net/context" ) -type Opts struct { +type ServiceOpts struct { Root string Runtime string } -func New(o Opts) (*Service, error) { - executor := executors.Get(o.Runtime)() +func New(opts ServiceOpts, executor Executor) (*Service, error) { return &Service{ - o: o, + o: opts, executor: executor, }, nil } type Service struct { - o Opts - executor execution.Executor + o ServiceOpts + executor Executor } func (s *Service) Create(ctx context.Context, r *api.CreateContainerRequest) (*api.CreateContainerResponse, error) { // TODO: write io and bundle path to dir // TODO: open IOs - container, err := s.executor.Create(r.ID, execution.CreateOpts{ + container, err := s.executor.Create(r.ID, CreateOpts{ Bundle: r.BundlePath, // Stdin: r.Stdin, // Stdout: r.Stdout, @@ -111,7 +108,7 @@ func (s *Service) StartProcess(ctx context.Context, r *api.StartProcessRequest) // TODO: generate spec var spec specs.Process // TODO: open IOs - process, err := s.executor.StartProcess(container, execution.CreateProcessOpts{ + process, err := s.executor.StartProcess(container, CreateProcessOpts{ Spec: spec, // Stdin: r.Stdin, // Stdout: r.Stdout,