mirror of https://github.com/docker/docs.git
do not try retry with soft-image-affinity when have node constraint
Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
parent
03714f66d1
commit
315ddfeb4d
|
@ -158,3 +158,15 @@ func (c *ContainerConfig) AddAffinity(affinity string) error {
|
|||
c.Labels[SwarmLabelNamespace+".affinities"] = string(labels)
|
||||
return nil
|
||||
}
|
||||
|
||||
// HaveNodeConstraint in config
|
||||
func (c *ContainerConfig) HaveNodeConstraint() bool {
|
||||
constraints := c.extractExprs("constraints")
|
||||
|
||||
for _, constraint := range constraints {
|
||||
if strings.HasPrefix(constraint, "node==") && !strings.HasPrefix(constraint, "node==~") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -89,3 +89,11 @@ func TestAddAffinity(t *testing.T) {
|
|||
config.AddAffinity("image==~testimage")
|
||||
assert.Len(t, config.Affinities(), 1)
|
||||
}
|
||||
|
||||
func TestHaveNodeConstraint(t *testing.T) {
|
||||
config := BuildContainerConfig(dockerclient.ContainerConfig{})
|
||||
assert.False(t, config.HaveNodeConstraint())
|
||||
|
||||
config = BuildContainerConfig(dockerclient.ContainerConfig{Env: []string{"constraint:node==node1"}})
|
||||
assert.True(t, config.HaveNodeConstraint())
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ func (c *Cluster) CreateContainer(config *cluster.ContainerConfig, name string)
|
|||
container, err := c.createContainer(config, name, false)
|
||||
|
||||
// fails with image not found, then try to reschedule with soft-image-affinity
|
||||
if err != nil && strings.HasSuffix(err.Error(), "not found") {
|
||||
if err != nil && strings.HasSuffix(err.Error(), "not found") && !config.HaveNodeConstraint() {
|
||||
// Check if the image exists in the cluster
|
||||
// If exists, retry with a soft-image-affinity
|
||||
if image := c.Image(config.Image); image != nil {
|
||||
|
|
|
@ -88,3 +88,25 @@ function teardown() {
|
|||
run docker_swarm ps
|
||||
[[ "${output}" == *"node-0/test_container"* ]]
|
||||
}
|
||||
|
||||
@test "docker run - reschedule with soft-image-affinity(have node constraint))" {
|
||||
start_docker_with_busybox 1
|
||||
start_docker 1
|
||||
|
||||
docker -H ${HOSTS[0]} tag busybox:latest busyboxabcde:latest
|
||||
swarm_manage
|
||||
|
||||
# make sure busyboxabcde exists
|
||||
run docker_swarm images
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${output}" == *"busyboxabcde"* ]]
|
||||
|
||||
# create container on node-1, node-1 does not have busyboxabcde and will pull it
|
||||
# but can not find busyboxabcde in dockerhub
|
||||
# because run with node constraint, will not retry with soft-image-affinity
|
||||
run docker_swarm run -d --name test_container -e constraint:node==node-1 busyboxabcde sleep 1000
|
||||
|
||||
# check error message
|
||||
[[ "${output}" != *"unable to find a node that satisfies"* ]]
|
||||
[[ "${output}" == *"busyboxabcde:latest not found"* ]]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue