mirror of
https://github.com/containers/podman.git
synced 2025-05-19 16:18:51 +08:00
Fix podman system reset
with external containers
It looks like we had some logic for this from #10789 but it does not appear to have ever worked; we can't pull external containers out of the DB, so the ContainerRm call failed unconditionally. Instead, just handle them in Libpod when we're removing images. We're removing every image, so setting Force when removing images should get rid of all external containers. It's a little later in the process than the current (nonfunctional) solution is but I can't think of a reason why that would be bad. [NO NEW TESTS NEEDED] We do not currently test `system reset`. We should probably reevaluate that at some point this year. Fixes https://issues.redhat.com/browse/RHEL-21261 Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
@ -48,10 +48,9 @@ func init() {
|
||||
|
||||
func reset(cmd *cobra.Command, args []string) {
|
||||
// Get all the external containers in use
|
||||
listCtn, _ := registry.ContainerEngine().ContainerListExternal(registry.Context())
|
||||
listCtnIds := make([]string, 0, len(listCtn))
|
||||
for _, externalCtn := range listCtn {
|
||||
listCtnIds = append(listCtnIds, externalCtn.ID)
|
||||
listCtn, err := registry.ContainerEngine().ContainerListExternal(registry.Context())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
// Prompt for confirmation if --force is not set
|
||||
if !forceFlag {
|
||||
@ -90,14 +89,8 @@ func reset(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Purge all the external containers with storage
|
||||
_, err := registry.ContainerEngine().ContainerRm(registry.Context(), listCtnIds, entities.RmOptions{Force: true, All: true, Ignore: true, Volumes: true})
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
// Clean build cache if any
|
||||
err = volumes.CleanCacheMount()
|
||||
if err != nil {
|
||||
if err := volumes.CleanCacheMount(); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
// Shutdown all running engines, `reset` will hijack repository
|
||||
|
@ -117,13 +117,23 @@ func (r *Runtime) reset(ctx context.Context) error {
|
||||
}
|
||||
|
||||
for _, c := range ctrs {
|
||||
if err := r.RemoveContainer(ctx, c, true, true, timeout); err != nil {
|
||||
if err := r.RemoveStorageContainer(c.ID(), true); err != nil {
|
||||
if errors.Is(err, define.ErrNoSuchCtr) {
|
||||
if ctrs, _, err := r.RemoveContainerAndDependencies(ctx, c, true, true, timeout); err != nil {
|
||||
for ctr, err := range ctrs {
|
||||
logrus.Errorf("Error removing container %s: %v", ctr, err)
|
||||
}
|
||||
|
||||
if errors.Is(err, define.ErrNoSuchCtr) || errors.Is(err, define.ErrCtrRemoved) {
|
||||
continue
|
||||
}
|
||||
|
||||
logrus.Errorf("Removing container %s: %v", c.ID(), err)
|
||||
}
|
||||
|
||||
// There's no point trying a storage container removal
|
||||
// here. High likelihood it doesn't work
|
||||
// (RemoveStorageContainer will refuse to remove if a
|
||||
// container exists in the Libpod database) and, even if
|
||||
// it would, we'll get the container later on during
|
||||
// image removal.
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,11 +141,7 @@ func (r *Runtime) reset(ctx context.Context) error {
|
||||
logrus.Errorf("Stopping pause process: %v", err)
|
||||
}
|
||||
|
||||
rmiOptions := &libimage.RemoveImagesOptions{Filters: []string{"readonly=false"}}
|
||||
if _, rmiErrors := r.LibimageRuntime().RemoveImages(ctx, nil, rmiOptions); rmiErrors != nil {
|
||||
return errorhandling.JoinErrors(rmiErrors)
|
||||
}
|
||||
|
||||
// Volumes before images, as volumes can mount images.
|
||||
volumes, err := r.state.AllVolumes()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -149,6 +155,19 @@ func (r *Runtime) reset(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Set force and ignore.
|
||||
// Ignore shouldn't be necessary, but it seems safer. We want everything
|
||||
// gone anyways...
|
||||
rmiOptions := &libimage.RemoveImagesOptions{
|
||||
Force: true,
|
||||
Ignore: true,
|
||||
RemoveContainerFunc: r.RemoveContainersForImageCallback(ctx),
|
||||
Filters: []string{"readonly=false"},
|
||||
}
|
||||
if _, rmiErrors := r.LibimageRuntime().RemoveImages(ctx, nil, rmiOptions); rmiErrors != nil {
|
||||
return errorhandling.JoinErrors(rmiErrors)
|
||||
}
|
||||
|
||||
// remove all networks
|
||||
nets, err := r.network.NetworkList()
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user