From ea52fb675c618d1ce50ebe0a6299657a74feb321 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 14 Feb 2022 15:43:52 -0500 Subject: [PATCH] Don't log errors on removing volumes inuse, if container --volumes-from When removing a container created with a --volumes-from a container created with a built in volume, we complain if the original container still exists. Since this is an expected state, we should not complain about it. Fixes: https://github.com/containers/podman/issues/12808 Signed-off-by: Daniel J Walsh Signed-off-by: Krzysztof Baran --- libpod/container_inspect.go | 11 +++++++++++ libpod/runtime_ctr.go | 8 ++++++++ test/system/070-build.bats | 21 +++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go index 07b28ba93ec5..3df6203e3b38 100644 --- a/libpod/container_inspect.go +++ b/libpod/container_inspect.go @@ -51,6 +51,17 @@ func (c *Container) Inspect(size bool) (*define.InspectContainerData, error) { return c.inspectLocked(size) } +func (c *Container) volumesFrom() ([]string, error) { + ctrSpec, err := c.specFromState() + if err != nil { + return nil, err + } + if ctrs, ok := ctrSpec.Annotations[define.InspectAnnotationVolumesFrom]; ok { + return strings.Split(ctrs, ","), nil + } + return nil, nil +} + func (c *Container) getContainerInspectData(size bool, driverData *define.DriverData) (*define.InspectContainerData, error) { config := c.config runtimeInfo := c.state diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 0fdcc8255261..fc1a688fb638 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -762,6 +762,14 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force, remo continue } if err := runtime.removeVolume(ctx, volume, false, timeout); err != nil && errors.Cause(err) != define.ErrNoSuchVolume { + if errors.Cause(err) == define.ErrVolumeBeingUsed { + // Ignore error, since podman will report original error + volumesFrom, _ := c.volumesFrom() + if len(volumesFrom) > 0 { + logrus.Debugf("Cleanup volume not possible since volume is in use (%s)", v) + continue + } + } logrus.Errorf("Cleanup volume (%s): %v", v, err) } } diff --git a/test/system/070-build.bats b/test/system/070-build.bats index a95acd9867ea..c963d8325f83 100644 --- a/test/system/070-build.bats +++ b/test/system/070-build.bats @@ -1016,6 +1016,27 @@ EOF run_podman build -t build_test $tmpdir/link } +@test "podman build --volumes-from conflict" { + rand_content=$(random_string 50) + + tmpdir=$PODMAN_TMPDIR/build-test + mkdir -p $tmpdir + dockerfile=$tmpdir/Dockerfile + cat >$dockerfile <