summaryrefslogtreecommitdiff
path: root/pkg/domain/infra/abi
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-12-23 06:41:55 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2022-01-11 14:33:54 -0500
commit8f2358eeaa59fe369eebc6186403f95c2d66e49b (patch)
treea454ef259ab28f85b17f53b3273725480aa78515 /pkg/domain/infra/abi
parentc4142ce0cfff792092bf420950b1985058cc241c (diff)
downloadpodman-8f2358eeaa59fe369eebc6186403f95c2d66e49b.tar.gz
podman-8f2358eeaa59fe369eebc6186403f95c2d66e49b.tar.bz2
podman-8f2358eeaa59fe369eebc6186403f95c2d66e49b.zip
Add podman rm --depend
This option causes Podman to not only remove the specified containers but all of the containers that depend on the specified containers. Fixes: https://github.com/containers/podman/issues/10360 Also ran codespell on the code Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/domain/infra/abi')
-rw-r--r--pkg/domain/infra/abi/containers.go37
1 files changed, 24 insertions, 13 deletions
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index bf4dcff62..a4522698e 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -301,27 +301,27 @@ func (ic *ContainerEngine) removeContainer(ctx context.Context, ctr *libpod.Cont
return err
}
-func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string, options entities.RmOptions) ([]*entities.RmReport, error) {
- reports := []*entities.RmReport{}
+func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string, options entities.RmOptions) ([]*reports.RmReport, error) {
+ rmReports := []*reports.RmReport{}
names := namesOrIds
// 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}
+ report := reports.RmReport{Id: ctr}
report.Err = ic.Libpod.RemoveStorageContainer(ctr, options.Force)
switch errors.Cause(report.Err) {
case nil:
// remove container names that we successfully deleted
- reports = append(reports, &report)
+ rmReports = append(rmReports, &report)
case define.ErrNoSuchCtr, define.ErrCtrExists:
// 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)
+ rmReports = append(rmReports, &report)
continue
}
// attempt to remove as a libpod container
@@ -340,23 +340,34 @@ func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string,
for _, ctr := range names {
logrus.Debugf("Evicting container %q", ctr)
- report := entities.RmReport{Id: ctr}
+ report := reports.RmReport{Id: ctr}
_, err := ic.Libpod.EvictContainer(ctx, ctr, options.Volumes)
if err != nil {
if options.Ignore && errors.Cause(err) == define.ErrNoSuchCtr {
logrus.Debugf("Ignoring error (--allow-missing): %v", err)
- reports = append(reports, &report)
+ rmReports = append(rmReports, &report)
continue
}
report.Err = err
- reports = append(reports, &report)
+ rmReports = append(rmReports, &report)
continue
}
- reports = append(reports, &report)
+ rmReports = append(rmReports, &report)
}
- return reports, nil
+ return rmReports, nil
}
+ if !options.All && options.Depend {
+ // Add additional containers based on dependencies to container map
+ for _, ctr := range ctrs {
+ reports, err := ic.Libpod.RemoveDepend(ctx, ctr, options.Force, options.Volumes, options.Timeout)
+ if err != nil {
+ return rmReports, err
+ }
+ rmReports = append(rmReports, reports...)
+ }
+ return rmReports, nil
+ }
errMap, err := parallelctr.ContainerOp(ctx, ctrs, func(c *libpod.Container) error {
return ic.removeContainer(ctx, c, options)
})
@@ -364,12 +375,12 @@ func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string,
return nil, err
}
for ctr, err := range errMap {
- report := new(entities.RmReport)
+ report := new(reports.RmReport)
report.Id = ctr.ID()
report.Err = err
- reports = append(reports, report)
+ rmReports = append(rmReports, report)
}
- return reports, nil
+ return rmReports, nil
}
func (ic *ContainerEngine) ContainerInspect(ctx context.Context, namesOrIds []string, options entities.InspectOptions) ([]*entities.ContainerInspectReport, []error, error) {