Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 11 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/1999-cognoz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add support for a private registry with a custom port in a restic-helper image
18 changes: 10 additions & 8 deletions pkg/restore/restic_restore_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
14 changes: 12 additions & 2 deletions pkg/restore/restic_restore_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,30 @@ 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),
},
{
name: "config map with untagged image returns image with buildinfo.Version as tag",
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 {
Expand Down