Merge pull request #1715 from vieux/1676-fiximageaffinity

Fix images affinity for local registry and digest
This commit is contained in:
Victor Vieux 2016-02-01 13:01:29 -08:00
commit 36e1fbdd77
3 changed files with 43 additions and 3 deletions

View File

@ -123,3 +123,24 @@ func TestImagesFilterWithNameFilterWithTag(t *testing.T) {
})
assert.Equal(t, len(result), 2)
}
func TestParseRepositoryTag(t *testing.T) {
repo, tag := ParseRepositoryTag("localhost.localdomain:5000/samalba/hipache:latest")
if tag != "latest" {
t.Errorf("repo=%s tag=%s", repo, tag)
}
repo, tag = ParseRepositoryTag("localhost:5000/foo/bar@sha256:bc8813ea7b3603864987522f02a76101c17ad122e1c46d790efc0fca78ca7bfb")
if tag != "sha256:bc8813ea7b3603864987522f02a76101c17ad122e1c46d790efc0fca78ca7bfb" {
t.Logf("repo=%s tag=%s", repo, tag)
}
repo, tag = ParseRepositoryTag("localhost:5000/foo/bar")
if tag != "" {
t.Logf("repo=%s tag=%s", repo, tag)
}
repo, tag = ParseRepositoryTag("localhost:5000/foo/bar:latest")
t.Logf("repo=%s tag=%s", repo, tag)
if tag != "latest" {
t.Logf("repo=%s tag=%s", repo, tag)
}
}

View File

@ -50,7 +50,8 @@ func (f *AffinityFilter) Filter(config *cluster.ContainerConfig, nodes []*node.N
images = append(images, image.Id)
images = append(images, image.RepoTags...)
for _, tag := range image.RepoTags {
images = append(images, strings.Split(tag, ":")[0])
repo, _ := cluster.ParseRepositoryTag(tag)
images = append(images, repo)
}
}
if affinity.Match(images...) {

View File

@ -68,8 +68,6 @@ function teardown() {
[ "$status" -eq 0 ]
run docker_swarm inspect c1
# FIXME: This will help debugging the failing test.
echo $output
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-1"'* ]]
@ -86,6 +84,26 @@ function teardown() {
[[ "${output}" != *'"Name": "node-1"'* ]]
}
@test "images affinity - local registry" {
start_docker_with_busybox 2
swarm_manage
# Create a new image just on the second host.
run docker -H ${HOSTS[1]} tag busybox localhost:5000/test
# pull busybox to force the refresh images
# FIXME: this is slow.
run docker_swarm pull busybox
[ "$status" -eq 0 ]
run docker_swarm run --name c1 -e affinity:image==localhost:5000/test -d busybox:latest sh
[ "$status" -eq 0 ]
run docker_swarm inspect c1
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-1"'* ]]
}
@test "label affinity" {
start_docker_with_busybox 2
swarm_manage