summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libpod/container_inspect.go11
-rw-r--r--libpod/runtime_ctr.go8
-rw-r--r--pkg/specgen/generate/kube/kube.go16
-rw-r--r--pkg/specgen/generate/kube/kube_test.go42
-rw-r--r--test/system/070-build.bats21
5 files changed, 96 insertions, 2 deletions
diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go
index 07b28ba93..3df6203e3 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 0fdcc8255..fc1a688fb 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/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go
index 475401016..767589ead 100644
--- a/pkg/specgen/generate/kube/kube.go
+++ b/pkg/specgen/generate/kube/kube.go
@@ -322,7 +322,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
continue
}
- dest, options, err := parseMountPath(volume.MountPath, volume.ReadOnly)
+ dest, options, err := parseMountPath(volume.MountPath, volume.ReadOnly, volume.MountPropagation)
if err != nil {
return nil, err
}
@@ -388,7 +388,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
return s, nil
}
-func parseMountPath(mountPath string, readOnly bool) (string, []string, error) {
+func parseMountPath(mountPath string, readOnly bool, propagationMode *v1.MountPropagationMode) (string, []string, error) {
options := []string{}
splitVol := strings.Split(mountPath, ":")
if len(splitVol) > 2 {
@@ -408,6 +408,18 @@ func parseMountPath(mountPath string, readOnly bool) (string, []string, error) {
if err != nil {
return "", opts, errors.Wrapf(err, "parsing MountOptions")
}
+ if propagationMode != nil {
+ switch *propagationMode {
+ case v1.MountPropagationNone:
+ opts = append(opts, "private")
+ case v1.MountPropagationHostToContainer:
+ opts = append(opts, "rslave")
+ case v1.MountPropagationBidirectional:
+ opts = append(opts, "rshared")
+ default:
+ return "", opts, errors.Errorf("unknown propagation mode %q", *propagationMode)
+ }
+ }
return dest, opts, nil
}
diff --git a/pkg/specgen/generate/kube/kube_test.go b/pkg/specgen/generate/kube/kube_test.go
new file mode 100644
index 000000000..62793ebb6
--- /dev/null
+++ b/pkg/specgen/generate/kube/kube_test.go
@@ -0,0 +1,42 @@
+package kube
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ v1 "k8s.io/api/core/v1"
+ //"github.com/stretchr/testify/require"
+)
+
+func testPropagation(t *testing.T, propagation v1.MountPropagationMode, expected string) {
+ dest, options, err := parseMountPath("/to", false, &propagation)
+ assert.NoError(t, err)
+ assert.Equal(t, dest, "/to")
+ assert.Contains(t, options, expected)
+}
+
+func TestParseMountPathPropagation(t *testing.T) {
+ testPropagation(t, v1.MountPropagationNone, "private")
+ testPropagation(t, v1.MountPropagationHostToContainer, "rslave")
+ testPropagation(t, v1.MountPropagationBidirectional, "rshared")
+
+ prop := v1.MountPropagationMode("SpaceWave")
+ _, _, err := parseMountPath("/to", false, &prop)
+ assert.Error(t, err)
+
+ _, options, err := parseMountPath("/to", false, nil)
+ assert.NoError(t, err)
+ assert.NotContains(t, options, "private")
+ assert.NotContains(t, options, "rslave")
+ assert.NotContains(t, options, "rshared")
+}
+
+func TestParseMountPathRO(t *testing.T) {
+ _, options, err := parseMountPath("/to", true, nil)
+ assert.NoError(t, err)
+ assert.Contains(t, options, "ro")
+
+ _, options, err = parseMountPath("/to", false, nil)
+ assert.NoError(t, err)
+ assert.NotContains(t, options, "ro")
+}
diff --git a/test/system/070-build.bats b/test/system/070-build.bats
index a95acd986..c963d8325 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 <<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