diff --git a/cluster/image_test.go b/cluster/image_test.go index 410fba1203..2648664a4d 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 70ca420102..6bc458d586 100644 --- a/scheduler/filter/affinity.go +++ b/scheduler/filter/affinity.go @@ -50,7 +50,7 @@ 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 { - repo, _ := parseRepositoryTag(tag) + repo, _ := cluster.ParseRepositoryTag(tag) images = append(images, repo) } } diff --git a/scheduler/filter/wrapper.go b/scheduler/filter/wrapper.go deleted file mode 100644 index e3a9b6605d..0000000000 --- a/scheduler/filter/wrapper.go +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index c71c9cea6e..0000000000 --- a/scheduler/filter/wrapper_test.go +++ /dev/null @@ -1,24 +0,0 @@ -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