Skip to content

Commit eb75203

Browse files
committed
Fix for #831 - Ignore domain when finding the image tag
1 parent 16d1b20 commit eb75203

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pkg/transformers/image.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,18 @@ func isImageMatched(s, t string) bool {
143143
// from the image string using either colon `:` or at `@` separators.
144144
// Note that the returned tag keeps its separator.
145145
func split(imageName string) (name string, tag string) {
146-
ic := strings.LastIndex(imageName, ":")
146+
// check if image name contains a domain
147+
// if domain is present, ignore domain and check for `:`
148+
ic := -1
149+
if slashIndex := strings.Index(imageName, "/"); slashIndex < 0 {
150+
ic = strings.LastIndex(imageName, ":")
151+
} else {
152+
lastIc := strings.LastIndex(imageName[slashIndex:], ":")
153+
// set ic only if `:` is present
154+
if lastIc > 0 {
155+
ic = slashIndex + lastIc
156+
}
157+
}
147158
ia := strings.LastIndex(imageName, "@")
148159
if ic < 0 && ia < 0 {
149160
return imageName, ""

pkg/transformers/image_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ func TestImageTransformer(t *testing.T) {
118118
"name": "myimage",
119119
"image": "myprivaterepohostname:1234/my/image:latest",
120120
},
121+
map[string]interface{}{
122+
"name": "myimage2",
123+
"image": "myprivaterepohostname:1234/my/image",
124+
},
121125
map[string]interface{}{
122126
"name": "my-app",
123127
"image": "my-app-image:v1",
@@ -218,6 +222,10 @@ func TestImageTransformer(t *testing.T) {
218222
"name": "myimage",
219223
"image": "myprivaterepohostname:1234/my/image:v1.0.1",
220224
},
225+
map[string]interface{}{
226+
"name": "myimage2",
227+
"image": "myprivaterepohostname:1234/my/image:v1.0.1",
228+
},
221229
map[string]interface{}{
222230
"name": "my-app",
223231
"image": "gcr.io/my-project/my-app-image:v1",

0 commit comments

Comments
 (0)