(ctx context.Context, ioCreate cio.Creator, rootDir string)
| 367 | } |
| 368 | |
| 369 | func (c *container) Restore(ctx context.Context, ioCreate cio.Creator, rootDir string) (_ int, retErr error) { |
| 370 | errorPid := -1 |
| 371 | i, err := ioCreate(c.id) |
| 372 | if err != nil { |
| 373 | return errorPid, err |
| 374 | } |
| 375 | defer func() { |
| 376 | if retErr != nil && i != nil { |
| 377 | i.Cancel() |
| 378 | i.Close() |
| 379 | } |
| 380 | }() |
| 381 | cfg := i.Config() |
| 382 | |
| 383 | request := &tasks.CreateTaskRequest{ |
| 384 | ContainerID: c.id, |
| 385 | Terminal: cfg.Terminal, |
| 386 | Stdin: cfg.Stdin, |
| 387 | Stdout: cfg.Stdout, |
| 388 | Stderr: cfg.Stderr, |
| 389 | } |
| 390 | |
| 391 | if err := c.handleMounts(ctx, request); err != nil { |
| 392 | return errorPid, err |
| 393 | } |
| 394 | |
| 395 | request.Checkpoint = &types.Descriptor{ |
| 396 | Annotations: map[string]string{ |
| 397 | // The following annotation is used to restore a checkpoint |
| 398 | // via CRI. This is mainly used to restore a container |
| 399 | // in Kubernetes. |
| 400 | "RestoreFromPath": rootDir, |
| 401 | }, |
| 402 | } |
| 403 | // (adrianreber): it is not totally clear to me, but it seems the only |
| 404 | // way to restore a container in containerd is going through Create(). |
| 405 | // This functions sets up Create() in such a way to handle container |
| 406 | // restore coming through the CRI. |
| 407 | response, err := c.client.TaskService().Create(ctx, request) |
| 408 | if err != nil { |
| 409 | return errorPid, errgrpc.ToNative(err) |
| 410 | } |
| 411 | |
| 412 | return int(response.GetPid()), nil |
| 413 | } |
| 414 | |
| 415 | func (c *container) Checkpoint(ctx context.Context, ref string, opts ...CheckpointOpts) (Image, error) { |
| 416 | index := &ocispec.Index{ |
nothing calls this directly
no test coverage detected