diff --git a/scheduler/filter/affinity.go b/scheduler/filter/affinity.go index 342984bfb5..70ca420102 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, _ := parseRepositoryTag(tag) + images = append(images, repo) } } if affinity.Match(images...) { diff --git a/scheduler/filter/wrapper.go b/scheduler/filter/wrapper.go new file mode 100644 index 0000000000..e3a9b6605d --- /dev/null +++ b/scheduler/filter/wrapper.go @@ -0,0 +1,23 @@ +package filter + +import "strings" + +// Get a repos name and returns the right reposName + tag|digest +// The tag can be confusing because of a port in a repository name. +// Ex: localhost.localdomain:5000/samalba/hipache:latest +// Digest ex: localhost:5000/foo/bar@sha256:bc8813ea7b3603864987522f02a76101c17ad122e1c46d790efc0fca78ca7bfb +func parseRepositoryTag(repos string) (string, string) { + n := strings.Index(repos, "@") + if n >= 0 { + parts := strings.Split(repos, "@") + return parts[0], parts[1] + } + n = strings.LastIndex(repos, ":") + if n < 0 { + return repos, "" + } + if tag := repos[n+1:]; !strings.Contains(tag, "/") { + return repos[:n], tag + } + return repos, "" +} \ No newline at end of file diff --git a/scheduler/filter/wrapper_test.go b/scheduler/filter/wrapper_test.go new file mode 100644 index 0000000000..c71c9cea6e --- /dev/null +++ b/scheduler/filter/wrapper_test.go @@ -0,0 +1,24 @@ +package filter + +import "testing" + +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) + } +} \ No newline at end of file