mirror of
https://github.com/containers/podman.git
synced 2025-05-17 15:18:43 +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:
@ -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) {
|
||||
continue
|
||||
}
|
||||
logrus.Errorf("Removing container %s: %v", c.ID(), err)
|
||||
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