fix soft filter

Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
Xian Chaobo 2015-10-08 05:16:19 -04:00
parent 03714f66d1
commit c6fb10cec3
4 changed files with 33 additions and 2 deletions

View File

@ -64,7 +64,7 @@ func (f *AffinityFilter) Filter(config *cluster.ContainerConfig, nodes []*node.N
}
if len(candidates) == 0 {
if affinity.isSoft {
return nodes, nil
continue
}
return nil, fmt.Errorf("unable to find a node that satisfies %s%s%s", affinity.key, OPERATORS[affinity.operator], affinity.value)
}

View File

@ -43,7 +43,7 @@ func (f *ConstraintFilter) Filter(config *cluster.ContainerConfig, nodes []*node
}
if len(candidates) == 0 {
if constraint.isSoft {
return nodes, nil
continue
}
return nil, fmt.Errorf("unable to find a node that satisfies %s%s%s", constraint.key, OPERATORS[constraint.operator], constraint.value)
}

View File

@ -125,3 +125,18 @@ function teardown() {
[ "$status" -eq 0 ]
[[ "${output}" != *'"Name": "node-1"'* ]]
}
@test "soft affinity" {
start_docker_with_busybox 2
# Create a new image just on the second host.
docker -H ${HOSTS[1]} tag busybox test
swarm_manage
docker_swarm run --name c1 -e affinity:image==~not_exist -e affinity:image==test -d busybox:latest sh
run docker_swarm inspect c1
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-1"'* ]]
}

View File

@ -39,6 +39,22 @@ function teardown() {
[[ "${output}" == *'"Name": "node-1"'* ]]
}
@test "soft constraint" {
start_docker_with_busybox 2
swarm_manage
docker_swarm run --name c1 -e constraint:storagedriver==~not_exist -e constraint:node==node-0 -d busybox:latest sh
docker_swarm run --name c2 -e constraint:storagedriver==~not_exist -e constraint:node==node-0 -d busybox:latest sh
run docker_swarm inspect c1
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-0"'* ]]
run docker_swarm inspect c2
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-0"'* ]]
}
@test "label constraints" {
start_docker_with_busybox 1 --label foo=a
start_docker_with_busybox 1 --label foo=b