diff --git a/cluster/image_test.go b/cluster/image_test.go index 410fba1203..a07185734c 100644 --- a/cluster/image_test.go +++ b/cluster/image_test.go @@ -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) + } +} diff --git a/scheduler/filter/affinity.go b/scheduler/filter/affinity.go index 342984bfb5..6bc458d586 100644 --- a/scheduler/filter/affinity.go +++ b/scheduler/filter/affinity.go @@ -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...) { diff --git a/test/integration/affinities.bats b/test/integration/affinities.bats index 055a73c1fe..d647a9d58c 100644 --- a/test/integration/affinities.bats +++ b/test/integration/affinities.bats @@ -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