Skip to content

Commit

Permalink
containerd handle localhost and 127.0.0.1 registry hosts
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Plock <chrisplo@appdynamics.com>
  • Loading branch information
chrisplo committed Dec 18, 2024
1 parent 3984f6f commit 776467f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/image/containerd/daemon_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,16 @@ func withMetadata(platform *platforms.Platform, ref string) (metadata []image.Ad
// if image doesn't have host set, add docker hub by default
func checkRegistryHostMissing(imageName string) string {
parts := strings.Split(imageName, "/")
if len(parts) == 1 {
switch {
case len(parts) == 0:
return imageName
case len(parts) == 1:
return fmt.Sprintf("docker.io/library/%s", imageName)
} else if len(parts) > 1 && !strings.Contains(parts[0], ".") {
case strings.Contains(parts[0], ".") || strings.Contains(parts[0], ":"):
return imageName
case parts[0] == "localhost" || parts[0] == "127.0.0.1":
return imageName
default:
return fmt.Sprintf("docker.io/%s", imageName)
}
return imageName
}
16 changes: 16 additions & 0 deletions pkg/image/containerd/daemon_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ func Test_checkRegistryHostMissing(t *testing.T) {
image: "registry.place.io/thing:version",
want: "registry.place.io/thing:version",
},
{
image: "127.0.0.1/thing:version",
want: "127.0.0.1/thing:version",
},
{
image: "127.0.0.1:1234/thing:version",
want: "127.0.0.1:1234/thing:version",
},
{
image: "localhost/thing:version",
want: "localhost/thing:version",
},
{
image: "localhost:1234/thing:version",
want: "localhost:1234/thing:version",
},
{
image: "alpine@sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209",
want: "docker.io/library/alpine@sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209",
Expand Down

0 comments on commit 776467f

Please sign in to comment.