Skip to content

Commit a0dd63f

Browse files
committedNov 1, 2019
fix(mirror): canonicalize names before swapping domain
1 parent 963728d commit a0dd63f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed
 

‎pkg/mirror/mirror.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,13 @@ func (b *IndexImageMirrorer) Mirror() (map[string]string, error) {
9595

9696
var errs []error
9797
for _, img := range images {
98-
ref, err := reference.ParseNamed(img)
98+
ref, err := reference.ParseNormalizedNamed(img)
9999
if err != nil {
100100
errs = append(errs, fmt.Errorf("couldn't parse image for mirroring (%s), skipping mirror: %s", img, err.Error()))
101101
continue
102102
}
103-
104103
domain := reference.Domain(ref)
105-
mapping[img] = b.Dest + strings.TrimPrefix(img, domain)
104+
mapping[ref.String()] = b.Dest + strings.TrimPrefix(ref.String(), domain)
106105
}
107106

108107
if err := b.ImageMirrorer.Mirror(mapping); err != nil {

‎pkg/mirror/mirror_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ func TestIndexImageMirrorer_Mirror(t *testing.T) {
7474
"quay.io/coreos/prometheus-operator@sha256:0e92dd9b5789c4b13d53e1319d0a6375bcca4caaf0d698af61198061222a576d":"localhost/coreos/prometheus-operator@sha256:0e92dd9b5789c4b13d53e1319d0a6375bcca4caaf0d698af61198061222a576d",
7575
"quay.io/coreos/prometheus-operator@sha256:3daa69a8c6c2f1d35dcf1fe48a7cd8b230e55f5229a1ded438f687debade5bcf":"localhost/coreos/prometheus-operator@sha256:3daa69a8c6c2f1d35dcf1fe48a7cd8b230e55f5229a1ded438f687debade5bcf",
7676
"quay.io/coreos/prometheus-operator@sha256:5037b4e90dbb03ebdefaa547ddf6a1f748c8eeebeedf6b9d9f0913ad662b5731":"localhost/coreos/prometheus-operator@sha256:5037b4e90dbb03ebdefaa547ddf6a1f748c8eeebeedf6b9d9f0913ad662b5731",
77+
"docker.io/strimzi/cluster-operator:0.11.0": "localhost/strimzi/cluster-operator:0.11.0",
78+
"docker.io/strimzi/cluster-operator:0.11.1": "localhost/strimzi/cluster-operator:0.11.1",
79+
"docker.io/strimzi/operator:0.12.1": "localhost/strimzi/operator:0.12.1",
80+
"docker.io/strimzi/operator:0.12.2": "localhost/strimzi/operator:0.12.2",
7781
},
78-
// strimzi has invalid images in its manifests, so we both return a list of maps and an error
79-
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]"),
8082
},
8183
}
8284
for _, tt := range tests {
@@ -95,7 +97,9 @@ func TestIndexImageMirrorer_Mirror(t *testing.T) {
9597
Dest: tt.fields.Dest,
9698
}
9799
got, err := b.Mirror()
98-
require.Equal(t, tt.wantErr.Error(), err.Error())
100+
if err != nil {
101+
require.Equal(t, tt.wantErr.Error(), err.Error())
102+
}
99103
require.Equal(t, tt.want, got)
100104
})
101105
}

0 commit comments

Comments
 (0)
Please sign in to comment.