mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove libcontainerd status type
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
dbe4a30928
commit
45e328b0ac
7 changed files with 29 additions and 49 deletions
|
@ -357,11 +357,11 @@ func (daemon *Daemon) restore() error {
|
||||||
logrus.WithField("container", c.ID).WithField("state", s).
|
logrus.WithField("container", c.ID).WithField("state", s).
|
||||||
Info("restored container paused")
|
Info("restored container paused")
|
||||||
switch s {
|
switch s {
|
||||||
case libcontainerdtypes.StatusPaused, libcontainerdtypes.StatusPausing:
|
case containerd.Paused, containerd.Pausing:
|
||||||
// nothing to do
|
// nothing to do
|
||||||
case libcontainerdtypes.StatusStopped:
|
case containerd.Stopped:
|
||||||
alive = false
|
alive = false
|
||||||
case libcontainerdtypes.StatusUnknown:
|
case containerd.Unknown:
|
||||||
logrus.WithField("container", c.ID).
|
logrus.WithField("container", c.ID).
|
||||||
Error("Unknown status for container during restore")
|
Error("Unknown status for container during restore")
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -54,7 +54,7 @@ func (c *MockContainerdClient) DeleteTask(ctx context.Context, containerID strin
|
||||||
return 0, time.Time{}, nil
|
return 0, time.Time{}, nil
|
||||||
}
|
}
|
||||||
func (c *MockContainerdClient) Delete(ctx context.Context, containerID string) error { return nil }
|
func (c *MockContainerdClient) Delete(ctx context.Context, containerID string) error { return nil }
|
||||||
func (c *MockContainerdClient) Status(ctx context.Context, containerID string) (libcontainerdtypes.Status, error) {
|
func (c *MockContainerdClient) Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error) {
|
||||||
return "null", nil
|
return "null", nil
|
||||||
}
|
}
|
||||||
func (c *MockContainerdClient) UpdateResources(ctx context.Context, containerID string, resources *libcontainerdtypes.Resources) error {
|
func (c *MockContainerdClient) UpdateResources(ctx context.Context, containerID string, resources *libcontainerdtypes.Resources) error {
|
||||||
|
|
|
@ -51,7 +51,7 @@ type container struct {
|
||||||
hcsContainer hcsshim.Container
|
hcsContainer hcsshim.Container
|
||||||
|
|
||||||
id string
|
id string
|
||||||
status libcontainerdtypes.Status
|
status containerd.ProcessStatus
|
||||||
exitedAt time.Time
|
exitedAt time.Time
|
||||||
exitCode uint32
|
exitCode uint32
|
||||||
waitCh chan struct{}
|
waitCh chan struct{}
|
||||||
|
@ -348,7 +348,7 @@ func (c *client) createWindows(id string, spec *specs.Spec, runtimeOptions inter
|
||||||
isWindows: true,
|
isWindows: true,
|
||||||
ociSpec: spec,
|
ociSpec: spec,
|
||||||
hcsContainer: hcsContainer,
|
hcsContainer: hcsContainer,
|
||||||
status: libcontainerdtypes.StatusCreated,
|
status: containerd.Created,
|
||||||
waitCh: make(chan struct{}),
|
waitCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,7 +543,7 @@ func (c *client) createLinux(id string, spec *specs.Spec, runtimeOptions interfa
|
||||||
isWindows: false,
|
isWindows: false,
|
||||||
ociSpec: spec,
|
ociSpec: spec,
|
||||||
hcsContainer: hcsContainer,
|
hcsContainer: hcsContainer,
|
||||||
status: libcontainerdtypes.StatusCreated,
|
status: containerd.Created,
|
||||||
waitCh: make(chan struct{}),
|
waitCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -709,7 +709,7 @@ func (c *client) Start(_ context.Context, id, _ string, withStdin bool, attachSt
|
||||||
}
|
}
|
||||||
logger.WithField("pid", p.pid).Debug("init process started")
|
logger.WithField("pid", p.pid).Debug("init process started")
|
||||||
|
|
||||||
ctr.status = libcontainerdtypes.StatusRunning
|
ctr.status = containerd.Running
|
||||||
ctr.init = p
|
ctr.init = p
|
||||||
|
|
||||||
// Spin up a go routine waiting for exit to handle cleanup
|
// Spin up a go routine waiting for exit to handle cleanup
|
||||||
|
@ -1004,7 +1004,7 @@ func (c *client) Pause(_ context.Context, containerID string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctr.status = libcontainerdtypes.StatusPaused
|
ctr.status = containerd.Paused
|
||||||
|
|
||||||
c.eventQ.Append(containerID, func() {
|
c.eventQ.Append(containerID, func() {
|
||||||
err := c.backend.ProcessEvent(containerID, libcontainerdtypes.EventPaused, libcontainerdtypes.EventInfo{
|
err := c.backend.ProcessEvent(containerID, libcontainerdtypes.EventPaused, libcontainerdtypes.EventInfo{
|
||||||
|
@ -1044,7 +1044,7 @@ func (c *client) Resume(_ context.Context, containerID string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctr.status = libcontainerdtypes.StatusRunning
|
ctr.status = containerd.Running
|
||||||
|
|
||||||
c.eventQ.Append(containerID, func() {
|
c.eventQ.Append(containerID, func() {
|
||||||
err := c.backend.ProcessEvent(containerID, libcontainerdtypes.EventResumed, libcontainerdtypes.EventInfo{
|
err := c.backend.ProcessEvent(containerID, libcontainerdtypes.EventResumed, libcontainerdtypes.EventInfo{
|
||||||
|
@ -1185,12 +1185,12 @@ func (c *client) Delete(_ context.Context, containerID string) error {
|
||||||
defer ctr.Unlock()
|
defer ctr.Unlock()
|
||||||
|
|
||||||
switch ctr.status {
|
switch ctr.status {
|
||||||
case libcontainerdtypes.StatusCreated:
|
case containerd.Created:
|
||||||
if err := c.shutdownContainer(ctr); err != nil {
|
if err := c.shutdownContainer(ctr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
case libcontainerdtypes.StatusStopped:
|
case containerd.Stopped:
|
||||||
delete(c.containers, containerID)
|
delete(c.containers, containerID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1198,12 +1198,12 @@ func (c *client) Delete(_ context.Context, containerID string) error {
|
||||||
return errors.WithStack(errdefs.InvalidParameter(errors.New("container is not stopped")))
|
return errors.WithStack(errdefs.InvalidParameter(errors.New("container is not stopped")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) Status(ctx context.Context, containerID string) (libcontainerdtypes.Status, error) {
|
func (c *client) Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error) {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
ctr := c.containers[containerID]
|
ctr := c.containers[containerID]
|
||||||
if ctr == nil {
|
if ctr == nil {
|
||||||
return libcontainerdtypes.StatusUnknown, errors.WithStack(errdefs.NotFound(errors.New("no such container")))
|
return containerd.Unknown, errors.WithStack(errdefs.NotFound(errors.New("no such container")))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctr.Lock()
|
ctr.Lock()
|
||||||
|
@ -1387,7 +1387,7 @@ func (c *client) reapProcess(ctr *container, p *process) int {
|
||||||
func (c *client) reapContainer(ctr *container, p *process, exitCode int, exitedAt time.Time, eventErr error, logger *logrus.Entry) (int, error) {
|
func (c *client) reapContainer(ctr *container, p *process, exitCode int, exitedAt time.Time, eventErr error, logger *logrus.Entry) (int, error) {
|
||||||
// Update container status
|
// Update container status
|
||||||
ctr.Lock()
|
ctr.Lock()
|
||||||
ctr.status = libcontainerdtypes.StatusStopped
|
ctr.status = containerd.Stopped
|
||||||
ctr.exitedAt = exitedAt
|
ctr.exitedAt = exitedAt
|
||||||
ctr.exitCode = uint32(exitCode)
|
ctr.exitCode = uint32(exitCode)
|
||||||
close(ctr.waitCh)
|
close(ctr.waitCh)
|
||||||
|
|
|
@ -550,23 +550,23 @@ func (c *client) Delete(ctx context.Context, containerID string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) Status(ctx context.Context, containerID string) (libcontainerdtypes.Status, error) {
|
func (c *client) Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error) {
|
||||||
ctr := c.getContainer(containerID)
|
ctr := c.getContainer(containerID)
|
||||||
if ctr == nil {
|
if ctr == nil {
|
||||||
return libcontainerdtypes.StatusUnknown, errors.WithStack(errdefs.NotFound(errors.New("no such container")))
|
return containerd.Unknown, errors.WithStack(errdefs.NotFound(errors.New("no such container")))
|
||||||
}
|
}
|
||||||
|
|
||||||
t := ctr.getTask()
|
t := ctr.getTask()
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return libcontainerdtypes.StatusUnknown, errors.WithStack(errdefs.NotFound(errors.New("no such task")))
|
return containerd.Unknown, errors.WithStack(errdefs.NotFound(errors.New("no such task")))
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := t.Status(ctx)
|
s, err := t.Status(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return libcontainerdtypes.StatusUnknown, wrapError(err)
|
return containerd.Unknown, wrapError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return libcontainerdtypes.Status(s.Status), nil
|
return s.Status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error {
|
func (c *client) CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error {
|
||||||
|
|
|
@ -25,27 +25,6 @@ const (
|
||||||
EventResumed EventType = "resumed"
|
EventResumed EventType = "resumed"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Status represents the current status of a container
|
|
||||||
type Status string
|
|
||||||
|
|
||||||
// Possible container statuses
|
|
||||||
const (
|
|
||||||
// Running indicates the process is currently executing
|
|
||||||
StatusRunning Status = "running"
|
|
||||||
// Created indicates the process has been created within containerd but the
|
|
||||||
// user's defined process has not started
|
|
||||||
StatusCreated Status = "created"
|
|
||||||
// Stopped indicates that the process has ran and exited
|
|
||||||
StatusStopped Status = "stopped"
|
|
||||||
// Paused indicates that the process is currently paused
|
|
||||||
StatusPaused Status = "paused"
|
|
||||||
// Pausing indicates that the process is currently switching from a
|
|
||||||
// running state into a paused state
|
|
||||||
StatusPausing Status = "pausing"
|
|
||||||
// Unknown indicates that we could not determine the status from the runtime
|
|
||||||
StatusUnknown Status = "unknown"
|
|
||||||
)
|
|
||||||
|
|
||||||
// EventInfo contains the event info
|
// EventInfo contains the event info
|
||||||
type EventInfo struct {
|
type EventInfo struct {
|
||||||
ContainerID string
|
ContainerID string
|
||||||
|
@ -81,7 +60,7 @@ type Client interface {
|
||||||
Summary(ctx context.Context, containerID string) ([]Summary, error)
|
Summary(ctx context.Context, containerID string) ([]Summary, error)
|
||||||
DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
|
DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
|
||||||
Delete(ctx context.Context, containerID string) error
|
Delete(ctx context.Context, containerID string) error
|
||||||
Status(ctx context.Context, containerID string) (Status, error)
|
Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error)
|
||||||
|
|
||||||
UpdateResources(ctx context.Context, containerID string, resources *Resources) error
|
UpdateResources(ctx context.Context, containerID string, resources *Resources) error
|
||||||
CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error
|
CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error
|
||||||
|
|
|
@ -32,7 +32,7 @@ type ExitHandler interface {
|
||||||
type Client interface {
|
type Client interface {
|
||||||
Create(ctx context.Context, containerID string, spec *specs.Spec, runtimeOptions interface{}) error
|
Create(ctx context.Context, containerID string, spec *specs.Spec, runtimeOptions interface{}) error
|
||||||
Restore(ctx context.Context, containerID string, attachStdio libcontainerdtypes.StdioCallback) (alive bool, pid int, err error)
|
Restore(ctx context.Context, containerID string, attachStdio libcontainerdtypes.StdioCallback) (alive bool, pid int, err error)
|
||||||
Status(ctx context.Context, containerID string) (libcontainerdtypes.Status, error)
|
Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error)
|
||||||
Delete(ctx context.Context, containerID string) error
|
Delete(ctx context.Context, containerID string) error
|
||||||
DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
|
DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
|
||||||
Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (pid int, err error)
|
Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (pid int, err error)
|
||||||
|
@ -88,7 +88,7 @@ func (e *Executor) Create(id string, spec specs.Spec, stdout, stderr io.WriteClo
|
||||||
logrus.WithError(err2).WithField("id", id).Warn("Received an error while attempting to read plugin status")
|
logrus.WithError(err2).WithField("id", id).Warn("Received an error while attempting to read plugin status")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if status != libcontainerdtypes.StatusRunning && status != libcontainerdtypes.StatusUnknown {
|
if status != containerd.Running && status != containerd.Unknown {
|
||||||
if err2 := e.client.Delete(ctx, id); err2 != nil && !errdefs.IsNotFound(err2) {
|
if err2 := e.client.Delete(ctx, id); err2 != nil && !errdefs.IsNotFound(err2) {
|
||||||
logrus.WithError(err2).WithField("plugin", id).Error("Error cleaning up containerd container")
|
logrus.WithError(err2).WithField("plugin", id).Error("Error cleaning up containerd container")
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ func (e *Executor) Restore(id string, stdout, stderr io.WriteCloser) (bool, erro
|
||||||
// IsRunning returns if the container with the given id is running
|
// IsRunning returns if the container with the given id is running
|
||||||
func (e *Executor) IsRunning(id string) (bool, error) {
|
func (e *Executor) IsRunning(id string) (bool, error) {
|
||||||
status, err := e.client.Status(context.Background(), id)
|
status, err := e.client.Status(context.Background(), id)
|
||||||
return status == libcontainerdtypes.StatusRunning, err
|
return status == containerd.Running, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal sends the specified signal to the container
|
// Signal sends the specified signal to the container
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd"
|
||||||
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -86,18 +87,18 @@ func (c *mockClient) Restore(ctx context.Context, id string, attachStdio libcont
|
||||||
return false, 0, nil
|
return false, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockClient) Status(ctx context.Context, id string) (libcontainerdtypes.Status, error) {
|
func (c *mockClient) Status(ctx context.Context, id string) (containerd.ProcessStatus, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
running, ok := c.containers[id]
|
running, ok := c.containers[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
return libcontainerdtypes.StatusUnknown, errors.New("not found")
|
return containerd.Unknown, errors.New("not found")
|
||||||
}
|
}
|
||||||
if running {
|
if running {
|
||||||
return libcontainerdtypes.StatusRunning, nil
|
return containerd.Running, nil
|
||||||
}
|
}
|
||||||
return libcontainerdtypes.StatusStopped, nil
|
return containerd.Stopped, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockClient) Delete(ctx context.Context, id string) error {
|
func (c *mockClient) Delete(ctx context.Context, id string) error {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue