Browse code

Remove libcontainerd status type

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Michael Crosby authored on 2019/04/05 03:46:02
Showing 7 changed files
... ...
@@ -357,11 +357,11 @@ func (daemon *Daemon) restore() error {
357 357
 						logrus.WithField("container", c.ID).WithField("state", s).
358 358
 							Info("restored container paused")
359 359
 						switch s {
360
-						case libcontainerdtypes.StatusPaused, libcontainerdtypes.StatusPausing:
360
+						case containerd.Paused, containerd.Pausing:
361 361
 							// nothing to do
362
-						case libcontainerdtypes.StatusStopped:
362
+						case containerd.Stopped:
363 363
 							alive = false
364
-						case libcontainerdtypes.StatusUnknown:
364
+						case containerd.Unknown:
365 365
 							logrus.WithField("container", c.ID).
366 366
 								Error("Unknown status for container during restore")
367 367
 						default:
... ...
@@ -54,7 +54,7 @@ func (c *MockContainerdClient) DeleteTask(ctx context.Context, containerID strin
54 54
 	return 0, time.Time{}, nil
55 55
 }
56 56
 func (c *MockContainerdClient) Delete(ctx context.Context, containerID string) error { return nil }
57
-func (c *MockContainerdClient) Status(ctx context.Context, containerID string) (libcontainerdtypes.Status, error) {
57
+func (c *MockContainerdClient) Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error) {
58 58
 	return "null", nil
59 59
 }
60 60
 func (c *MockContainerdClient) UpdateResources(ctx context.Context, containerID string, resources *libcontainerdtypes.Resources) error {
... ...
@@ -51,7 +51,7 @@ type container struct {
51 51
 	hcsContainer hcsshim.Container
52 52
 
53 53
 	id               string
54
-	status           libcontainerdtypes.Status
54
+	status           containerd.ProcessStatus
55 55
 	exitedAt         time.Time
56 56
 	exitCode         uint32
57 57
 	waitCh           chan struct{}
... ...
@@ -348,7 +348,7 @@ func (c *client) createWindows(id string, spec *specs.Spec, runtimeOptions inter
348 348
 		isWindows:    true,
349 349
 		ociSpec:      spec,
350 350
 		hcsContainer: hcsContainer,
351
-		status:       libcontainerdtypes.StatusCreated,
351
+		status:       containerd.Created,
352 352
 		waitCh:       make(chan struct{}),
353 353
 	}
354 354
 
... ...
@@ -543,7 +543,7 @@ func (c *client) createLinux(id string, spec *specs.Spec, runtimeOptions interfa
543 543
 		isWindows:    false,
544 544
 		ociSpec:      spec,
545 545
 		hcsContainer: hcsContainer,
546
-		status:       libcontainerdtypes.StatusCreated,
546
+		status:       containerd.Created,
547 547
 		waitCh:       make(chan struct{}),
548 548
 	}
549 549
 
... ...
@@ -709,7 +709,7 @@ func (c *client) Start(_ context.Context, id, _ string, withStdin bool, attachSt
709 709
 	}
710 710
 	logger.WithField("pid", p.pid).Debug("init process started")
711 711
 
712
-	ctr.status = libcontainerdtypes.StatusRunning
712
+	ctr.status = containerd.Running
713 713
 	ctr.init = p
714 714
 
715 715
 	// Spin up a go routine waiting for exit to handle cleanup
... ...
@@ -1004,7 +1004,7 @@ func (c *client) Pause(_ context.Context, containerID string) error {
1004 1004
 		return err
1005 1005
 	}
1006 1006
 
1007
-	ctr.status = libcontainerdtypes.StatusPaused
1007
+	ctr.status = containerd.Paused
1008 1008
 
1009 1009
 	c.eventQ.Append(containerID, func() {
1010 1010
 		err := c.backend.ProcessEvent(containerID, libcontainerdtypes.EventPaused, libcontainerdtypes.EventInfo{
... ...
@@ -1044,7 +1044,7 @@ func (c *client) Resume(_ context.Context, containerID string) error {
1044 1044
 		return err
1045 1045
 	}
1046 1046
 
1047
-	ctr.status = libcontainerdtypes.StatusRunning
1047
+	ctr.status = containerd.Running
1048 1048
 
1049 1049
 	c.eventQ.Append(containerID, func() {
1050 1050
 		err := c.backend.ProcessEvent(containerID, libcontainerdtypes.EventResumed, libcontainerdtypes.EventInfo{
... ...
@@ -1185,12 +1185,12 @@ func (c *client) Delete(_ context.Context, containerID string) error {
1185 1185
 	defer ctr.Unlock()
1186 1186
 
1187 1187
 	switch ctr.status {
1188
-	case libcontainerdtypes.StatusCreated:
1188
+	case containerd.Created:
1189 1189
 		if err := c.shutdownContainer(ctr); err != nil {
1190 1190
 			return err
1191 1191
 		}
1192 1192
 		fallthrough
1193
-	case libcontainerdtypes.StatusStopped:
1193
+	case containerd.Stopped:
1194 1194
 		delete(c.containers, containerID)
1195 1195
 		return nil
1196 1196
 	}
... ...
@@ -1198,12 +1198,12 @@ func (c *client) Delete(_ context.Context, containerID string) error {
1198 1198
 	return errors.WithStack(errdefs.InvalidParameter(errors.New("container is not stopped")))
1199 1199
 }
1200 1200
 
1201
-func (c *client) Status(ctx context.Context, containerID string) (libcontainerdtypes.Status, error) {
1201
+func (c *client) Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error) {
1202 1202
 	c.Lock()
1203 1203
 	defer c.Unlock()
1204 1204
 	ctr := c.containers[containerID]
1205 1205
 	if ctr == nil {
1206
-		return libcontainerdtypes.StatusUnknown, errors.WithStack(errdefs.NotFound(errors.New("no such container")))
1206
+		return containerd.Unknown, errors.WithStack(errdefs.NotFound(errors.New("no such container")))
1207 1207
 	}
1208 1208
 
1209 1209
 	ctr.Lock()
... ...
@@ -1387,7 +1387,7 @@ func (c *client) reapProcess(ctr *container, p *process) int {
1387 1387
 func (c *client) reapContainer(ctr *container, p *process, exitCode int, exitedAt time.Time, eventErr error, logger *logrus.Entry) (int, error) {
1388 1388
 	// Update container status
1389 1389
 	ctr.Lock()
1390
-	ctr.status = libcontainerdtypes.StatusStopped
1390
+	ctr.status = containerd.Stopped
1391 1391
 	ctr.exitedAt = exitedAt
1392 1392
 	ctr.exitCode = uint32(exitCode)
1393 1393
 	close(ctr.waitCh)
... ...
@@ -550,23 +550,23 @@ func (c *client) Delete(ctx context.Context, containerID string) error {
550 550
 	return nil
551 551
 }
552 552
 
553
-func (c *client) Status(ctx context.Context, containerID string) (libcontainerdtypes.Status, error) {
553
+func (c *client) Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error) {
554 554
 	ctr := c.getContainer(containerID)
555 555
 	if ctr == nil {
556
-		return libcontainerdtypes.StatusUnknown, errors.WithStack(errdefs.NotFound(errors.New("no such container")))
556
+		return containerd.Unknown, errors.WithStack(errdefs.NotFound(errors.New("no such container")))
557 557
 	}
558 558
 
559 559
 	t := ctr.getTask()
560 560
 	if t == nil {
561
-		return libcontainerdtypes.StatusUnknown, errors.WithStack(errdefs.NotFound(errors.New("no such task")))
561
+		return containerd.Unknown, errors.WithStack(errdefs.NotFound(errors.New("no such task")))
562 562
 	}
563 563
 
564 564
 	s, err := t.Status(ctx)
565 565
 	if err != nil {
566
-		return libcontainerdtypes.StatusUnknown, wrapError(err)
566
+		return containerd.Unknown, wrapError(err)
567 567
 	}
568 568
 
569
-	return libcontainerdtypes.Status(s.Status), nil
569
+	return s.Status, nil
570 570
 }
571 571
 
572 572
 func (c *client) CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error {
... ...
@@ -25,27 +25,6 @@ const (
25 25
 	EventResumed     EventType = "resumed"
26 26
 )
27 27
 
28
-// Status represents the current status of a container
29
-type Status string
30
-
31
-// Possible container statuses
32
-const (
33
-	// Running indicates the process is currently executing
34
-	StatusRunning Status = "running"
35
-	// Created indicates the process has been created within containerd but the
36
-	// user's defined process has not started
37
-	StatusCreated Status = "created"
38
-	// Stopped indicates that the process has ran and exited
39
-	StatusStopped Status = "stopped"
40
-	// Paused indicates that the process is currently paused
41
-	StatusPaused Status = "paused"
42
-	// Pausing indicates that the process is currently switching from a
43
-	// running state into a paused state
44
-	StatusPausing Status = "pausing"
45
-	// Unknown indicates that we could not determine the status from the runtime
46
-	StatusUnknown Status = "unknown"
47
-)
48
-
49 28
 // EventInfo contains the event info
50 29
 type EventInfo struct {
51 30
 	ContainerID string
... ...
@@ -81,7 +60,7 @@ type Client interface {
81 81
 	Summary(ctx context.Context, containerID string) ([]Summary, error)
82 82
 	DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
83 83
 	Delete(ctx context.Context, containerID string) error
84
-	Status(ctx context.Context, containerID string) (Status, error)
84
+	Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error)
85 85
 
86 86
 	UpdateResources(ctx context.Context, containerID string, resources *Resources) error
87 87
 	CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error
... ...
@@ -32,7 +32,7 @@ type ExitHandler interface {
32 32
 type Client interface {
33 33
 	Create(ctx context.Context, containerID string, spec *specs.Spec, runtimeOptions interface{}) error
34 34
 	Restore(ctx context.Context, containerID string, attachStdio libcontainerdtypes.StdioCallback) (alive bool, pid int, err error)
35
-	Status(ctx context.Context, containerID string) (libcontainerdtypes.Status, error)
35
+	Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error)
36 36
 	Delete(ctx context.Context, containerID string) error
37 37
 	DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
38 38
 	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
88 88
 				logrus.WithError(err2).WithField("id", id).Warn("Received an error while attempting to read plugin status")
89 89
 			}
90 90
 		} else {
91
-			if status != libcontainerdtypes.StatusRunning && status != libcontainerdtypes.StatusUnknown {
91
+			if status != containerd.Running && status != containerd.Unknown {
92 92
 				if err2 := e.client.Delete(ctx, id); err2 != nil && !errdefs.IsNotFound(err2) {
93 93
 					logrus.WithError(err2).WithField("plugin", id).Error("Error cleaning up containerd container")
94 94
 				}
... ...
@@ -123,7 +123,7 @@ func (e *Executor) Restore(id string, stdout, stderr io.WriteCloser) (bool, erro
123 123
 // IsRunning returns if the container with the given id is running
124 124
 func (e *Executor) IsRunning(id string) (bool, error) {
125 125
 	status, err := e.client.Status(context.Background(), id)
126
-	return status == libcontainerdtypes.StatusRunning, err
126
+	return status == containerd.Running, err
127 127
 }
128 128
 
129 129
 // Signal sends the specified signal to the container
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"testing"
9 9
 	"time"
10 10
 
11
+	"github.com/containerd/containerd"
11 12
 	libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
12 13
 	"github.com/opencontainers/runtime-spec/specs-go"
13 14
 	"github.com/pkg/errors"
... ...
@@ -86,18 +87,18 @@ func (c *mockClient) Restore(ctx context.Context, id string, attachStdio libcont
86 86
 	return false, 0, nil
87 87
 }
88 88
 
89
-func (c *mockClient) Status(ctx context.Context, id string) (libcontainerdtypes.Status, error) {
89
+func (c *mockClient) Status(ctx context.Context, id string) (containerd.ProcessStatus, error) {
90 90
 	c.mu.Lock()
91 91
 	defer c.mu.Unlock()
92 92
 
93 93
 	running, ok := c.containers[id]
94 94
 	if !ok {
95
-		return libcontainerdtypes.StatusUnknown, errors.New("not found")
95
+		return containerd.Unknown, errors.New("not found")
96 96
 	}
97 97
 	if running {
98
-		return libcontainerdtypes.StatusRunning, nil
98
+		return containerd.Running, nil
99 99
 	}
100
-	return libcontainerdtypes.StatusStopped, nil
100
+	return containerd.Stopped, nil
101 101
 }
102 102
 
103 103
 func (c *mockClient) Delete(ctx context.Context, id string) error {