Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for checkpoint images with 'podman run' #16569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions pkg/domain/infra/abi/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"os"
"reflect"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -1110,6 +1111,44 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta
fmt.Fprintf(os.Stderr, "%s\n", w)
}

if opts.Spec != nil && !reflect.ValueOf(opts.Spec).IsNil() {
// If this is a checkpoint image, restore it.
img, resolvedImageName := opts.Spec.GetImage()
if img != nil && resolvedImageName != "" {
imgData, err := img.Inspect(ctx, nil)
if err != nil {
return nil, err
}
if imgData != nil {
_, isCheckpointImage := imgData.Annotations[define.CheckpointAnnotationRuntimeName]
if isCheckpointImage {
var restoreOptions entities.RestoreOptions
restoreOptions.Name = opts.Spec.Name
restoreOptions.Pod = opts.Spec.Pod
responses, err := ic.ContainerRestore(ctx, []string{resolvedImageName}, restoreOptions)
if err != nil {
return nil, err
}

report := entities.ContainerRunReport{}
for _, r := range responses {
report.Id = r.Id
report.ExitCode = 0
if r.Err != nil {
logrus.Errorf("Failed to restore checkpoint image %s: %v", resolvedImageName, r.Err)
rst0git marked this conversation as resolved.
Show resolved Hide resolved
report.ExitCode = 126
}
if r.RawInput != "" {
logrus.Errorf("Failed to restore checkpoint image %s: %v", resolvedImageName, r.RawInput)
report.ExitCode = 126
}
}
return &report, nil
}
}
}
}

rtSpec, spec, optsN, err := generate.MakeContainer(ctx, ic.Libpod, opts.Spec, false, nil)
if err != nil {
return nil, err
Expand Down
25 changes: 25 additions & 0 deletions pkg/domain/infra/tunnel/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"os"
"reflect"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -790,6 +791,30 @@ func (ic *ContainerEngine) ContainerListExternal(ctx context.Context) ([]entitie
}

func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.ContainerRunOptions) (*entities.ContainerRunReport, error) {
if opts.Spec != nil && !reflect.ValueOf(opts.Spec).IsNil() && opts.Spec.RawImageName != "" {
// If this is a checkpoint image, restore it.
getImageOptions := new(images.GetOptions).WithSize(false)
inspectReport, err := images.GetImage(ic.ClientCtx, opts.Spec.RawImageName, getImageOptions)
if err != nil {
return nil, fmt.Errorf("no such container or image: %s", opts.Spec.RawImageName)
}
if inspectReport != nil {
_, isCheckpointImage := inspectReport.Annotations[define.CheckpointAnnotationRuntimeName]
if isCheckpointImage {
restoreOptions := new(containers.RestoreOptions)
restoreOptions.WithName(opts.Spec.Name)
restoreOptions.WithPod(opts.Spec.Pod)

restoreReport, err := containers.Restore(ic.ClientCtx, inspectReport.ID, restoreOptions)
if err != nil {
return nil, err
}
runReport := entities.ContainerRunReport{Id: restoreReport.Id}
return &runReport, nil
}
}
}

con, err := containers.CreateWithSpec(ic.ClientCtx, opts.Spec, nil)
if err != nil {
return nil, err
Expand Down
Loading