Merge pull request #30582 from dims/fix-issue-30580

Automatic merge from submit-queue

Fix image verification when hostname is present in image

Deal better with the situation where a image name contains
a hostname as well.

Fixes #30580
This commit is contained in:
Kubernetes Submit Queue 2016-08-15 14:26:05 -07:00 committed by GitHub
commit 967dc4234a
2 changed files with 22 additions and 3 deletions

View File

@ -167,11 +167,20 @@ func matchImageTagOrSHA(inspected dockertypes.ImageInspect, image string) bool {
return true
}
if isTagged {
hostname, _ := dockerref.SplitHostname(named)
// Check the RepoTags for an exact match
for _, tag := range inspected.RepoTags {
if tag == image {
// We found a specific tag that we were looking for
return true
// Deal with image with hostname specified
if len(hostname) > 0 {
if strings.HasSuffix(image, tag) {
return true
}
} else {
if tag == image {
// We found a specific tag that we were looking for
return true
}
}
}
}

View File

@ -173,6 +173,16 @@ func TestMatchImageTagOrSHA(t *testing.T) {
Image: "ubuntu:latest",
Output: false,
},
{
Inspected: dockertypes.ImageInspect{RepoTags: []string{"colemickens/hyperkube-amd64:217.9beff63"}},
Image: "colemickens/hyperkube-amd64:217.9beff63",
Output: true,
},
{
Inspected: dockertypes.ImageInspect{RepoTags: []string{"colemickens/hyperkube-amd64:217.9beff63"}},
Image: "docker.io/colemickens/hyperkube-amd64:217.9beff63",
Output: true,
},
{
Inspected: dockertypes.ImageInspect{
ID: "sha256:2208f7a29005d226d1ee33a63e33af1f47af6156c740d7d23c7948e8d282d53d",