From 95f373fde6f04ebced1df3c92859a8c6d9076ad8 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Wed, 27 Sep 2017 17:03:54 -0400 Subject: [PATCH] Normalize RepoTags before checking for match on projectatomic-based docker, we get "docker.io/library/busybox:latest" when someone uses an unqualified name like "busybox". Though when we inspect, the RepoTag will still say "docker.io/busybox:latest", So we have reparse the tag, normalize it and try again. Please see the additional test case. Signed-off-by: Andy Goldstein --- pkg/kubelet/dockershim/libdocker/helpers.go | 32 +++++++++++++++++++ .../dockershim/libdocker/helpers_test.go | 8 +++++ 2 files changed, 40 insertions(+) diff --git a/pkg/kubelet/dockershim/libdocker/helpers.go b/pkg/kubelet/dockershim/libdocker/helpers.go index a1390a3c1261..f8a785cbd0a4 100644 --- a/pkg/kubelet/dockershim/libdocker/helpers.go +++ b/pkg/kubelet/dockershim/libdocker/helpers.go @@ -60,6 +60,38 @@ func matchImageTagOrSHA(inspected dockertypes.ImageInspect, image string) bool { // hostname or not, we only check for the suffix match. if strings.HasSuffix(image, tag) || strings.HasSuffix(tag, image) { return true + } else { + // TODO: We need to remove this hack when project atomic based + // docker distro(s) like centos/fedora/rhel image fix problems on + // their end. + // Say the tag is "docker.io/busybox:latest" + // and the image is "docker.io/library/busybox:latest" + t, err := dockerref.ParseNormalizedNamed(tag) + if err != nil { + continue + } + // the parsed/normalized tag will look like + // reference.taggedReference { + // namedRepository: reference.repository { + // domain: "docker.io", + // path: "library/busybox" + // }, + // tag: "latest" + // } + // If it does not have tags then we bail out + t2, ok := t.(dockerref.Tagged) + if !ok { + continue + } + // normalized tag would look like "docker.io/library/busybox:latest" + // note the library get added in the string + normalizedTag := t2.String() + if normalizedTag == "" { + continue + } + if strings.HasSuffix(image, normalizedTag) || strings.HasSuffix(normalizedTag, image) { + return true + } } } } diff --git a/pkg/kubelet/dockershim/libdocker/helpers_test.go b/pkg/kubelet/dockershim/libdocker/helpers_test.go index 03e0046b9fc8..546a604c9ad4 100644 --- a/pkg/kubelet/dockershim/libdocker/helpers_test.go +++ b/pkg/kubelet/dockershim/libdocker/helpers_test.go @@ -101,6 +101,14 @@ func TestMatchImageTagOrSHA(t *testing.T) { Image: "centos/ruby-23-centos7@sha256:940584acbbfb0347272112d2eb95574625c0c60b4e2fdadb139de5859cf754bf", Output: true, }, + { + Inspected: dockertypes.ImageInspect{ + ID: "sha256:9bbdf247c91345f0789c10f50a57e36a667af1189687ad1de88a6243d05a2227", + RepoTags: []string{"docker.io/busybox:latest"}, + }, + Image: "docker.io/library/busybox:latest", + Output: true, + }, { // RepoDigest match is is required Inspected: dockertypes.ImageInspect{