Update windows for plugin interfaces
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
a11de50127
commit
5a2ad6393f
@ -3,6 +3,7 @@
|
|||||||
package windows
|
package windows
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
@ -10,10 +11,10 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/windows/hcs"
|
"github.com/containerd/containerd/windows/hcs"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/net/context"
|
|
||||||
winsys "golang.org/x/sys/windows"
|
winsys "golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ func loadContainers(ctx context.Context, h *hcs.HCS, sendEvent eventCallback) ([
|
|||||||
for _, c := range hCtr {
|
for _, c := range hCtr {
|
||||||
containers = append(containers, &container{
|
containers = append(containers, &container{
|
||||||
ctr: c,
|
ctr: c,
|
||||||
status: containerd.RunningStatus,
|
status: plugin.RunningStatus,
|
||||||
sendEvent: sendEvent,
|
sendEvent: sendEvent,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -41,7 +42,7 @@ func loadContainers(ctx context.Context, h *hcs.HCS, sendEvent eventCallback) ([
|
|||||||
return containers, nil
|
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)
|
cio, err := hcs.NewIO(io.Stdin, io.Stdout, io.Stderr, io.Terminal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -55,22 +56,21 @@ func newContainer(ctx context.Context, h *hcs.HCS, id string, spec RuntimeSpec,
|
|||||||
|
|
||||||
return &container{
|
return &container{
|
||||||
ctr: hcsCtr,
|
ctr: hcsCtr,
|
||||||
status: containerd.CreatedStatus,
|
status: plugin.CreatedStatus,
|
||||||
sendEvent: sendEvent,
|
sendEvent: sendEvent,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// container implements both containerd.Container and containerd.State
|
|
||||||
type container struct {
|
type container struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
ctr *hcs.Container
|
ctr *hcs.Container
|
||||||
status containerd.Status
|
status plugin.Status
|
||||||
sendEvent eventCallback
|
sendEvent eventCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *container) Info() containerd.ContainerInfo {
|
func (c *container) Info() plugin.ContainerInfo {
|
||||||
return containerd.ContainerInfo{
|
return plugin.ContainerInfo{
|
||||||
ID: c.ctr.ID(),
|
ID: c.ctr.ID(),
|
||||||
Runtime: runtimeName,
|
Runtime: runtimeName,
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ func (c *container) Start(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.setStatus(containerd.RunningStatus)
|
c.setStatus(plugin.RunningStatus)
|
||||||
c.sendEvent(c.ctr.ID(), containerd.StartEvent, c.ctr.Pid(), 0, time.Time{})
|
c.sendEvent(c.ctr.ID(), containerd.StartEvent, c.ctr.Pid(), 0, time.Time{})
|
||||||
|
|
||||||
// Wait for our process to terminate
|
// Wait for our process to terminate
|
||||||
@ -95,7 +95,7 @@ func (c *container) Start(ctx context.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.G(ctx).Debug(err)
|
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())
|
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()
|
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
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ func (c *container) Kill(ctx context.Context, signal uint32, all bool) error {
|
|||||||
return c.ctr.Stop(ctx)
|
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 {
|
if c.ctr.Pid() == 0 {
|
||||||
return nil, ErrLoadedContainer
|
return nil, ErrLoadedContainer
|
||||||
}
|
}
|
||||||
@ -162,11 +162,11 @@ func (c *container) CloseStdin(ctx context.Context, pid uint32) error {
|
|||||||
return c.ctr.CloseStdin(ctx, pid)
|
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)
|
return c.ctr.Pty(ctx, pid, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *container) Status() containerd.Status {
|
func (c *container) Status() plugin.Status {
|
||||||
return c.getStatus()
|
return c.getStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,13 +174,13 @@ func (c *container) Pid() uint32 {
|
|||||||
return c.ctr.Pid()
|
return c.ctr.Pid()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *container) setStatus(status containerd.Status) {
|
func (c *container) setStatus(status plugin.Status) {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
c.status = status
|
c.status = status
|
||||||
c.Unlock()
|
c.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *container) getStatus() containerd.Status {
|
func (c *container) getStatus() plugin.Status {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
return c.status
|
return c.status
|
||||||
|
@ -15,8 +15,8 @@ import (
|
|||||||
|
|
||||||
"github.com/Microsoft/hcsshim"
|
"github.com/Microsoft/hcsshim"
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/containerd/containerd"
|
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/windows/pid"
|
"github.com/containerd/containerd/windows/pid"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -216,7 +216,7 @@ func (c *Container) CloseStdin(ctx context.Context, pid uint32) error {
|
|||||||
return proc.CloseStdin()
|
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
|
var proc *Process
|
||||||
c.Lock()
|
c.Lock()
|
||||||
for _, p := range c.processes {
|
for _, p := range c.processes {
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Microsoft/hcsshim"
|
"github.com/Microsoft/hcsshim"
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,14 +35,14 @@ func (p *Process) ExitedAt() time.Time {
|
|||||||
return p.exitedAt
|
return p.exitedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Status() containerd.Status {
|
func (p *Process) Status() plugin.Status {
|
||||||
select {
|
select {
|
||||||
case <-p.ecSync:
|
case <-p.ecSync:
|
||||||
return containerd.StoppedStatus
|
return plugin.StoppedStatus
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
return containerd.RunningStatus
|
return plugin.RunningStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Delete() error {
|
func (p *Process) Delete() error {
|
||||||
|
@ -3,9 +3,10 @@
|
|||||||
package windows
|
package windows
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containerd/containerd"
|
"context"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/windows/hcs"
|
"github.com/containerd/containerd/windows/hcs"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// process implements containerd.Process and containerd.State
|
// process implements containerd.Process and containerd.State
|
||||||
@ -13,7 +14,7 @@ type process struct {
|
|||||||
*hcs.Process
|
*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
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ func (p *process) Kill(ctx context.Context, sig uint32, all bool) error {
|
|||||||
return p.Process.Kill()
|
return p.Process.Kill()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *process) Status() containerd.Status {
|
func (p *process) Status() plugin.Status {
|
||||||
return p.Process.Status()
|
return p.Process.Status()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
package windows
|
package windows
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -17,8 +18,6 @@ import (
|
|||||||
"github.com/containerd/containerd/windows/pid"
|
"github.com/containerd/containerd/windows/pid"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -26,7 +25,7 @@ const (
|
|||||||
owner = "containerd"
|
owner = "containerd"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = (containerd.Runtime)(&Runtime{})
|
var _ = (plugin.Runtime)(&Runtime{})
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
plugin.Register(runtimeName, &plugin.Registration{
|
plugin.Register(runtimeName, &plugin.Registration{
|
||||||
@ -36,13 +35,13 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(ic *plugin.InitContext) (interface{}, error) {
|
func New(ic *plugin.InitContext) (interface{}, error) {
|
||||||
c, cancel := context.WithCancel(ic.Context)
|
|
||||||
|
|
||||||
rootDir := filepath.Join(ic.Root, runtimeName)
|
rootDir := filepath.Join(ic.Root, runtimeName)
|
||||||
if err := os.MkdirAll(rootDir, 0755); err != nil {
|
if err := os.MkdirAll(rootDir, 0755); err != nil {
|
||||||
return nil, errors.Wrapf(err, "could not create state directory at %s", rootDir)
|
return nil, errors.Wrapf(err, "could not create state directory at %s", rootDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c, cancel := context.WithCancel(ic.Context)
|
||||||
r := &Runtime{
|
r := &Runtime{
|
||||||
pidPool: pid.NewPool(),
|
pidPool: pid.NewPool(),
|
||||||
containers: make(map[string]*container),
|
containers: make(map[string]*container),
|
||||||
@ -102,7 +101,7 @@ type RuntimeSpec struct {
|
|||||||
hcs.Configuration
|
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
|
var rtSpec RuntimeSpec
|
||||||
if err := json.Unmarshal(opts.Spec, &rtSpec); err != nil {
|
if err := json.Unmarshal(opts.Spec, &rtSpec); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to unmarshal oci spec")
|
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
|
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)
|
wc, ok := c.(*container)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("container cannot be cast as *windows.container")
|
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())
|
delete(r.containers, wc.ctr.ID())
|
||||||
r.Unlock()
|
r.Unlock()
|
||||||
|
|
||||||
return &containerd.Exit{
|
return &plugin.Exit{
|
||||||
Status: ec,
|
Status: ec,
|
||||||
Timestamp: wc.ctr.Processes()[0].ExitedAt(),
|
Timestamp: wc.ctr.Processes()[0].ExitedAt(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runtime) Containers(ctx context.Context) ([]containerd.Container, error) {
|
func (r *Runtime) Containers(ctx context.Context) ([]plugin.Container, error) {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
list := make([]containerd.Container, len(r.containers))
|
list := make([]plugin.Container, len(r.containers))
|
||||||
for _, c := range r.containers {
|
for _, c := range r.containers {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
Loading…
Reference in New Issue
Block a user