mirror of https://github.com/docker/docs.git
fix #807: support --volumes-from rw/ro
Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
parent
9d914b16b1
commit
b94d6baf2b
|
@ -22,6 +22,11 @@ func (f *DependencyFilter) Filter(config *cluster.ContainerConfig, nodes []*node
|
|||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
// Volumes
|
||||
volumes := []string{}
|
||||
for _, volume := range config.HostConfig.VolumesFrom {
|
||||
volumes = append(volumes, strings.SplitN(volume, ":", 2)[0])
|
||||
}
|
||||
|
||||
// Extract containers from links.
|
||||
links := []string{}
|
||||
|
@ -37,7 +42,7 @@ func (f *DependencyFilter) Filter(config *cluster.ContainerConfig, nodes []*node
|
|||
|
||||
candidates := []*node.Node{}
|
||||
for _, node := range nodes {
|
||||
if f.check(config.HostConfig.VolumesFrom, node) &&
|
||||
if f.check(volumes, node) &&
|
||||
f.check(links, node) &&
|
||||
f.check(net, node) {
|
||||
candidates = append(candidates, node)
|
||||
|
|
|
@ -54,6 +54,24 @@ func TestDependencyFilterSimple(t *testing.T) {
|
|||
assert.Len(t, result, 1)
|
||||
assert.Equal(t, result[0], nodes[0])
|
||||
|
||||
// volumes-from:rw
|
||||
config = &cluster.ContainerConfig{dockerclient.ContainerConfig{HostConfig: dockerclient.HostConfig{
|
||||
VolumesFrom: []string{"c0:rw"},
|
||||
}}}
|
||||
result, err = f.Filter(config, nodes)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, result, 1)
|
||||
assert.Equal(t, result[0], nodes[0])
|
||||
|
||||
// volumes-from:ro
|
||||
config = &cluster.ContainerConfig{dockerclient.ContainerConfig{HostConfig: dockerclient.HostConfig{
|
||||
VolumesFrom: []string{"c0:ro"},
|
||||
}}}
|
||||
result, err = f.Filter(config, nodes)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, result, 1)
|
||||
assert.Equal(t, result[0], nodes[0])
|
||||
|
||||
// link.
|
||||
config = &cluster.ContainerConfig{dockerclient.ContainerConfig{HostConfig: dockerclient.HostConfig{
|
||||
Links: []string{"c1:foobar"},
|
||||
|
|
|
@ -32,15 +32,62 @@ function teardown() {
|
|||
[[ "${output}" == *'"Name": "node-1"'* ]]
|
||||
}
|
||||
|
||||
@test "shared volumes(rw) dependency" {
|
||||
start_docker_with_busybox 2
|
||||
swarm_manage
|
||||
|
||||
# Running the second container with shared volumes.
|
||||
docker_swarm run --name b1 -e constraint:node==node-1 -d busybox:latest sleep 500
|
||||
|
||||
docker_swarm run --name b2 --volumes-from=/b1:rw -d busybox:latest sh
|
||||
|
||||
# check if containers share volume.
|
||||
run docker_swarm inspect -f "{{ .HostConfig.VolumesFrom }}" b2
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${output}" == *"[/b1:rw]"* ]]
|
||||
|
||||
# check if both containers are started on the same node
|
||||
run docker_swarm inspect b1
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${output}" == *'"Name": "node-1"'* ]]
|
||||
|
||||
run docker_swarm inspect b2
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${output}" == *'"Name": "node-1"'* ]]
|
||||
}
|
||||
|
||||
@test "shared volumes(ro) dependency" {
|
||||
start_docker_with_busybox 2
|
||||
swarm_manage
|
||||
|
||||
# Running the second container with shared volumes.
|
||||
docker_swarm run --name b1 -e constraint:node==node-1 -d busybox:latest sleep 500
|
||||
|
||||
docker_swarm run --name b2 --volumes-from=/b1:ro -d busybox:latest sh
|
||||
|
||||
# check if containers share volume.
|
||||
run docker_swarm inspect -f "{{ .HostConfig.VolumesFrom }}" b2
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${output}" == *"[/b1:ro]"* ]]
|
||||
|
||||
# check if both containers are started on the same node
|
||||
run docker_swarm inspect b1
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${output}" == *'"Name": "node-1"'* ]]
|
||||
|
||||
run docker_swarm inspect b2
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${output}" == *'"Name": "node-1"'* ]]
|
||||
}
|
||||
|
||||
@test "links dependency" {
|
||||
start_docker_with_busybox 2
|
||||
swarm_manage
|
||||
|
||||
# Running the second container with link dependency.
|
||||
run docker_swarm run --name b1 -e constraint:node==node-1 -d busybox:latest sleep 500
|
||||
[ "$status" -eq 0 ]
|
||||
run docker_swarm run --name b2 --link=/b1:foo -d busybox:latest sh
|
||||
[ "$status" -eq 0 ]
|
||||
docker_swarm run --name b1 -e constraint:node==node-1 -d busybox:latest sleep 500
|
||||
|
||||
docker_swarm run --name b2 --link=/b1:foo -d busybox:latest sh
|
||||
|
||||
# check if containers share link.
|
||||
run docker_swarm inspect -f "{{ .HostConfig.Links }}" b2
|
||||
|
@ -62,10 +109,9 @@ function teardown() {
|
|||
swarm_manage
|
||||
|
||||
# Running the second container with network stack dependency.
|
||||
run docker_swarm run --name b1 -e constraint:node==node-1 -d busybox:latest sleep 500
|
||||
[ "$status" -eq 0 ]
|
||||
docker_swarm run --name b1 -e constraint:node==node-1 -d busybox:latest sleep 500
|
||||
|
||||
run docker_swarm run --name b2 --net=container:/b1 -d busybox:latest sh
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# check if containers have shared network stack.
|
||||
run docker_swarm inspect -f "{{ .HostConfig.NetworkMode }}" b2
|
||||
|
|
Loading…
Reference in New Issue