Move Container and runtime to plugin pkg
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
fa4e114979
commit
01b9f5ec67
@ -263,8 +263,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
|
||||
@ -286,7 +286,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
|
||||
}
|
||||
@ -356,7 +356,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,9 +44,9 @@ type cgroupsMonitor struct {
|
||||
events chan<- *containerd.Event
|
||||
}
|
||||
|
||||
func (m *cgroupsMonitor) Monitor(c containerd.Container) error {
|
||||
func (m *cgroupsMonitor) Monitor(c plugin.Container) error {
|
||||
// skip non-linux containers
|
||||
if _, ok := c.(containerd.LinuxContainer); !ok {
|
||||
if _, ok := c.(plugin.LinuxContainer); !ok {
|
||||
return nil
|
||||
}
|
||||
id := c.Info().ID
|
||||
@ -64,8 +64,8 @@ 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 {
|
||||
func (m *cgroupsMonitor) Stop(c plugin.Container) error {
|
||||
if _, ok := c.(plugin.LinuxContainer); !ok {
|
||||
return nil
|
||||
}
|
||||
m.collector.Remove(c.Info().ID)
|
||||
|
@ -1,6 +1,6 @@
|
||||
package containerd
|
||||
package plugin
|
||||
|
||||
import "golang.org/x/net/context"
|
||||
import "context"
|
||||
|
||||
type ContainerInfo struct {
|
||||
ID string
|
@ -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,
|
||||
@ -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,7 +281,7 @@ 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()
|
||||
@ -291,7 +291,7 @@ func (s *Service) getContainer(id string) (containerd.Container, error) {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user