Skip to content

Commit b9b5dc3

Browse files
committed
Remove inmemory container map
Signed-off-by: Michael Crosby <[email protected]>
1 parent adb15c2 commit b9b5dc3

9 files changed

Lines changed: 211 additions & 410 deletions

File tree

daemon/daemon.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,17 @@ func (daemon *Daemon) restore() error {
325325
alive bool
326326
ec uint32
327327
exitedAt time.Time
328+
process libcontainerdtypes.Process
328329
)
329330

330-
alive, _, err = daemon.containerd.Restore(context.Background(), c.ID, c.InitializeStdio)
331+
alive, _, process, err = daemon.containerd.Restore(context.Background(), c.ID, c.InitializeStdio)
331332
if err != nil && !errdefs.IsNotFound(err) {
332333
logrus.Errorf("Failed to restore container %s with containerd: %s", c.ID, err)
333334
return
334335
}
335-
if !alive {
336-
ec, exitedAt, err = daemon.containerd.DeleteTask(context.Background(), c.ID)
337-
if err != nil && !errdefs.IsNotFound(err) {
336+
if !alive && process != nil {
337+
ec, exitedAt, err = process.Delete(context.Background())
338+
if err != nil {
338339
logrus.WithError(err).Errorf("Failed to delete container %s from containerd", c.ID)
339340
return
340341
}

daemon/util_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ import (
1111
specs "github.com/opencontainers/runtime-spec/specs-go"
1212
)
1313

14+
type mockProcess struct {
15+
}
16+
17+
func (m *mockProcess) Delete(_ context.Context) (uint32, time.Time, error) {
18+
return 0, time.Time{}, nil
19+
}
20+
1421
// Mock containerd client implementation, for unit tests.
1522
type MockContainerdClient struct {
1623
}
1724

1825
func (c *MockContainerdClient) Version(ctx context.Context) (containerd.Version, error) {
1926
return containerd.Version{}, nil
2027
}
21-
func (c *MockContainerdClient) Restore(ctx context.Context, containerID string, attachStdio libcontainerdtypes.StdioCallback) (alive bool, pid int, err error) {
22-
return false, 0, nil
28+
func (c *MockContainerdClient) Restore(ctx context.Context, containerID string, attachStdio libcontainerdtypes.StdioCallback) (alive bool, pid int, p libcontainerdtypes.Process, err error) {
29+
return false, 0, &mockProcess{}, nil
2330
}
2431
func (c *MockContainerdClient) Create(ctx context.Context, containerID string, spec *specs.Spec, runtimeOptions interface{}) error {
2532
return nil

libcontainerd/local/local_windows.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ func (c *client) Stats(_ context.Context, containerID string) (*libcontainerdtyp
10851085
}
10861086

10871087
// Restore is the handler for restoring a container
1088-
func (c *client) Restore(ctx context.Context, id string, attachStdio libcontainerdtypes.StdioCallback) (bool, int, error) {
1088+
func (c *client) Restore(ctx context.Context, id string, attachStdio libcontainerdtypes.StdioCallback) (bool, int, libcontainerdtypes.Process, error) {
10891089
c.logger.WithField("container", id).Debug("restore()")
10901090

10911091
// TODO Windows: On RS1, a re-attach isn't possible.
@@ -1107,10 +1107,13 @@ func (c *client) Restore(ctx context.Context, id string, attachStdio libcontaine
11071107

11081108
if err != nil {
11091109
c.logger.WithField("container", id).WithError(err).Debug("terminate failed on restore")
1110-
return false, -1, err
1110+
return false, -1, nil, err
11111111
}
11121112
}
1113-
return false, -1, nil
1113+
return false, -1, &restoredProcess{
1114+
c: c,
1115+
id: id,
1116+
}, nil
11141117
}
11151118

11161119
// GetPidsForContainer returns a list of process IDs running in a container.
@@ -1153,6 +1156,15 @@ func (c *client) Summary(_ context.Context, containerID string) ([]libcontainerd
11531156
return pl, nil
11541157
}
11551158

1159+
type restoredProcess struct {
1160+
id string
1161+
c *client
1162+
}
1163+
1164+
func (p *restoredProcess) Delete(ctx context.Context) (uint32, time.Time, error) {
1165+
return p.c.DeleteTask(ctx, p.id)
1166+
}
1167+
11561168
func (c *client) DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error) {
11571169
ec := -1
11581170
ctr := c.getContainer(containerID)

0 commit comments

Comments
 (0)