MCPcopy
hub / github.com/containerd/containerd / Restore

Method Restore

client/container.go:369–413  ·  view source on GitHub ↗
(ctx context.Context, ioCreate cio.Creator, rootDir string)

Source from the content-addressed store, hash-verified

367}
368
369func (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
415func (c *container) Checkpoint(ctx context.Context, ref string, opts ...CheckpointOpts) (Image, error) {
416 index := &ocispec.Index{

Callers

nothing calls this directly

Calls 7

handleMountsMethod · 0.95
TaskServiceMethod · 0.80
CancelMethod · 0.65
CloseMethod · 0.65
ConfigMethod · 0.65
CreateMethod · 0.65
GetPidMethod · 0.65

Tested by

no test coverage detected