diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-01-20 17:58:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-20 17:58:11 -0500 |
commit | 14443ccdfc19a7d719c63937ce76bfddf01f88e2 (patch) | |
tree | 3b3270237f9d3837668733e7364feb029037d437 /pkg/domain | |
parent | fe4f9ba303affde0b838e19c862b45206ae2feed (diff) | |
parent | e7df73efadd36e2489954ee9a766a3fbfe4eafeb (diff) | |
download | podman-14443ccdfc19a7d719c63937ce76bfddf01f88e2.tar.gz podman-14443ccdfc19a7d719c63937ce76bfddf01f88e2.tar.bz2 podman-14443ccdfc19a7d719c63937ce76bfddf01f88e2.zip |
Merge pull request #9014 from rhatdan/rm
Fix handling of container remove
Diffstat (limited to 'pkg/domain')
-rw-r--r-- | pkg/domain/entities/containers.go | 11 | ||||
-rw-r--r-- | pkg/domain/infra/abi/containers.go | 30 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/containers.go | 8 |
3 files changed, 20 insertions, 29 deletions
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go index d8576c101..4c1bd6a7d 100644 --- a/pkg/domain/entities/containers.go +++ b/pkg/domain/entities/containers.go @@ -128,12 +128,11 @@ type RestartReport struct { } type RmOptions struct { - All bool - CIDFiles []string - Force bool - Ignore bool - Latest bool - Volumes bool + All bool + Force bool + Ignore bool + Latest bool + Volumes bool } type RmReport struct { diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index a8f4d44a8..48a32817d 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -264,30 +264,30 @@ func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string, reports := []*entities.RmReport{} names := namesOrIds - for _, cidFile := range options.CIDFiles { - content, err := ioutil.ReadFile(cidFile) - if err != nil { - return nil, errors.Wrap(err, "error reading CIDFile") - } - id := strings.Split(string(content), "\n")[0] - names = append(names, id) - } - // Attempt to remove named containers directly from storage, if container is defined in libpod // this will fail and code will fall through to removing the container from libpod.` tmpNames := []string{} for _, ctr := range names { report := entities.RmReport{Id: ctr} - if err := ic.Libpod.RemoveStorageContainer(ctr, options.Force); err != nil { + report.Err = ic.Libpod.RemoveStorageContainer(ctr, options.Force) + switch errors.Cause(report.Err) { + case nil: // remove container names that we successfully deleted - tmpNames = append(tmpNames, ctr) - } else { reports = append(reports, &report) + case define.ErrNoSuchCtr: + // There is still a potential this is a libpod container + tmpNames = append(tmpNames, ctr) + default: + if _, err := ic.Libpod.LookupContainer(ctr); errors.Cause(err) == define.ErrNoSuchCtr { + // remove container failed, but not a libpod container + reports = append(reports, &report) + continue + } + // attempt to remove as a libpod container + tmpNames = append(tmpNames, ctr) } } - if len(tmpNames) < len(names) { - names = tmpNames - } + names = tmpNames ctrs, err := getContainersByContext(options.All, options.Latest, names, ic.Libpod) if err != nil && !(options.Ignore && errors.Cause(err) == define.ErrNoSuchCtr) { diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go index 84a07f8e9..524b29553 100644 --- a/pkg/domain/infra/tunnel/containers.go +++ b/pkg/domain/infra/tunnel/containers.go @@ -173,14 +173,6 @@ func (ic *ContainerEngine) ContainerRestart(ctx context.Context, namesOrIds []st } func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string, opts entities.RmOptions) ([]*entities.RmReport, error) { - for _, cidFile := range opts.CIDFiles { - content, err := ioutil.ReadFile(cidFile) - if err != nil { - return nil, errors.Wrap(err, "error reading CIDFile") - } - id := strings.Split(string(content), "\n")[0] - namesOrIds = append(namesOrIds, id) - } ctrs, err := getContainersByContext(ic.ClientCtx, opts.All, opts.Ignore, namesOrIds) if err != nil { return nil, err |