Skip to content

Commit ca20431

Browse files
Merge pull request #2422 from crosbymichael/ctr-delete
Add cio.Load for loading io set
2 parents 08f7ee9 + fdceb13 commit ca20431

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

cio/io.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,14 @@ func (l *logIO) Wait() {
255255
func (l *logIO) Close() error {
256256
return nil
257257
}
258+
259+
// Load the io for a container but do not attach
260+
//
261+
// Allows io to be loaded on the task for deletion without
262+
// starting copy routines
263+
func Load(set *FIFOSet) (IO, error) {
264+
return &cio{
265+
config: set.Config,
266+
closers: []io.Closer{set},
267+
}, nil
268+
}

cmd/ctr/commands/containers/containers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"text/tabwriter"
2626

2727
"github.com/containerd/containerd"
28+
"github.com/containerd/containerd/cio"
2829
"github.com/containerd/containerd/cmd/ctr/commands"
2930
"github.com/containerd/containerd/cmd/ctr/commands/run"
3031
"github.com/containerd/containerd/log"
@@ -162,7 +163,6 @@ var deleteCommand = cli.Command{
162163
log.G(ctx).WithError(err).Errorf("failed to delete container %q", arg)
163164
}
164165
}
165-
166166
return exitErr
167167
},
168168
}
@@ -172,7 +172,7 @@ func deleteContainer(ctx context.Context, client *containerd.Client, id string,
172172
if err != nil {
173173
return err
174174
}
175-
task, err := container.Task(ctx, nil)
175+
task, err := container.Task(ctx, cio.Load)
176176
if err != nil {
177177
return container.Delete(ctx, opts...)
178178
}

cmd/ctr/commands/tasks/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package tasks
1818

1919
import (
2020
"github.com/containerd/containerd"
21+
"github.com/containerd/containerd/cio"
2122
"github.com/containerd/containerd/cmd/ctr/commands"
2223
"github.com/urfave/cli"
2324
)
@@ -42,8 +43,7 @@ var deleteCommand = cli.Command{
4243
if err != nil {
4344
return err
4445
}
45-
46-
task, err := container.Task(ctx, nil)
46+
task, err := container.Task(ctx, cio.Load)
4747
if err != nil {
4848
return err
4949
}

container.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ func (c *container) get(ctx context.Context) (containers.Container, error) {
307307

308308
// get the existing fifo paths from the task information stored by the daemon
309309
func attachExistingIO(response *tasks.GetResponse, ioAttach cio.Attach) (cio.IO, error) {
310+
fifoSet := loadFifos(response)
311+
return ioAttach(fifoSet)
312+
}
313+
314+
// loadFifos loads the containers fifos
315+
func loadFifos(response *tasks.GetResponse) *cio.FIFOSet {
310316
path := getFifoDir([]string{
311317
response.Process.Stdin,
312318
response.Process.Stdout,
@@ -315,13 +321,12 @@ func attachExistingIO(response *tasks.GetResponse, ioAttach cio.Attach) (cio.IO,
315321
closer := func() error {
316322
return os.RemoveAll(path)
317323
}
318-
fifoSet := cio.NewFIFOSet(cio.Config{
324+
return cio.NewFIFOSet(cio.Config{
319325
Stdin: response.Process.Stdin,
320326
Stdout: response.Process.Stdout,
321327
Stderr: response.Process.Stderr,
322328
Terminal: response.Process.Terminal,
323329
}, closer)
324-
return ioAttach(fifoSet)
325330
}
326331

327332
// getFifoDir looks for any non-empty path for a stdio fifo

0 commit comments

Comments
 (0)