Merge pull request #846 from crosbymichael/linux-container
Move container and runtime to plugin pkg
This commit is contained in:
commit
6df793797e
@ -265,8 +265,8 @@ func resolveMetaDB(ctx *cli.Context) (*bolt.DB, error) {
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func loadRuntimes(monitor plugin.ContainerMonitor) (map[string]containerd.Runtime, error) {
|
||||
o := make(map[string]containerd.Runtime)
|
||||
func loadRuntimes(monitor plugin.ContainerMonitor) (map[string]plugin.Runtime, error) {
|
||||
o := make(map[string]plugin.Runtime)
|
||||
for name, rr := range plugin.Registrations() {
|
||||
if rr.Type != plugin.RuntimePlugin {
|
||||
continue
|
||||
@ -288,7 +288,7 @@ func loadRuntimes(monitor plugin.ContainerMonitor) (map[string]containerd.Runtim
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
o[name] = vr.(containerd.Runtime)
|
||||
o[name] = vr.(plugin.Runtime)
|
||||
}
|
||||
return o, nil
|
||||
}
|
||||
@ -358,7 +358,7 @@ func newGRPCServer() *grpc.Server {
|
||||
return s
|
||||
}
|
||||
|
||||
func loadServices(runtimes map[string]containerd.Runtime, store content.Store, sn snapshot.Snapshotter, meta *bolt.DB) ([]plugin.Service, error) {
|
||||
func loadServices(runtimes map[string]plugin.Runtime, store content.Store, sn snapshot.Snapshotter, meta *bolt.DB) ([]plugin.Service, error) {
|
||||
var o []plugin.Service
|
||||
for name, sr := range plugin.Registrations() {
|
||||
if sr.Type != plugin.GRPCPlugin {
|
||||
|
@ -3,24 +3,25 @@
|
||||
package linux
|
||||
|
||||
import (
|
||||
"github.com/containerd/containerd"
|
||||
"context"
|
||||
|
||||
"github.com/containerd/containerd/api/services/shim"
|
||||
"github.com/containerd/containerd/api/types/container"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
protobuf "github.com/gogo/protobuf/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type State struct {
|
||||
pid uint32
|
||||
status containerd.Status
|
||||
status plugin.Status
|
||||
}
|
||||
|
||||
func (s State) Pid() uint32 {
|
||||
return s.pid
|
||||
}
|
||||
|
||||
func (s State) Status() containerd.Status {
|
||||
func (s State) Status() plugin.Status {
|
||||
return s.status
|
||||
}
|
||||
|
||||
@ -37,8 +38,8 @@ type Container struct {
|
||||
shim shim.ShimClient
|
||||
}
|
||||
|
||||
func (c *Container) Info() containerd.ContainerInfo {
|
||||
return containerd.ContainerInfo{
|
||||
func (c *Container) Info() plugin.ContainerInfo {
|
||||
return plugin.ContainerInfo{
|
||||
ID: c.id,
|
||||
Runtime: runtimeName,
|
||||
}
|
||||
@ -49,21 +50,21 @@ func (c *Container) Start(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Container) State(ctx context.Context) (containerd.State, error) {
|
||||
func (c *Container) State(ctx context.Context) (plugin.State, error) {
|
||||
response, err := c.shim.State(ctx, &shim.StateRequest{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var status containerd.Status
|
||||
var status plugin.Status
|
||||
switch response.Status {
|
||||
case container.Status_CREATED:
|
||||
status = containerd.CreatedStatus
|
||||
status = plugin.CreatedStatus
|
||||
case container.Status_RUNNING:
|
||||
status = containerd.RunningStatus
|
||||
status = plugin.RunningStatus
|
||||
case container.Status_STOPPED:
|
||||
status = containerd.StoppedStatus
|
||||
status = plugin.StoppedStatus
|
||||
case container.Status_PAUSED:
|
||||
status = containerd.PausedStatus
|
||||
status = plugin.PausedStatus
|
||||
// TODO: containerd.DeletedStatus
|
||||
}
|
||||
return &State{
|
||||
@ -90,7 +91,7 @@ func (c *Container) Kill(ctx context.Context, signal uint32, all bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Container) Exec(ctx context.Context, opts containerd.ExecOpts) (containerd.Process, error) {
|
||||
func (c *Container) Exec(ctx context.Context, opts plugin.ExecOpts) (plugin.Process, error) {
|
||||
request := &shim.ExecRequest{
|
||||
Stdin: opts.IO.Stdin,
|
||||
Stdout: opts.IO.Stdout,
|
||||
@ -110,7 +111,7 @@ func (c *Container) Exec(ctx context.Context, opts containerd.ExecOpts) (contain
|
||||
c: c,
|
||||
}, nil
|
||||
}
|
||||
func (c *Container) Pty(ctx context.Context, pid uint32, size containerd.ConsoleSize) error {
|
||||
func (c *Container) Pty(ctx context.Context, pid uint32, size plugin.ConsoleSize) error {
|
||||
_, err := c.shim.Pty(ctx, &shim.PtyRequest{
|
||||
Pid: pid,
|
||||
Width: size.Width,
|
||||
@ -139,7 +140,7 @@ func (p *Process) Kill(ctx context.Context, signal uint32, _ bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *Process) State(ctx context.Context) (containerd.State, error) {
|
||||
func (p *Process) State(ctx context.Context) (plugin.State, error) {
|
||||
// use the container status for the status of the process
|
||||
state, err := p.c.State(ctx)
|
||||
if err != nil {
|
||||
|
@ -4,6 +4,7 @@ package linux
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -19,7 +20,6 @@ import (
|
||||
"github.com/containerd/containerd/plugin"
|
||||
runc "github.com/containerd/go-runc"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
@ -37,7 +37,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
var _ = (containerd.Runtime)(&Runtime{})
|
||||
var _ = (plugin.Runtime)(&Runtime{})
|
||||
|
||||
type Config struct {
|
||||
// Runtime is a path or name of an OCI runtime used by the shim
|
||||
@ -81,7 +81,7 @@ type Runtime struct {
|
||||
monitor plugin.ContainerMonitor
|
||||
}
|
||||
|
||||
func (r *Runtime) Create(ctx context.Context, id string, opts containerd.CreateOpts) (containerd.Container, error) {
|
||||
func (r *Runtime) Create(ctx context.Context, id string, opts plugin.CreateOpts) (plugin.Container, error) {
|
||||
path, err := r.newBundle(id, opts.Spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -123,7 +123,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts containerd.CreateO
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (r *Runtime) Delete(ctx context.Context, c containerd.Container) (*containerd.Exit, error) {
|
||||
func (r *Runtime) Delete(ctx context.Context, c plugin.Container) (*plugin.Exit, error) {
|
||||
lc, ok := c.(*Container)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("container cannot be cast as *linux.Container")
|
||||
@ -138,18 +138,18 @@ func (r *Runtime) Delete(ctx context.Context, c containerd.Container) (*containe
|
||||
return nil, err
|
||||
}
|
||||
lc.shim.Exit(ctx, &shim.ExitRequest{})
|
||||
return &containerd.Exit{
|
||||
return &plugin.Exit{
|
||||
Status: rsp.ExitStatus,
|
||||
Timestamp: rsp.ExitedAt,
|
||||
}, r.deleteBundle(lc.id)
|
||||
}
|
||||
|
||||
func (r *Runtime) Containers(ctx context.Context) ([]containerd.Container, error) {
|
||||
func (r *Runtime) Containers(ctx context.Context) ([]plugin.Container, error) {
|
||||
dir, err := ioutil.ReadDir(r.root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var o []containerd.Container
|
||||
var o []plugin.Container
|
||||
for _, fi := range dir {
|
||||
if !fi.IsDir() {
|
||||
continue
|
||||
|
@ -44,11 +44,7 @@ type cgroupsMonitor struct {
|
||||
events chan<- *containerd.Event
|
||||
}
|
||||
|
||||
func (m *cgroupsMonitor) Monitor(c containerd.Container) error {
|
||||
// skip non-linux containers
|
||||
if _, ok := c.(containerd.LinuxContainer); !ok {
|
||||
return nil
|
||||
}
|
||||
func (m *cgroupsMonitor) Monitor(c plugin.Container) error {
|
||||
id := c.Info().ID
|
||||
state, err := c.State(m.context)
|
||||
if err != nil {
|
||||
@ -64,10 +60,7 @@ func (m *cgroupsMonitor) Monitor(c containerd.Container) error {
|
||||
return m.oom.Add(id, cg, m.trigger)
|
||||
}
|
||||
|
||||
func (m *cgroupsMonitor) Stop(c containerd.Container) error {
|
||||
if _, ok := c.(containerd.LinuxContainer); !ok {
|
||||
return nil
|
||||
}
|
||||
func (m *cgroupsMonitor) Stop(c plugin.Container) error {
|
||||
m.collector.Remove(c.Info().ID)
|
||||
return nil
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package containerd
|
||||
package plugin
|
||||
|
||||
import "golang.org/x/net/context"
|
||||
import "context"
|
||||
|
||||
type ContainerInfo struct {
|
||||
ID string
|
||||
@ -28,10 +28,6 @@ type Container interface {
|
||||
CloseStdin(context.Context, uint32) error
|
||||
}
|
||||
|
||||
type LinuxContainer interface {
|
||||
Container
|
||||
}
|
||||
|
||||
type ExecOpts struct {
|
||||
Spec []byte
|
||||
IO IO
|
@ -1,4 +1,4 @@
|
||||
package containerd
|
||||
package plugin
|
||||
|
||||
import "errors"
|
||||
|
@ -5,9 +5,9 @@ import "github.com/containerd/containerd"
|
||||
// ContainerMonitor provides an interface for monitoring of containers within containerd
|
||||
type ContainerMonitor interface {
|
||||
// Monitor adds the provided container to the monitor
|
||||
Monitor(containerd.Container) error
|
||||
Monitor(Container) error
|
||||
// Stop stops and removes the provided container from the monitor
|
||||
Stop(containerd.Container) error
|
||||
Stop(Container) error
|
||||
// Events emits events from the monitor
|
||||
Events(chan<- *containerd.Event)
|
||||
}
|
||||
@ -25,11 +25,11 @@ func NewNoopMonitor() ContainerMonitor {
|
||||
type noopContainerMonitor struct {
|
||||
}
|
||||
|
||||
func (mm *noopContainerMonitor) Monitor(c containerd.Container) error {
|
||||
func (mm *noopContainerMonitor) Monitor(c Container) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *noopContainerMonitor) Stop(c containerd.Container) error {
|
||||
func (mm *noopContainerMonitor) Stop(c Container) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ type multiContainerMonitor struct {
|
||||
monitors []ContainerMonitor
|
||||
}
|
||||
|
||||
func (mm *multiContainerMonitor) Monitor(c containerd.Container) error {
|
||||
func (mm *multiContainerMonitor) Monitor(c Container) error {
|
||||
for _, m := range mm.monitors {
|
||||
if err := m.Monitor(c); err != nil {
|
||||
return err
|
||||
@ -49,7 +49,7 @@ func (mm *multiContainerMonitor) Monitor(c containerd.Container) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *multiContainerMonitor) Stop(c containerd.Container) error {
|
||||
func (mm *multiContainerMonitor) Stop(c Container) error {
|
||||
for _, m := range mm.monitors {
|
||||
if err := m.Stop(c); err != nil {
|
||||
return err
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
|
||||
@ -32,7 +31,7 @@ type Registration struct {
|
||||
type InitContext struct {
|
||||
Root string
|
||||
State string
|
||||
Runtimes map[string]containerd.Runtime
|
||||
Runtimes map[string]Runtime
|
||||
Content content.Store
|
||||
Meta *bolt.DB
|
||||
Snapshotter snapshot.Snapshotter
|
||||
|
@ -1,9 +1,10 @@
|
||||
package containerd
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"github.com/containerd/containerd"
|
||||
)
|
||||
|
||||
type IO struct {
|
||||
@ -17,7 +18,7 @@ type CreateOpts struct {
|
||||
// Spec is the OCI runtime spec
|
||||
Spec []byte
|
||||
// Rootfs mounts to perform to gain access to the container's filesystem
|
||||
Rootfs []Mount
|
||||
Rootfs []containerd.Mount
|
||||
// IO for the container's main process
|
||||
IO IO
|
||||
}
|
||||
@ -37,5 +38,5 @@ type Runtime interface {
|
||||
// Delete removes the container in the runtime
|
||||
Delete(context.Context, Container) (*Exit, error)
|
||||
// Events returns events for the runtime and all containers created by the runtime
|
||||
Events(context.Context) <-chan *Event
|
||||
Events(context.Context) <-chan *containerd.Event
|
||||
}
|
@ -4,11 +4,12 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func newCollector(ctx context.Context, runtimes map[string]containerd.Runtime) (*collector, error) {
|
||||
func newCollector(ctx context.Context, runtimes map[string]plugin.Runtime) (*collector, error) {
|
||||
c := &collector{
|
||||
context: ctx,
|
||||
ch: make(chan *containerd.Event, 2048),
|
||||
@ -42,7 +43,7 @@ type collector struct {
|
||||
}
|
||||
|
||||
// collect collects events from the provided runtime
|
||||
func (c *collector) collect(r containerd.Runtime) error {
|
||||
func (c *collector) collect(r plugin.Runtime) error {
|
||||
c.wg.Add(1)
|
||||
go func() {
|
||||
defer c.wg.Done()
|
||||
|
@ -32,7 +32,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
}
|
||||
return &Service{
|
||||
runtimes: ic.Runtimes,
|
||||
containers: make(map[string]containerd.Container),
|
||||
containers: make(map[string]plugin.Container),
|
||||
collector: c,
|
||||
}, nil
|
||||
}
|
||||
@ -40,8 +40,8 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
type Service struct {
|
||||
mu sync.Mutex
|
||||
|
||||
runtimes map[string]containerd.Runtime
|
||||
containers map[string]containerd.Container
|
||||
runtimes map[string]plugin.Runtime
|
||||
containers map[string]plugin.Container
|
||||
collector *collector
|
||||
}
|
||||
|
||||
@ -61,9 +61,9 @@ func (s *Service) Register(server *grpc.Server) error {
|
||||
}
|
||||
|
||||
func (s *Service) Create(ctx context.Context, r *api.CreateRequest) (*api.CreateResponse, error) {
|
||||
opts := containerd.CreateOpts{
|
||||
opts := plugin.CreateOpts{
|
||||
Spec: r.Spec.Value,
|
||||
IO: containerd.IO{
|
||||
IO: plugin.IO{
|
||||
Stdin: r.Stdin,
|
||||
Stdout: r.Stdout,
|
||||
Stderr: r.Stderr,
|
||||
@ -84,7 +84,7 @@ func (s *Service) Create(ctx context.Context, r *api.CreateRequest) (*api.Create
|
||||
s.mu.Lock()
|
||||
if _, ok := s.containers[r.ID]; ok {
|
||||
s.mu.Unlock()
|
||||
return nil, containerd.ErrContainerExists
|
||||
return nil, plugin.ErrContainerExists
|
||||
}
|
||||
c, err := runtime.Create(ctx, r.ID, opts)
|
||||
if err != nil {
|
||||
@ -140,7 +140,7 @@ func (s *Service) Delete(ctx context.Context, r *api.DeleteRequest) (*api.Delete
|
||||
}, nil
|
||||
}
|
||||
|
||||
func containerFromContainerd(ctx context.Context, c containerd.Container) (*container.Container, error) {
|
||||
func containerFromContainerd(ctx context.Context, c plugin.Container) (*container.Container, error) {
|
||||
state, err := c.State(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -148,13 +148,13 @@ func containerFromContainerd(ctx context.Context, c containerd.Container) (*cont
|
||||
|
||||
var status container.Status
|
||||
switch state.Status() {
|
||||
case containerd.CreatedStatus:
|
||||
case plugin.CreatedStatus:
|
||||
status = container.Status_CREATED
|
||||
case containerd.RunningStatus:
|
||||
case plugin.RunningStatus:
|
||||
status = container.Status_RUNNING
|
||||
case containerd.StoppedStatus:
|
||||
case plugin.StoppedStatus:
|
||||
status = container.Status_STOPPED
|
||||
case containerd.PausedStatus:
|
||||
case plugin.PausedStatus:
|
||||
status = container.Status_PAUSED
|
||||
default:
|
||||
log.G(ctx).WithField("status", state.Status()).Warn("unknown status")
|
||||
@ -235,9 +235,9 @@ func (s *Service) Exec(ctx context.Context, r *api.ExecRequest) (*api.ExecRespon
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
process, err := c.Exec(ctx, containerd.ExecOpts{
|
||||
process, err := c.Exec(ctx, plugin.ExecOpts{
|
||||
Spec: r.Spec.Value,
|
||||
IO: containerd.IO{
|
||||
IO: plugin.IO{
|
||||
Stdin: r.Stdin,
|
||||
Stdout: r.Stdout,
|
||||
Stderr: r.Stderr,
|
||||
@ -261,7 +261,7 @@ func (s *Service) Pty(ctx context.Context, r *api.PtyRequest) (*google_protobuf.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := c.Pty(ctx, r.Pid, containerd.ConsoleSize{
|
||||
if err := c.Pty(ctx, r.Pid, plugin.ConsoleSize{
|
||||
Width: r.Width,
|
||||
Height: r.Height,
|
||||
}); err != nil {
|
||||
@ -281,20 +281,20 @@ func (s *Service) CloseStdin(ctx context.Context, r *api.CloseStdinRequest) (*go
|
||||
return empty, nil
|
||||
}
|
||||
|
||||
func (s *Service) getContainer(id string) (containerd.Container, error) {
|
||||
func (s *Service) getContainer(id string) (plugin.Container, error) {
|
||||
s.mu.Lock()
|
||||
c, ok := s.containers[id]
|
||||
s.mu.Unlock()
|
||||
if !ok {
|
||||
return nil, containerd.ErrContainerNotExist
|
||||
return nil, plugin.ErrContainerNotExist
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (s *Service) getRuntime(name string) (containerd.Runtime, error) {
|
||||
func (s *Service) getRuntime(name string) (plugin.Runtime, error) {
|
||||
runtime, ok := s.runtimes[name]
|
||||
if !ok {
|
||||
return nil, containerd.ErrUnknownRuntime
|
||||
return nil, plugin.ErrUnknownRuntime
|
||||
}
|
||||
return runtime, nil
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
@ -10,10 +11,10 @@ import (
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/windows/hcs"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/context"
|
||||
winsys "golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@ -33,7 +34,7 @@ func loadContainers(ctx context.Context, h *hcs.HCS, sendEvent eventCallback) ([
|
||||
for _, c := range hCtr {
|
||||
containers = append(containers, &container{
|
||||
ctr: c,
|
||||
status: containerd.RunningStatus,
|
||||
status: plugin.RunningStatus,
|
||||
sendEvent: sendEvent,
|
||||
})
|
||||
}
|
||||
@ -41,7 +42,7 @@ func loadContainers(ctx context.Context, h *hcs.HCS, sendEvent eventCallback) ([
|
||||
return containers, nil
|
||||
}
|
||||
|
||||
func newContainer(ctx context.Context, h *hcs.HCS, id string, spec RuntimeSpec, io containerd.IO, sendEvent eventCallback) (*container, error) {
|
||||
func newContainer(ctx context.Context, h *hcs.HCS, id string, spec RuntimeSpec, io plugin.IO, sendEvent eventCallback) (*container, error) {
|
||||
cio, err := hcs.NewIO(io.Stdin, io.Stdout, io.Stderr, io.Terminal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -55,22 +56,21 @@ func newContainer(ctx context.Context, h *hcs.HCS, id string, spec RuntimeSpec,
|
||||
|
||||
return &container{
|
||||
ctr: hcsCtr,
|
||||
status: containerd.CreatedStatus,
|
||||
status: plugin.CreatedStatus,
|
||||
sendEvent: sendEvent,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// container implements both containerd.Container and containerd.State
|
||||
type container struct {
|
||||
sync.Mutex
|
||||
|
||||
ctr *hcs.Container
|
||||
status containerd.Status
|
||||
status plugin.Status
|
||||
sendEvent eventCallback
|
||||
}
|
||||
|
||||
func (c *container) Info() containerd.ContainerInfo {
|
||||
return containerd.ContainerInfo{
|
||||
func (c *container) Info() plugin.ContainerInfo {
|
||||
return plugin.ContainerInfo{
|
||||
ID: c.ctr.ID(),
|
||||
Runtime: runtimeName,
|
||||
}
|
||||
@ -86,7 +86,7 @@ func (c *container) Start(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
c.setStatus(containerd.RunningStatus)
|
||||
c.setStatus(plugin.RunningStatus)
|
||||
c.sendEvent(c.ctr.ID(), containerd.StartEvent, c.ctr.Pid(), 0, time.Time{})
|
||||
|
||||
// Wait for our process to terminate
|
||||
@ -95,7 +95,7 @@ func (c *container) Start(ctx context.Context) error {
|
||||
if err != nil {
|
||||
log.G(ctx).Debug(err)
|
||||
}
|
||||
c.setStatus(containerd.StoppedStatus)
|
||||
c.setStatus(plugin.StoppedStatus)
|
||||
c.sendEvent(c.ctr.ID(), containerd.ExitEvent, c.ctr.Pid(), ec, c.ctr.Processes()[0].ExitedAt())
|
||||
}()
|
||||
|
||||
@ -116,7 +116,7 @@ func (c *container) Resume(ctx context.Context) error {
|
||||
return c.ctr.Resume()
|
||||
}
|
||||
|
||||
func (c *container) State(ctx context.Context) (containerd.State, error) {
|
||||
func (c *container) State(ctx context.Context) (plugin.State, error) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ func (c *container) Kill(ctx context.Context, signal uint32, all bool) error {
|
||||
return c.ctr.Stop(ctx)
|
||||
}
|
||||
|
||||
func (c *container) Exec(ctx context.Context, opts containerd.ExecOpts) (containerd.Process, error) {
|
||||
func (c *container) Exec(ctx context.Context, opts plugin.ExecOpts) (plugin.Process, error) {
|
||||
if c.ctr.Pid() == 0 {
|
||||
return nil, ErrLoadedContainer
|
||||
}
|
||||
@ -162,11 +162,11 @@ func (c *container) CloseStdin(ctx context.Context, pid uint32) error {
|
||||
return c.ctr.CloseStdin(ctx, pid)
|
||||
}
|
||||
|
||||
func (c *container) Pty(ctx context.Context, pid uint32, size containerd.ConsoleSize) error {
|
||||
func (c *container) Pty(ctx context.Context, pid uint32, size plugin.ConsoleSize) error {
|
||||
return c.ctr.Pty(ctx, pid, size)
|
||||
}
|
||||
|
||||
func (c *container) Status() containerd.Status {
|
||||
func (c *container) Status() plugin.Status {
|
||||
return c.getStatus()
|
||||
}
|
||||
|
||||
@ -174,13 +174,13 @@ func (c *container) Pid() uint32 {
|
||||
return c.ctr.Pid()
|
||||
}
|
||||
|
||||
func (c *container) setStatus(status containerd.Status) {
|
||||
func (c *container) setStatus(status plugin.Status) {
|
||||
c.Lock()
|
||||
c.status = status
|
||||
c.Unlock()
|
||||
}
|
||||
|
||||
func (c *container) getStatus() containerd.Status {
|
||||
func (c *container) getStatus() plugin.Status {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
return c.status
|
||||
|
@ -15,8 +15,8 @@ import (
|
||||
|
||||
"github.com/Microsoft/hcsshim"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/windows/pid"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
@ -216,7 +216,7 @@ func (c *Container) CloseStdin(ctx context.Context, pid uint32) error {
|
||||
return proc.CloseStdin()
|
||||
}
|
||||
|
||||
func (c *Container) Pty(ctx context.Context, pid uint32, size containerd.ConsoleSize) error {
|
||||
func (c *Container) Pty(ctx context.Context, pid uint32, size plugin.ConsoleSize) error {
|
||||
var proc *Process
|
||||
c.Lock()
|
||||
for _, p := range c.processes {
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/Microsoft/hcsshim"
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -35,14 +35,14 @@ func (p *Process) ExitedAt() time.Time {
|
||||
return p.exitedAt
|
||||
}
|
||||
|
||||
func (p *Process) Status() containerd.Status {
|
||||
func (p *Process) Status() plugin.Status {
|
||||
select {
|
||||
case <-p.ecSync:
|
||||
return containerd.StoppedStatus
|
||||
return plugin.StoppedStatus
|
||||
default:
|
||||
}
|
||||
|
||||
return containerd.RunningStatus
|
||||
return plugin.RunningStatus
|
||||
}
|
||||
|
||||
func (p *Process) Delete() error {
|
||||
|
@ -3,9 +3,10 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"github.com/containerd/containerd"
|
||||
"context"
|
||||
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/windows/hcs"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// process implements containerd.Process and containerd.State
|
||||
@ -13,7 +14,7 @@ type process struct {
|
||||
*hcs.Process
|
||||
}
|
||||
|
||||
func (p *process) State(ctx context.Context) (containerd.State, error) {
|
||||
func (p *process) State(ctx context.Context) (plugin.State, error) {
|
||||
return p, nil
|
||||
}
|
||||
|
||||
@ -21,7 +22,7 @@ func (p *process) Kill(ctx context.Context, sig uint32, all bool) error {
|
||||
return p.Process.Kill()
|
||||
}
|
||||
|
||||
func (p *process) Status() containerd.Status {
|
||||
func (p *process) Status() plugin.Status {
|
||||
return p.Process.Status()
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -17,8 +18,6 @@ import (
|
||||
"github.com/containerd/containerd/windows/pid"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -26,7 +25,7 @@ const (
|
||||
owner = "containerd"
|
||||
)
|
||||
|
||||
var _ = (containerd.Runtime)(&Runtime{})
|
||||
var _ = (plugin.Runtime)(&Runtime{})
|
||||
|
||||
func init() {
|
||||
plugin.Register(runtimeName, &plugin.Registration{
|
||||
@ -36,13 +35,13 @@ func init() {
|
||||
}
|
||||
|
||||
func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
c, cancel := context.WithCancel(ic.Context)
|
||||
|
||||
rootDir := filepath.Join(ic.Root, runtimeName)
|
||||
if err := os.MkdirAll(rootDir, 0755); err != nil {
|
||||
return nil, errors.Wrapf(err, "could not create state directory at %s", rootDir)
|
||||
}
|
||||
|
||||
c, cancel := context.WithCancel(ic.Context)
|
||||
r := &Runtime{
|
||||
pidPool: pid.NewPool(),
|
||||
containers: make(map[string]*container),
|
||||
@ -102,7 +101,7 @@ type RuntimeSpec struct {
|
||||
hcs.Configuration
|
||||
}
|
||||
|
||||
func (r *Runtime) Create(ctx context.Context, id string, opts containerd.CreateOpts) (containerd.Container, error) {
|
||||
func (r *Runtime) Create(ctx context.Context, id string, opts plugin.CreateOpts) (plugin.Container, error) {
|
||||
var rtSpec RuntimeSpec
|
||||
if err := json.Unmarshal(opts.Spec, &rtSpec); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to unmarshal oci spec")
|
||||
@ -120,7 +119,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts containerd.CreateO
|
||||
return ctr, nil
|
||||
}
|
||||
|
||||
func (r *Runtime) Delete(ctx context.Context, c containerd.Container) (*containerd.Exit, error) {
|
||||
func (r *Runtime) Delete(ctx context.Context, c plugin.Container) (*plugin.Exit, error) {
|
||||
wc, ok := c.(*container)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("container cannot be cast as *windows.container")
|
||||
@ -136,16 +135,16 @@ func (r *Runtime) Delete(ctx context.Context, c containerd.Container) (*containe
|
||||
delete(r.containers, wc.ctr.ID())
|
||||
r.Unlock()
|
||||
|
||||
return &containerd.Exit{
|
||||
return &plugin.Exit{
|
||||
Status: ec,
|
||||
Timestamp: wc.ctr.Processes()[0].ExitedAt(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Runtime) Containers(ctx context.Context) ([]containerd.Container, error) {
|
||||
func (r *Runtime) Containers(ctx context.Context) ([]plugin.Container, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
list := make([]containerd.Container, len(r.containers))
|
||||
list := make([]plugin.Container, len(r.containers))
|
||||
for _, c := range r.containers {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
Loading…
Reference in New Issue
Block a user