diff options
author | Adrian Reber <areber@redhat.com> | 2021-11-17 16:55:43 +0000 |
---|---|---|
committer | Adrian Reber <areber@redhat.com> | 2021-11-19 17:46:06 +0000 |
commit | c76caba367583c5d4f1e8fe3f111383148d4d175 (patch) | |
tree | d53725f3777e678942b902038cfe1fde42ca07f9 /cmd | |
parent | 671e5ee42d4eb71fc0238e8b0b1e4a68b1def156 (diff) | |
download | podman-c76caba367583c5d4f1e8fe3f111383148d4d175.tar.gz podman-c76caba367583c5d4f1e8fe3f111383148d4d175.tar.bz2 podman-c76caba367583c5d4f1e8fe3f111383148d4d175.zip |
Use same runtime to restore a container as during checkpointing
There are at least two runtimes that support checkpoint and restore:
runc and crun. Although the checkpoints created by these are almost
compatible, it is not (yet) possible to restore a checkpoint created
with one runtime with the other runtime. To make checkpoint/restore
usage more comfortable this adds code to look into the checkpoint
archive during restore and to set the runtime to the one used during
checkpointing.
This also adds a check, if the user explicitly sets a runtime during
restore, that the runtime is also the same as used during checkpointing.
If a different runtime is selected than the one used during
checkpointing the restore will fail early.
If runc and crun will create compatible checkpoints in the future the
check can be changed to treat crun and runc as compatible
checkpoint/restore runtimes.
Signed-off-by: Adrian Reber <areber@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/root.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 9e4c8d24d..bccc559ce 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -15,6 +15,7 @@ import ( "github.com/containers/podman/v3/cmd/podman/registry" "github.com/containers/podman/v3/cmd/podman/validate" "github.com/containers/podman/v3/libpod/define" + "github.com/containers/podman/v3/pkg/checkpoint/crutils" "github.com/containers/podman/v3/pkg/domain/entities" "github.com/containers/podman/v3/pkg/parallel" "github.com/containers/podman/v3/pkg/rootless" @@ -114,6 +115,48 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error { cfg := registry.PodmanConfig() + // Currently it is only possible to restore a container with the same runtime + // as used for checkpointing. It should be possible to make crun and runc + // compatible to restore a container with another runtime then checkpointed. + // Currently that does not work. + // To make it easier for users we will look into the checkpoint archive and + // set the runtime to the one used during checkpointing. + if !registry.IsRemote() && cmd.Name() == "restore" { + if cmd.Flag("import").Changed { + runtime, err := crutils.CRGetRuntimeFromArchive(cmd.Flag("import").Value.String()) + if err != nil { + return errors.Wrapf( + err, + "failed extracting runtime information from %s", + cmd.Flag("import").Value.String(), + ) + } + if cfg.RuntimePath == "" { + // If the user did not select a runtime, this takes the one from + // the checkpoint archives and tells Podman to use it for the restore. + runtimeFlag := cmd.Root().Flags().Lookup("runtime") + if runtimeFlag == nil { + return errors.Errorf( + "Unexcpected error setting runtime to '%s' for restore", + *runtime, + ) + } + runtimeFlag.Value.Set(*runtime) + runtimeFlag.Changed = true + logrus.Debugf("Checkpoint was created using '%s'. Restore will use the same runtime", *runtime) + } else if cfg.RuntimePath != *runtime { + // If the user selected a runtime on the command-line this checks if + // it is the same then during checkpointing and errors out if not. + return errors.Errorf( + "checkpoint archive %s was created with runtime '%s' and cannot be restored with runtime '%s'", + cmd.Flag("import").Value.String(), + *runtime, + cfg.RuntimePath, + ) + } + } + } + // --connection is not as "special" as --remote so we can wait and process it here conn := cmd.Root().LocalFlags().Lookup("connection") if conn != nil && conn.Changed { |