Skip to content

Commit

Permalink
fix: prefix stripping in image import (#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofdrys authored Jun 30, 2022
1 parent 8e7cea6 commit aa40fdc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/client/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,17 @@ func isFile(image string) bool {
}

func dockerSpecialImageNameEqual(requestedImageName string, runtimeImageName string) bool {
if strings.HasPrefix(requestedImageName, "docker.io/") {
return dockerSpecialImageNameEqual(strings.TrimPrefix(requestedImageName, "docker.io/"), runtimeImageName)
prefixes := []string{
"docker.io/library/",
"docker.io/",
"library/",
}

if strings.HasPrefix(requestedImageName, "library/") {
return imageNamesEqual(strings.TrimPrefix(requestedImageName, "library/"), runtimeImageName)
for _, prefix := range prefixes {
if strings.HasPrefix(requestedImageName, prefix) {
return imageNamesEqual(strings.TrimPrefix(requestedImageName, prefix), runtimeImageName)
}

}

return false
Expand Down
11 changes: 11 additions & 0 deletions pkg/client/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Test_findRuntimeImage(T *testing.T) {
"registry:1234/one/two:latest",
"registry:1234/one/two/three/four:version",
"registry:1234/one/two/three/four:latest",
"one/two:latest",
}

tests := map[string]struct {
Expand Down Expand Up @@ -143,6 +144,16 @@ func Test_findRuntimeImage(T *testing.T) {
expectedFound: true,
givenRequestedImageName: "docker.io/library/busybox:version",
},
"docker.io is used as registry": {
expectedImageName: "one/two:latest",
expectedFound: true,
givenRequestedImageName: "docker.io/one/two:latest",
},
"docker.io is used as registry, no version tag": {
expectedImageName: "one/two:latest",
expectedFound: true,
givenRequestedImageName: "docker.io/one/two",
},
"unknown image": {
expectedFound: false,
givenRequestedImageName: "unknown",
Expand Down

0 comments on commit aa40fdc

Please sign in to comment.