Files
podman/cmd/podman/system_migrate.go
Matthew Heon feba94eb95 Migrate can move containers to a new runtime
This is a horrible hack to work around issues with Fedora 31, but
other distros might need it to, so we'll move it upstream.

I do not recommend this functionality for general use, and the
manpages and other documentation will reflect this. But for some
upgrade cases, it will be the only thing that allows for a
working system.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-10-10 10:25:06 -04:00

53 lines
1.4 KiB
Go

package main
import (
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
var (
migrateCommand cliconfig.SystemMigrateValues
migrateDescription = `
podman system migrate
Migrate existing containers to a new version of Podman.
`
_migrateCommand = &cobra.Command{
Use: "migrate",
Args: noSubArgs,
Short: "Migrate containers",
Long: migrateDescription,
RunE: func(cmd *cobra.Command, args []string) error {
migrateCommand.InputArgs = args
migrateCommand.GlobalFlags = MainGlobalOpts
return migrateCmd(&migrateCommand)
},
}
)
func init() {
migrateCommand.Command = _migrateCommand
migrateCommand.SetHelpTemplate(HelpTemplate())
migrateCommand.SetUsageTemplate(UsageTemplate())
flags := migrateCommand.Flags()
flags.StringVar(&migrateCommand.NewRuntime, "new-runtime", "", "Specify a new runtime for all containers")
}
func migrateCmd(c *cliconfig.SystemMigrateValues) error {
// We need to pass one extra option to NewRuntime.
// This will inform the OCI runtime to start a migrate.
// That's controlled by the last argument to GetRuntime.
r, err := libpodruntime.GetRuntimeMigrate(getContext(), &c.PodmanCommand, c.NewRuntime)
if err != nil {
return errors.Wrapf(err, "error migrating containers")
}
if err := r.Shutdown(false); err != nil {
return err
}
return nil
}