diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-09-28 14:13:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-28 14:13:32 +0000 |
commit | 97841e55072ae71713922ab6c6c1269e74b08dcf (patch) | |
tree | 755a73bf2863a88b5523692f1c920177930620a9 /pkg/domain | |
parent | 03d01abec6d028e9d5f60615b0451e42d0611d1d (diff) | |
parent | 343a10e25fb12685f18ed3600c567397c01a7cc8 (diff) | |
download | podman-97841e55072ae71713922ab6c6c1269e74b08dcf.tar.gz podman-97841e55072ae71713922ab6c6c1269e74b08dcf.tar.bz2 podman-97841e55072ae71713922ab6c6c1269e74b08dcf.zip |
Merge pull request #7793 from Luap99/network-force
Fix podman network rm --force when network is used by a pod
Diffstat (limited to 'pkg/domain')
-rw-r--r-- | pkg/domain/infra/abi/network.go | 15 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/network.go | 11 |
2 files changed, 20 insertions, 6 deletions
diff --git a/pkg/domain/infra/abi/network.go b/pkg/domain/infra/abi/network.go index 807e4b272..053be6528 100644 --- a/pkg/domain/infra/abi/network.go +++ b/pkg/domain/infra/abi/network.go @@ -82,12 +82,21 @@ func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, o // We need to iterate containers looking to see if they belong to the given network for _, c := range containers { if util.StringInSlice(name, c.Config().Networks) { - // if user passes force, we nuke containers + // if user passes force, we nuke containers and pods if !options.Force { // Without the force option, we return an error - return reports, errors.Errorf("%q has associated containers with it. Use -f to forcibly delete containers", name) + return reports, errors.Errorf("%q has associated containers with it. Use -f to forcibly delete containers and pods", name) } - if err := ic.Libpod.RemoveContainer(ctx, c, true, true); err != nil { + if c.IsInfra() { + // if we have a infra container we need to remove the pod + pod, err := ic.Libpod.GetPod(c.PodID()) + if err != nil { + return reports, err + } + if err := ic.Libpod.RemovePod(ctx, pod, true, true); err != nil { + return reports, err + } + } else if err := ic.Libpod.RemoveContainer(ctx, c, true, true); err != nil { return reports, err } } diff --git a/pkg/domain/infra/tunnel/network.go b/pkg/domain/infra/tunnel/network.go index 074425087..d155fdd9e 100644 --- a/pkg/domain/infra/tunnel/network.go +++ b/pkg/domain/infra/tunnel/network.go @@ -26,11 +26,16 @@ func (ic *ContainerEngine) NetworkInspect(ctx context.Context, namesOrIds []stri func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, options entities.NetworkRmOptions) ([]*entities.NetworkRmReport, error) { reports := make([]*entities.NetworkRmReport, 0, len(namesOrIds)) for _, name := range namesOrIds { - report, err := network.Remove(ic.ClientCxt, name, &options.Force) + response, err := network.Remove(ic.ClientCxt, name, &options.Force) if err != nil { - report[0].Err = err + report := &entities.NetworkRmReport{ + Name: name, + Err: err, + } + reports = append(reports, report) + } else { + reports = append(reports, response...) } - reports = append(reports, report...) } return reports, nil } |