mirror of
https://github.com/containers/podman.git
synced 2025-08-06 11:32:07 +08:00
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 <dwalsh@redhat.com>
This commit is contained in:

committed by
Matthew Heon

parent
eb9fe52a55
commit
ee7cf3cc2c
@ -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
|
||||
|
@ -768,6 +768,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)
|
||||
}
|
||||
}
|
||||
|
@ -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 <<EOF
|
||||
FROM $IMAGE
|
||||
VOLUME /vol
|
||||
EOF
|
||||
|
||||
run_podman build -t build_test $tmpdir
|
||||
is "$output" ".*COMMIT" "COMMIT seen in log"
|
||||
|
||||
run_podman run -d --name test_ctr build_test top
|
||||
run_podman run --rm --volumes-from test_ctr $IMAGE echo $rand_content
|
||||
is "$output" "$rand_content" "No error should be thrown about volume in use"
|
||||
|
||||
run_podman rmi -f build_test
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
# A timeout or other error in 'build' can leave behind stale images
|
||||
# that podman can't even see and which will cascade into subsequent
|
||||
|
Reference in New Issue
Block a user