mirror of https://github.com/docker/docs.git
fix images affinity
Signed-off-by: 易嘉 <changhai.ych@alibaba-inc.com>
This commit is contained in:
parent
cc4eea83da
commit
686f743856
|
@ -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...) {
|
||||
|
|
|
@ -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, ""
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue