From a0dd63fb960bce0f9219a80bcfd910bcc32a2f5d Mon Sep 17 00:00:00 2001 From: Evan Cordell Date: Fri, 1 Nov 2019 15:08:54 -0400 Subject: [PATCH] fix(mirror): canonicalize names before swapping domain --- pkg/mirror/mirror.go | 5 ++--- pkg/mirror/mirror_test.go | 10 +++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/mirror/mirror.go b/pkg/mirror/mirror.go index f9b6ad427..428e68d57 100644 --- a/pkg/mirror/mirror.go +++ b/pkg/mirror/mirror.go @@ -95,14 +95,13 @@ func (b *IndexImageMirrorer) Mirror() (map[string]string, error) { var errs []error for _, img := range images { - ref, err := reference.ParseNamed(img) + ref, err := reference.ParseNormalizedNamed(img) if err != nil { errs = append(errs, fmt.Errorf("couldn't parse image for mirroring (%s), skipping mirror: %s", img, err.Error())) continue } - domain := reference.Domain(ref) - mapping[img] = b.Dest + strings.TrimPrefix(img, domain) + mapping[ref.String()] = b.Dest + strings.TrimPrefix(ref.String(), domain) } if err := b.ImageMirrorer.Mirror(mapping); err != nil { diff --git a/pkg/mirror/mirror_test.go b/pkg/mirror/mirror_test.go index bdbdd0944..12a237730 100644 --- a/pkg/mirror/mirror_test.go +++ b/pkg/mirror/mirror_test.go @@ -74,9 +74,11 @@ func TestIndexImageMirrorer_Mirror(t *testing.T) { "quay.io/coreos/prometheus-operator@sha256:0e92dd9b5789c4b13d53e1319d0a6375bcca4caaf0d698af61198061222a576d":"localhost/coreos/prometheus-operator@sha256:0e92dd9b5789c4b13d53e1319d0a6375bcca4caaf0d698af61198061222a576d", "quay.io/coreos/prometheus-operator@sha256:3daa69a8c6c2f1d35dcf1fe48a7cd8b230e55f5229a1ded438f687debade5bcf":"localhost/coreos/prometheus-operator@sha256:3daa69a8c6c2f1d35dcf1fe48a7cd8b230e55f5229a1ded438f687debade5bcf", "quay.io/coreos/prometheus-operator@sha256:5037b4e90dbb03ebdefaa547ddf6a1f748c8eeebeedf6b9d9f0913ad662b5731":"localhost/coreos/prometheus-operator@sha256:5037b4e90dbb03ebdefaa547ddf6a1f748c8eeebeedf6b9d9f0913ad662b5731", + "docker.io/strimzi/cluster-operator:0.11.0": "localhost/strimzi/cluster-operator:0.11.0", + "docker.io/strimzi/cluster-operator:0.11.1": "localhost/strimzi/cluster-operator:0.11.1", + "docker.io/strimzi/operator:0.12.1": "localhost/strimzi/operator:0.12.1", + "docker.io/strimzi/operator:0.12.2": "localhost/strimzi/operator:0.12.2", }, - // strimzi has invalid images in its manifests, so we both return a list of maps and an error - wantErr: fmt.Errorf("[couldn't parse image for mirroring (strimzi/cluster-operator:0.11.0), skipping mirror: repository name must be canonical, couldn't parse image for mirroring (strimzi/cluster-operator:0.11.1), skipping mirror: repository name must be canonical, couldn't parse image for mirroring (strimzi/operator:0.12.1), skipping mirror: repository name must be canonical, couldn't parse image for mirroring (strimzi/operator:0.12.2), skipping mirror: repository name must be canonical]"), }, } for _, tt := range tests { @@ -95,7 +97,9 @@ func TestIndexImageMirrorer_Mirror(t *testing.T) { Dest: tt.fields.Dest, } got, err := b.Mirror() - require.Equal(t, tt.wantErr.Error(), err.Error()) + if err != nil { + require.Equal(t, tt.wantErr.Error(), err.Error()) + } require.Equal(t, tt.want, got) }) }