aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-12-19 19:37:00 +0100
committerGitHub <noreply@github.com>2019-12-19 19:37:00 +0100
commita359ca0d1825859dd8b7c1384f11d703ec6625b4 (patch)
treea493650454ba9d9728fe9a1aa191bd5fcbab742c
parentdde48b44e725a3da959c627519e8110ec992a26e (diff)
parent88917e4a939f23bedf17fdf470ca1a2c387045eb (diff)
downloadpodman-a359ca0d1825859dd8b7c1384f11d703ec6625b4.tar.gz
podman-a359ca0d1825859dd8b7c1384f11d703ec6625b4.tar.bz2
podman-a359ca0d1825859dd8b7c1384f11d703ec6625b4.zip
Merge pull request #4723 from mheon/pod_volume_postremove
Remove volumes after containers in pod remove
-rw-r--r--libpod/runtime_ctr.go2
-rw-r--r--libpod/runtime_pod_linux.go30
2 files changed, 29 insertions, 3 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index ae401013c..d272e4549 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -573,7 +573,7 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool,
if !volume.IsCtrSpecific() {
continue
}
- if err := runtime.removeVolume(ctx, volume, false); err != nil && err != define.ErrNoSuchVolume && err != define.ErrVolumeBeingUsed {
+ if err := runtime.removeVolume(ctx, volume, false); err != nil && errors.Cause(err) != define.ErrNoSuchVolume {
logrus.Errorf("cleanup volume (%s): %v", v, err)
}
}
diff --git a/libpod/runtime_pod_linux.go b/libpod/runtime_pod_linux.go
index 704aaf9d0..563d9728a 100644
--- a/libpod/runtime_pod_linux.go
+++ b/libpod/runtime_pod_linux.go
@@ -225,11 +225,20 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
}
}
+ ctrNamedVolumes := make(map[string]*ContainerNamedVolume)
+
// Second loop - all containers are good, so we should be clear to
// remove.
for _, ctr := range ctrs {
- // Remove the container
- if err := r.removeContainer(ctx, ctr, force, true, true); err != nil {
+ // Remove the container.
+ // Do NOT remove named volumes. Instead, we're going to build a
+ // list of them to be removed at the end, once the containers
+ // have been removed by RemovePodContainers.
+ for _, vol := range ctr.config.NamedVolumes {
+ ctrNamedVolumes[vol.Name] = vol
+ }
+
+ if err := r.removeContainer(ctx, ctr, force, false, true); err != nil {
if removalErr != nil {
removalErr = err
} else {
@@ -246,6 +255,23 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
return err
}
+ for volName := range ctrNamedVolumes {
+ volume, err := r.state.Volume(volName)
+ if err != nil && errors.Cause(err) != define.ErrNoSuchVolume {
+ logrus.Errorf("Error retrieving volume %s: %v", volName, err)
+ continue
+ }
+ if !volume.IsCtrSpecific() {
+ continue
+ }
+ if err := r.removeVolume(ctx, volume, false); err != nil {
+ if errors.Cause(err) == define.ErrNoSuchVolume || errors.Cause(err) == define.ErrVolumeRemoved {
+ continue
+ }
+ logrus.Errorf("Error removing volume %s: %v", volName, err)
+ }
+ }
+
// Remove pod cgroup, if present
if p.state.CgroupPath != "" {
logrus.Debugf("Removing pod cgroup %s", p.state.CgroupPath)