Add support for private registry with custom port in restic-helper image (#1999)

* Add support for private registry with custom port in restic-helper image definition

Signed-off-by: Roman Klimenko <cognoz@ya.ru>
pull/2095/head
Roman Klimenko 2019-12-04 19:01:39 +03:00 committed by Carlisia Campos
parent 6395fa086d
commit 87be775139
3 changed files with 23 additions and 10 deletions

View File

@ -0,0 +1 @@
add support for a private registry with a custom port in a restic-helper image

View File

@ -156,20 +156,22 @@ func getImage(log logrus.FieldLogger, config *corev1.ConfigMap) string {
log = log.WithField("image", image)
parts := strings.Split(image, ":")
switch {
case len(parts) == 1:
parts := strings.Split(image, "/")
if len(parts) == 1 {
// Image supplied without registry part
log.Debugf("Plugin config contains image name without registry name. Return defaultImageBase")
return initContainerImage(defaultImageBase)
}
if !(strings.Contains(parts[len(parts)-1], ":")) {
// tag-less image name: add tag
log.Debugf("Plugin config contains image name without tag. Adding tag.")
return initContainerImage(image)
case len(parts) == 2:
} else {
// tagged image name
log.Debugf("Plugin config contains image name with tag")
return image
default:
// unrecognized
log.Warnf("Plugin config contains unparseable image name")
return initContainerImage(defaultImageBase)
}
}

View File

@ -69,8 +69,8 @@ func TestGetImage(t *testing.T) {
want: fmt.Sprintf("%s:%s", defaultImageBase, buildinfo.Version),
},
{
name: "config map with invalid data in 'image' key returns default image with buildinfo.Version as tag",
configMap: configMapWithData("image", "not:valid:image"),
name: "config map without '/' in image name returns default image with buildinfo.Version as tag",
configMap: configMapWithData("image", "my-image"),
want: fmt.Sprintf("%s:%s", defaultImageBase, buildinfo.Version),
},
{
@ -78,11 +78,21 @@ func TestGetImage(t *testing.T) {
configMap: configMapWithData("image", "myregistry.io/my-image"),
want: fmt.Sprintf("%s:%s", "myregistry.io/my-image", buildinfo.Version),
},
{
name: "config map with untagged image and custom registry port with ':' returns image with buildinfo.Version as tag",
configMap: configMapWithData("image", "myregistry.io:34567/my-image"),
want: fmt.Sprintf("%s:%s", "myregistry.io:34567/my-image", buildinfo.Version),
},
{
name: "config map with tagged image returns tagged image",
configMap: configMapWithData("image", "myregistry.io/my-image:my-tag"),
want: "myregistry.io/my-image:my-tag",
},
{
name: "config map with tagged image and custom registry port with ':' returns tagged image",
configMap: configMapWithData("image", "myregistry.io:34567/my-image:my-tag"),
want: "myregistry.io:34567/my-image:my-tag",
},
}
for _, test := range tests {