mirror of
https://github.com/containers/podman.git
synced 2025-05-20 16:47:39 +08:00
Remove Libpod special-init conditions
Before this, for some special Podman commands (system reset, system migrate, system renumber), Podman would create a first Libpod runtime to do initialization and flag parsing, then stop that runtime and create an entirely new runtime to perform the actual task. This is an artifact of the pre-Podman 2.0 days, when there was almost no indirection between Libpod and the CLI, and we only used one runtime because we didn't need a second runtime for flag parsing and basic init. This system was clunky, and apparently, very buggy. When we migrated to SQLite, some logic was introduced where we'd select a different database location based on whether or not Libpod's StaticDir was manually set - which differed between the first invocation of Libpod and the second. So we'd get a different database for some commands (like `system reset`) and they would not be able to see existing containers, meaning they would not function properly. The immediate cause is obviously the SQLite behavior, but I'm certain there's a lot more baggage hiding behind this multiple Libpod runtime logic, so let's just refactor it out. It doesn't make sense, and complicates the code. Instead, make Reset, Renumber, and Migrate methods of the libpod Runtime. For Reset and Renumber, we can shut the runtime down afterwards to achieve the desired effect (no valid runtime after). Then pipe all of them through the ContainerEngine so cmd/podman can access them. As part of this, remove the SystemEngine part of pkg/domain. This was supposed to encompass these "special" commands, but every command in SystemEngine is actually a ContainerEngine command. Reset, Renumber, Migrate - they all need a full Libpod and access to all containers. There's no point to a separate engine if it just wraps Libpod in the exact same way as ContainerEngine. This consolidation saves us a bit more code and complexity. Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
@ -454,9 +454,10 @@ func WithDefaultInfraCommand(cmd string) RuntimeOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithReset instructs libpod to reset all storage to factory defaults.
|
||||
// All containers, pods, volumes, images, and networks will be removed.
|
||||
// All directories created by Libpod will be removed.
|
||||
// WithReset tells Libpod that the runtime will be used to perform a system
|
||||
// reset. A number of checks at initialization are relaxed as the runtime is
|
||||
// going to be used to remove all containers, pods, volumes, images, and
|
||||
// networks.
|
||||
func WithReset() RuntimeOption {
|
||||
return func(rt *Runtime) error {
|
||||
if rt.valid {
|
||||
@ -469,10 +470,8 @@ func WithReset() RuntimeOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithRenumber instructs libpod to perform a lock renumbering while
|
||||
// initializing. This will handle migrations from early versions of libpod with
|
||||
// file locks to newer versions with SHM locking, as well as changes in the
|
||||
// number of configured locks.
|
||||
// WithRenumber tells Libpod that the runtime will be used to perform a system
|
||||
// renumber. A number of checks on initialization related to locks are relaxed.
|
||||
func WithRenumber() RuntimeOption {
|
||||
return func(rt *Runtime) error {
|
||||
if rt.valid {
|
||||
@ -485,43 +484,6 @@ func WithRenumber() RuntimeOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithMigrate instructs libpod to migrate container configurations to account
|
||||
// for changes between Engine versions. All running containers will be stopped
|
||||
// during a migration, then restarted after the migration is complete.
|
||||
func WithMigrate() RuntimeOption {
|
||||
return func(rt *Runtime) error {
|
||||
if rt.valid {
|
||||
return define.ErrRuntimeFinalized
|
||||
}
|
||||
|
||||
rt.doMigrate = true
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithMigrateRuntime instructs Engine to change the default OCI runtime on all
|
||||
// containers during a migration. This is not used if `MigrateRuntime()` is not
|
||||
// also passed.
|
||||
// Engine makes no promises that your containers continue to work with the new
|
||||
// runtime - migrations between dissimilar runtimes may well break things.
|
||||
// Use with caution.
|
||||
func WithMigrateRuntime(requestedRuntime string) RuntimeOption {
|
||||
return func(rt *Runtime) error {
|
||||
if rt.valid {
|
||||
return define.ErrRuntimeFinalized
|
||||
}
|
||||
|
||||
if requestedRuntime == "" {
|
||||
return fmt.Errorf("must provide a non-empty name for new runtime: %w", define.ErrInvalidArg)
|
||||
}
|
||||
|
||||
rt.migrateRuntime = requestedRuntime
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithEventsLogger sets the events backend to use.
|
||||
// Currently supported values are "file" for file backend and "journald" for
|
||||
// journald backend.
|
||||
|
Reference in New Issue
Block a user