Merge pull request #39002 from crosbymichael/remove-status

Remove libcontainerd status type
This commit is contained in:
Sebastiaan van Stijn 2019-04-05 02:20:52 +02:00 committed by GitHub
commit 9819f9ef47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 49 deletions

View file

@ -357,11 +357,11 @@ func (daemon *Daemon) restore() error {
logrus.WithField("container", c.ID).WithField("state", s).
Info("restored container paused")
switch s {
case libcontainerdtypes.StatusPaused, libcontainerdtypes.StatusPausing:
case containerd.Paused, containerd.Pausing:
// nothing to do
case libcontainerdtypes.StatusStopped:
case containerd.Stopped:
alive = false
case libcontainerdtypes.StatusUnknown:
case containerd.Unknown:
logrus.WithField("container", c.ID).
Error("Unknown status for container during restore")
default:

View file

@ -54,7 +54,7 @@ func (c *MockContainerdClient) DeleteTask(ctx context.Context, containerID strin
return 0, time.Time{}, 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
}
func (c *MockContainerdClient) UpdateResources(ctx context.Context, containerID string, resources *libcontainerdtypes.Resources) error {

View file

@ -51,7 +51,7 @@ type container struct {
hcsContainer hcsshim.Container
id string
status libcontainerdtypes.Status
status containerd.ProcessStatus
exitedAt time.Time
exitCode uint32
waitCh chan struct{}
@ -348,7 +348,7 @@ func (c *client) createWindows(id string, spec *specs.Spec, runtimeOptions inter
isWindows: true,
ociSpec: spec,
hcsContainer: hcsContainer,
status: libcontainerdtypes.StatusCreated,
status: containerd.Created,
waitCh: make(chan struct{}),
}
@ -543,7 +543,7 @@ func (c *client) createLinux(id string, spec *specs.Spec, runtimeOptions interfa
isWindows: false,
ociSpec: spec,
hcsContainer: hcsContainer,
status: libcontainerdtypes.StatusCreated,
status: containerd.Created,
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")
ctr.status = libcontainerdtypes.StatusRunning
ctr.status = containerd.Running
ctr.init = p
// 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
}
ctr.status = libcontainerdtypes.StatusPaused
ctr.status = containerd.Paused
c.eventQ.Append(containerID, func() {
err := c.backend.ProcessEvent(containerID, libcontainerdtypes.EventPaused, libcontainerdtypes.EventInfo{
@ -1044,7 +1044,7 @@ func (c *client) Resume(_ context.Context, containerID string) error {
return err
}
ctr.status = libcontainerdtypes.StatusRunning
ctr.status = containerd.Running
c.eventQ.Append(containerID, func() {
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()
switch ctr.status {
case libcontainerdtypes.StatusCreated:
case containerd.Created:
if err := c.shutdownContainer(ctr); err != nil {
return err
}
fallthrough
case libcontainerdtypes.StatusStopped:
case containerd.Stopped:
delete(c.containers, containerID)
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")))
}
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()
defer c.Unlock()
ctr := c.containers[containerID]
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()
@ -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) {
// Update container status
ctr.Lock()
ctr.status = libcontainerdtypes.StatusStopped
ctr.status = containerd.Stopped
ctr.exitedAt = exitedAt
ctr.exitCode = uint32(exitCode)
close(ctr.waitCh)

View file

@ -550,23 +550,23 @@ func (c *client) Delete(ctx context.Context, containerID string) error {
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)
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()
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)
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 {

View file

@ -25,27 +25,6 @@ const (
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
type EventInfo struct {
ContainerID string
@ -81,7 +60,7 @@ type Client interface {
Summary(ctx context.Context, containerID string) ([]Summary, error)
DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, 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
CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error

View file

@ -32,7 +32,7 @@ type ExitHandler interface {
type Client interface {
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)
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
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)
@ -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")
}
} 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) {
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
func (e *Executor) IsRunning(id string) (bool, error) {
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

View file

@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/containerd/containerd"
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
@ -86,18 +87,18 @@ func (c *mockClient) Restore(ctx context.Context, id string, attachStdio libcont
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()
defer c.mu.Unlock()
running, ok := c.containers[id]
if !ok {
return libcontainerdtypes.StatusUnknown, errors.New("not found")
return containerd.Unknown, errors.New("not found")
}
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 {