mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 20:17:41 +00:00
Merge pull request #30789 from yujuhong/image_match
Automatic merge from submit-queue Fix image inspection and matching An image string could contain a hostname (e.g., "docker.io") or not. The same applies to the RepoTags returned from an image inspection. To determine whether the image docker pulled matches what the user ask for, we check if the either string is the suffix of the other. /cc @dims @dchen1107 @Random-Liu This fixes #30710
This commit is contained in:
commit
7b3c08d7d3
@ -166,24 +166,19 @@ func matchImageTagOrSHA(inspected dockertypes.ImageInspect, image string) bool {
|
||||
// No Tag or SHA specified, so just return what we have
|
||||
return true
|
||||
}
|
||||
if isTagged {
|
||||
hostname, _ := dockerref.SplitHostname(named)
|
||||
// Check the RepoTags for an exact match
|
||||
for _, tag := range inspected.RepoTags {
|
||||
// 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
|
||||
}
|
||||
if isTagged {
|
||||
// Check the RepoTags for a match.
|
||||
for _, tag := range inspected.RepoTags {
|
||||
// An image name (without the tag/digest) can be [hostname '/'] component ['/' component]*
|
||||
// Because either the RepoTag or the name *may* contain the
|
||||
// hostname or not, we only check for the suffix match.
|
||||
if strings.HasSuffix(image, tag) || strings.HasSuffix(tag, image) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if isDigested {
|
||||
algo := digest.Digest().Algorithm().String()
|
||||
sha := digest.Digest().Hex()
|
||||
|
@ -183,6 +183,11 @@ func TestMatchImageTagOrSHA(t *testing.T) {
|
||||
Image: "docker.io/colemickens/hyperkube-amd64:217.9beff63",
|
||||
Output: true,
|
||||
},
|
||||
{
|
||||
Inspected: dockertypes.ImageInspect{RepoTags: []string{"docker.io/kubernetes/pause:latest"}},
|
||||
Image: "kubernetes/pause:latest",
|
||||
Output: true,
|
||||
},
|
||||
{
|
||||
Inspected: dockertypes.ImageInspect{
|
||||
ID: "sha256:2208f7a29005d226d1ee33a63e33af1f47af6156c740d7d23c7948e8d282d53d",
|
||||
|
Loading…
Reference in New Issue
Block a user