NOTE: Checkpoint supports to dump task information to a directory, in this way, an empty OCI Index will be returned.
(ctx context.Context, opts ...CheckpointTaskOpts)
| 549 | // NOTE: Checkpoint supports to dump task information to a directory, in this way, an empty |
| 550 | // OCI Index will be returned. |
| 551 | func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Image, error) { |
| 552 | ctx, done, err := t.client.WithLease(ctx) |
| 553 | if err != nil { |
| 554 | return nil, err |
| 555 | } |
| 556 | defer done(ctx) |
| 557 | cr, err := t.client.ContainerService().Get(ctx, t.id) |
| 558 | if err != nil { |
| 559 | return nil, err |
| 560 | } |
| 561 | |
| 562 | request := &tasks.CheckpointTaskRequest{ |
| 563 | ContainerID: t.id, |
| 564 | } |
| 565 | i := CheckpointTaskInfo{ |
| 566 | runtime: cr.Runtime.Name, |
| 567 | } |
| 568 | for _, o := range opts { |
| 569 | if err := o(&i); err != nil { |
| 570 | return nil, err |
| 571 | } |
| 572 | } |
| 573 | // set a default name |
| 574 | if i.Name == "" { |
| 575 | i.Name = fmt.Sprintf(checkpointNameFormat, t.id, time.Now().Format(checkpointDateFormat)) |
| 576 | } |
| 577 | request.ParentCheckpoint = i.ParentCheckpoint.String() |
| 578 | if i.Options != nil { |
| 579 | o, err := typeurl.MarshalAnyToProto(i.Options) |
| 580 | if err != nil { |
| 581 | return nil, err |
| 582 | } |
| 583 | request.Options = o |
| 584 | } |
| 585 | |
| 586 | status, err := t.Status(ctx) |
| 587 | if err != nil { |
| 588 | return nil, err |
| 589 | } |
| 590 | |
| 591 | if status.Status != Paused { |
| 592 | // make sure we pause it and resume after all other filesystem operations are completed |
| 593 | if err := t.Pause(ctx); err != nil { |
| 594 | return nil, err |
| 595 | } |
| 596 | defer t.Resume(ctx) |
| 597 | } |
| 598 | |
| 599 | index := v1.Index{ |
| 600 | Versioned: is.Versioned{ |
| 601 | SchemaVersion: 2, |
| 602 | }, |
| 603 | Annotations: make(map[string]string), |
| 604 | } |
| 605 | if err := t.checkpointTask(ctx, &index, request); err != nil { |
| 606 | return nil, err |
| 607 | } |
| 608 | // if checkpoint image path passed, jump checkpoint image, |
nothing calls this directly
no test coverage detected