Skip to content

Commit e94ae1a

Browse files
committed
containerd handle localhost and 127.0.0.1 registry hosts
Signed-off-by: Chris Plock <chrisplo@cisco.com>
1 parent 3984f6f commit e94ae1a

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

pkg/image/containerd/daemon_provider.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,16 @@ func withMetadata(platform *platforms.Platform, ref string) (metadata []image.Ad
507507
// if image doesn't have host set, add docker hub by default
508508
func checkRegistryHostMissing(imageName string) string {
509509
parts := strings.Split(imageName, "/")
510-
if len(parts) == 1 {
510+
switch {
511+
case len(parts) == 0:
512+
return imageName
513+
case len(parts) == 1:
511514
return fmt.Sprintf("docker.io/library/%s", imageName)
512-
} else if len(parts) > 1 && !strings.Contains(parts[0], ".") {
515+
case strings.Contains(parts[0], ".") || strings.Contains(parts[0], ":"):
516+
return imageName
517+
case parts[0] == "localhost":
518+
return imageName
519+
default:
513520
return fmt.Sprintf("docker.io/%s", imageName)
514521
}
515-
return imageName
516522
}

pkg/image/containerd/daemon_provider_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ func Test_checkRegistryHostMissing(t *testing.T) {
3232
image: "registry.place.io/thing:version",
3333
want: "registry.place.io/thing:version",
3434
},
35+
{
36+
image: "127.0.0.1/thing:version",
37+
want: "127.0.0.1/thing:version",
38+
},
39+
{
40+
image: "127.0.0.1:1234/thing:version",
41+
want: "127.0.0.1:1234/thing:version",
42+
},
43+
{
44+
image: "localhost/thing:version",
45+
want: "localhost/thing:version",
46+
},
47+
{
48+
image: "localhost:1234/thing:version",
49+
want: "localhost:1234/thing:version",
50+
},
3551
{
3652
image: "alpine@sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209",
3753
want: "docker.io/library/alpine@sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209",

0 commit comments

Comments
 (0)