Skip to content

Commit fed5d71

Browse files
authored
Prevent unnecessary application of default repository (#4817)
1 parent 558dfa0 commit fed5d71

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pkg/skaffold/docker/default_repo.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ func SubstituteDefaultRepoIntoImage(defaultRepo string, image string) (string, e
5050
}
5151

5252
func replace(defaultRepo string, baseImage string) string {
53+
if strings.HasPrefix(baseImage, defaultRepo) {
54+
return baseImage
55+
}
5356
originalPrefix := prefixRegex.FindString(baseImage)
5457
defaultRepoPrefix := prefixRegex.FindString(defaultRepo)
5558
if originalPrefix != "" && defaultRepoPrefix != "" {
5659
// prefixes match
5760
if originalPrefix == defaultRepoPrefix {
5861
return defaultRepo + "/" + baseImage[len(originalPrefix):]
5962
}
60-
if strings.HasPrefix(baseImage, defaultRepo) {
61-
return baseImage
62-
}
6363
// prefixes don't match, concatenate and truncate
6464
return truncate(defaultRepo + "/" + baseImage)
6565
}

pkg/skaffold/docker/default_repo_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ func TestImageReplaceDefaultRepo(t *testing.T) {
7777
defaultRepo: "gcr.io/k8s-skaffold",
7878
expectedImage: "gcr.io/k8s-skaffold/skaffold-example",
7979
},
80+
{
81+
description: "image has shared prefix with defaultRepo, but not gcr",
82+
image: "myrepo/skaffold-example",
83+
defaultRepo: "myrepo",
84+
expectedImage: "myrepo/skaffold-example",
85+
},
8086
{
8187
description: "keep tag",
8288
image: "img:tag",

0 commit comments

Comments
 (0)