Skip to content

Commit

Permalink
mysqlcluster:fix image without namespace error
Browse files Browse the repository at this point in the history
  • Loading branch information
zhl003 committed Nov 3, 2022
2 parents fa20056 + 3626a19 commit 2925dc4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 10 additions & 4 deletions mysqlcluster/mysqlcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,18 @@ func GetPrefixFromEnv() string {

// GetImage returns the image name with the prefix and override.
func GetImage(name string) string {
var image_namespace string
prefix := GetPrefixFromEnv()
override := os.Getenv("IMAGE_NAMESPACE_OVERRIDE")
imagearray := strings.Split(name, "/")
image_namespace := strings.Join(imagearray[0:len(imagearray)-1], "/")
imageArray := strings.Split(name, "/")
if len(imageArray) == 1 {
image_namespace = ""
} else {
image_namespace = strings.Join(imageArray[0:len(imageArray)-1], "/") + "/"
}
if len(override) > 0 {
image_namespace = override
image_namespace = override + "/"
}
return prefix + image_namespace + "/" + imagearray[len(imagearray)-1]

return prefix + image_namespace + imageArray[len(imageArray)-1]
}
9 changes: 9 additions & 0 deletions mysqlcluster/mysqlcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,4 +752,13 @@ func TestGetImage(t *testing.T) {
result := GetImage(testCase)
assert.Equal(t, want, result)
}
{
// No image namespace
t.Setenv("IMAGE_PREFIX", "")
t.Setenv("IMAGE_NAMESPACE_OVERRIDE", "")
testCase := "busybox:1.32"
want := "busybox:1.32"
result := GetImage(testCase)
assert.Equal(t, want, result)
}
}

0 comments on commit 2925dc4

Please sign in to comment.