mirror of
https://github.com/containers/podman.git
synced 2025-06-24 19:42:56 +08:00
Merge pull request #3051 from mheon/podman_migrate_fixes
Small fixes for #2950
This commit is contained in:
@ -78,8 +78,6 @@ func getRuntime(ctx context.Context, c *cliconfig.PodmanCommand, renumber bool,
|
|||||||
options = append(options, libpod.WithRenumber())
|
options = append(options, libpod.WithRenumber())
|
||||||
}
|
}
|
||||||
|
|
||||||
options = append(options, libpod.WithContext(ctx))
|
|
||||||
|
|
||||||
// Only set this if the user changes storage config on the command line
|
// Only set this if the user changes storage config on the command line
|
||||||
if storageSet {
|
if storageSet {
|
||||||
options = append(options, libpod.WithStorageConfig(storageOpts))
|
options = append(options, libpod.WithStorageConfig(storageOpts))
|
||||||
@ -146,7 +144,7 @@ func getRuntime(ctx context.Context, c *cliconfig.PodmanCommand, renumber bool,
|
|||||||
options = append(options, libpod.WithDefaultInfraCommand(infraCommand))
|
options = append(options, libpod.WithDefaultInfraCommand(infraCommand))
|
||||||
}
|
}
|
||||||
if c.Flags().Changed("config") {
|
if c.Flags().Changed("config") {
|
||||||
return libpod.NewRuntimeFromConfig(c.GlobalFlags.Config, options...)
|
return libpod.NewRuntimeFromConfig(ctx, c.GlobalFlags.Config, options...)
|
||||||
}
|
}
|
||||||
return libpod.NewRuntime(options...)
|
return libpod.NewRuntime(ctx, options...)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package libpod
|
package libpod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -437,10 +436,9 @@ func WithRenumber() RuntimeOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithMigrate instructs libpod to perform a lock migrateing while
|
// WithMigrate instructs libpod to migrate container configurations to account
|
||||||
// initializing. This will handle migrations from early versions of libpod with
|
// for changes between Libpod versions. All running containers will be stopped
|
||||||
// file locks to newer versions with SHM locking, as well as changes in the
|
// during a migration, then restarted after the migration is complete.
|
||||||
// number of configured locks.
|
|
||||||
func WithMigrate() RuntimeOption {
|
func WithMigrate() RuntimeOption {
|
||||||
return func(rt *Runtime) error {
|
return func(rt *Runtime) error {
|
||||||
if rt.valid {
|
if rt.valid {
|
||||||
@ -467,19 +465,6 @@ func WithShmDir(dir string) CtrCreateOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithContext sets the context to use.
|
|
||||||
func WithContext(ctx context.Context) RuntimeOption {
|
|
||||||
return func(rt *Runtime) error {
|
|
||||||
if rt.valid {
|
|
||||||
return ErrRuntimeFinalized
|
|
||||||
}
|
|
||||||
|
|
||||||
rt.ctx = ctx
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithSystemd turns on systemd mode in the container
|
// WithSystemd turns on systemd mode in the container
|
||||||
func WithSystemd() CtrCreateOption {
|
func WithSystemd() CtrCreateOption {
|
||||||
return func(ctr *Container) error {
|
return func(ctr *Container) error {
|
||||||
|
@ -112,8 +112,6 @@ type Runtime struct {
|
|||||||
|
|
||||||
// mechanism to read and write even logs
|
// mechanism to read and write even logs
|
||||||
eventer events.Eventer
|
eventer events.Eventer
|
||||||
|
|
||||||
ctx context.Context
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OCIRuntimePath contains information about an OCI runtime.
|
// OCIRuntimePath contains information about an OCI runtime.
|
||||||
@ -353,8 +351,8 @@ func SetXdgRuntimeDir(val string) error {
|
|||||||
|
|
||||||
// NewRuntime creates a new container runtime
|
// NewRuntime creates a new container runtime
|
||||||
// Options can be passed to override the default configuration for the runtime
|
// Options can be passed to override the default configuration for the runtime
|
||||||
func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
|
func NewRuntime(ctx context.Context, options ...RuntimeOption) (runtime *Runtime, err error) {
|
||||||
return newRuntimeFromConfig("", options...)
|
return newRuntimeFromConfig(ctx, "", options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRuntimeFromConfig creates a new container runtime using the given
|
// NewRuntimeFromConfig creates a new container runtime using the given
|
||||||
@ -362,14 +360,14 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
|
|||||||
// functions can be used to mutate this configuration further.
|
// functions can be used to mutate this configuration further.
|
||||||
// An error will be returned if the configuration file at the given path does
|
// An error will be returned if the configuration file at the given path does
|
||||||
// not exist or cannot be loaded
|
// not exist or cannot be loaded
|
||||||
func NewRuntimeFromConfig(userConfigPath string, options ...RuntimeOption) (runtime *Runtime, err error) {
|
func NewRuntimeFromConfig(ctx context.Context, userConfigPath string, options ...RuntimeOption) (runtime *Runtime, err error) {
|
||||||
if userConfigPath == "" {
|
if userConfigPath == "" {
|
||||||
return nil, errors.New("invalid configuration file specified")
|
return nil, errors.New("invalid configuration file specified")
|
||||||
}
|
}
|
||||||
return newRuntimeFromConfig(userConfigPath, options...)
|
return newRuntimeFromConfig(ctx, userConfigPath, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRuntimeFromConfig(userConfigPath string, options ...RuntimeOption) (runtime *Runtime, err error) {
|
func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options ...RuntimeOption) (runtime *Runtime, err error) {
|
||||||
runtime = new(Runtime)
|
runtime = new(Runtime)
|
||||||
runtime.config = new(RuntimeConfig)
|
runtime.config = new(RuntimeConfig)
|
||||||
runtime.configuredFrom = new(runtimeConfiguredFrom)
|
runtime.configuredFrom = new(runtimeConfiguredFrom)
|
||||||
@ -563,7 +561,7 @@ func newRuntimeFromConfig(userConfigPath string, options ...RuntimeOption) (runt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := makeRuntime(runtime); err != nil {
|
if err := makeRuntime(ctx, runtime); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return runtime, nil
|
return runtime, nil
|
||||||
@ -571,7 +569,7 @@ func newRuntimeFromConfig(userConfigPath string, options ...RuntimeOption) (runt
|
|||||||
|
|
||||||
// Make a new runtime based on the given configuration
|
// Make a new runtime based on the given configuration
|
||||||
// Sets up containers/storage, state store, OCI runtime
|
// Sets up containers/storage, state store, OCI runtime
|
||||||
func makeRuntime(runtime *Runtime) (err error) {
|
func makeRuntime(ctx context.Context, runtime *Runtime) (err error) {
|
||||||
// Backward compatibility for `runtime_path`
|
// Backward compatibility for `runtime_path`
|
||||||
if runtime.config.RuntimePath != nil {
|
if runtime.config.RuntimePath != nil {
|
||||||
// Don't print twice in rootless mode.
|
// Don't print twice in rootless mode.
|
||||||
@ -980,7 +978,7 @@ func makeRuntime(runtime *Runtime) (err error) {
|
|||||||
os.Exit(ret)
|
os.Exit(ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := runtime.migrate(); err != nil {
|
if err := runtime.migrate(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package libpod
|
package libpod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Runtime) migrate() error {
|
func (r *Runtime) migrate(ctx context.Context) error {
|
||||||
runningContainers, err := r.GetRunningContainers()
|
runningContainers, err := r.GetRunningContainers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -38,7 +39,7 @@ func (r *Runtime) migrate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, ctr := range runningContainers {
|
for _, ctr := range runningContainers {
|
||||||
if err := ctr.Start(r.ctx, true); err != nil {
|
if err := ctr.Start(ctx, true); err != nil {
|
||||||
logrus.Errorf("error restarting container %s", ctr.ID())
|
logrus.Errorf("error restarting container %s", ctr.ID())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user