Skip to content

Commit

Permalink
Fix for #831 - Ignore domain when finding the image tag
Browse files Browse the repository at this point in the history
  • Loading branch information
narayanan committed Mar 2, 2019
1 parent 16d1b20 commit eb75203
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/transformers/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,18 @@ func isImageMatched(s, t string) bool {
// from the image string using either colon `:` or at `@` separators.
// Note that the returned tag keeps its separator.
func split(imageName string) (name string, tag string) {
ic := strings.LastIndex(imageName, ":")
// check if image name contains a domain
// if domain is present, ignore domain and check for `:`
ic := -1
if slashIndex := strings.Index(imageName, "/"); slashIndex < 0 {
ic = strings.LastIndex(imageName, ":")
} else {
lastIc := strings.LastIndex(imageName[slashIndex:], ":")
// set ic only if `:` is present
if lastIc > 0 {
ic = slashIndex + lastIc
}
}
ia := strings.LastIndex(imageName, "@")
if ic < 0 && ia < 0 {
return imageName, ""
Expand Down
8 changes: 8 additions & 0 deletions pkg/transformers/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func TestImageTransformer(t *testing.T) {
"name": "myimage",
"image": "myprivaterepohostname:1234/my/image:latest",
},
map[string]interface{}{
"name": "myimage2",
"image": "myprivaterepohostname:1234/my/image",
},
map[string]interface{}{
"name": "my-app",
"image": "my-app-image:v1",
Expand Down Expand Up @@ -218,6 +222,10 @@ func TestImageTransformer(t *testing.T) {
"name": "myimage",
"image": "myprivaterepohostname:1234/my/image:v1.0.1",
},
map[string]interface{}{
"name": "myimage2",
"image": "myprivaterepohostname:1234/my/image:v1.0.1",
},
map[string]interface{}{
"name": "my-app",
"image": "gcr.io/my-project/my-app-image:v1",
Expand Down

0 comments on commit eb75203

Please sign in to comment.