diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-02-02 18:17:23 +0100 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-02-03 13:14:07 +0100 |
commit | 55c4a1468b8738a5711d213cfe7c172b463ecd24 (patch) | |
tree | 69bc9576f3ca2d8f41a8b61c9bf23b0c725fa9fd /libpod | |
parent | f2263fade4aef30fd619b648e4d1ca4aaf6bd506 (diff) | |
download | podman-55c4a1468b8738a5711d213cfe7c172b463ecd24.tar.gz podman-55c4a1468b8738a5711d213cfe7c172b463ecd24.tar.bz2 podman-55c4a1468b8738a5711d213cfe7c172b463ecd24.zip |
system prune: remove all networks
podman system prune should also remove all networks. When we want to
users to migrate to the new network stack we recommend to run podman
system reset. However this did not remove networks and if there were
still networks around we would continue to use cni since this was
considered an old system.
There is one exception for the default network. It should not be removed
since this could cause other issues when it no longer exists. The
network backend detection logic ignores the default network so this is
fine.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/reset.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libpod/reset.go b/libpod/reset.go index 2b2b586bc..28d0ee3f6 100644 --- a/libpod/reset.go +++ b/libpod/reset.go @@ -7,6 +7,7 @@ import ( "path/filepath" "github.com/containers/common/libimage" + "github.com/containers/common/libnetwork/types" "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/errorhandling" "github.com/containers/podman/v4/pkg/rootless" @@ -70,6 +71,22 @@ func (r *Runtime) Reset(ctx context.Context) error { } } + // remove all networks + nets, err := r.network.NetworkList() + if err != nil { + return err + } + for _, net := range nets { + // do not delete the default network + if net.Name == r.network.DefaultNetworkName() { + continue + } + // ignore not exists errors because of the TOCTOU problem + if err := r.network.NetworkRemove(net.Name); err != nil && !errors.Is(err, types.ErrNoSuchNetwork) { + logrus.Errorf("Removing network %s: %v", net.Name, err) + } + } + xdgRuntimeDir := filepath.Clean(os.Getenv("XDG_RUNTIME_DIR")) _, prevError := r.store.Shutdown(true) graphRoot := filepath.Clean(r.store.GraphRoot()) |