Commit 967dc423 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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
parents 79ed7064 cc9f41c6
...@@ -167,11 +167,20 @@ func matchImageTagOrSHA(inspected dockertypes.ImageInspect, image string) bool { ...@@ -167,11 +167,20 @@ func matchImageTagOrSHA(inspected dockertypes.ImageInspect, image string) bool {
return true return true
} }
if isTagged { if isTagged {
hostname, _ := dockerref.SplitHostname(named)
// Check the RepoTags for an exact match // Check the RepoTags for an exact match
for _, tag := range inspected.RepoTags { for _, tag := range inspected.RepoTags {
if tag == image { // Deal with image with hostname specified
// We found a specific tag that we were looking for if len(hostname) > 0 {
return true if strings.HasSuffix(image, tag) {
return true
}
} else {
if tag == image {
// We found a specific tag that we were looking for
return true
}
} }
} }
} }
......
...@@ -174,6 +174,16 @@ func TestMatchImageTagOrSHA(t *testing.T) { ...@@ -174,6 +174,16 @@ func TestMatchImageTagOrSHA(t *testing.T) {
Output: false, 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{ Inspected: dockertypes.ImageInspect{
ID: "sha256:2208f7a29005d226d1ee33a63e33af1f47af6156c740d7d23c7948e8d282d53d", ID: "sha256:2208f7a29005d226d1ee33a63e33af1f47af6156c740d7d23c7948e8d282d53d",
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment