From eb752039266a20ce0ad9e868309a7fc1b9b8f5b6 Mon Sep 17 00:00:00 2001 From: Narayanan Singaram Date: Fri, 1 Mar 2019 23:23:32 -0800 Subject: [PATCH] Fix for #831 - Ignore domain when finding the image tag --- pkg/transformers/image.go | 13 ++++++++++++- pkg/transformers/image_test.go | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/transformers/image.go b/pkg/transformers/image.go index 734b5aca75..2e07976943 100644 --- a/pkg/transformers/image.go +++ b/pkg/transformers/image.go @@ -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, "" diff --git a/pkg/transformers/image_test.go b/pkg/transformers/image_test.go index f1bf18351b..c62ba34329 100644 --- a/pkg/transformers/image_test.go +++ b/pkg/transformers/image_test.go @@ -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", @@ -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",