diff --git a/pkg/sysregistriesv2/system_registries_v2_test.go b/pkg/sysregistriesv2/system_registries_v2_test.go index 6e4be24dff..867f547378 100644 --- a/pkg/sysregistriesv2/system_registries_v2_test.go +++ b/pkg/sysregistriesv2/system_registries_v2_test.go @@ -650,107 +650,104 @@ func TestPullSourcesFromReference(t *testing.T) { SystemRegistriesConfDirPath: "testdata/this-does-not-exist", } registries, err := GetRegistries(sys) - assert.Nil(t, err) - assert.Equal(t, 2, len(registries)) - - // Registry A allowing any kind of pull from mirrors - registryA, err := FindRegistry(sys, "registry-a.com/foo/image:latest") - assert.Nil(t, err) - assert.NotNil(t, registryA) - // Digest - referenceADigest := toNamedRef(t, "registry-a.com/foo/image@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") - pullSources, err := registryA.PullSourcesFromReference(referenceADigest) - assert.Nil(t, err) - assert.Equal(t, 3, len(pullSources)) - assert.Equal(t, "mirror-1.registry-a.com/image@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", pullSources[0].Reference.String()) - assert.True(t, pullSources[1].Endpoint.Insecure) - // Tag - referenceATag := toNamedRef(t, "registry-a.com/foo/image:aaa") - pullSources, err = registryA.PullSourcesFromReference(referenceATag) - assert.Nil(t, err) - assert.Equal(t, 3, len(pullSources)) - assert.Equal(t, "registry-a.com/bar/image:aaa", pullSources[2].Reference.String()) - - // Registry B allowing digests pull only from mirrors - registryB, err := FindRegistry(sys, "registry-b.com/foo/image:latest") - assert.Nil(t, err) - assert.NotNil(t, registryB) - // Digest - referenceBDigest := toNamedRef(t, "registry-b.com/foo/image@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") - pullSources, err = registryB.PullSourcesFromReference(referenceBDigest) - assert.Nil(t, err) - assert.Equal(t, 3, len(pullSources)) - assert.Equal(t, "registry-b.com/bar", pullSources[2].Endpoint.Location) - assert.Equal(t, "registry-b.com/bar/image@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", pullSources[2].Reference.String()) - // Tag - referenceBTag := toNamedRef(t, "registry-b.com/foo/image:aaa") - pullSources, err = registryB.PullSourcesFromReference(referenceBTag) - assert.Nil(t, err) - assert.Equal(t, 1, len(pullSources)) -} - -func TestPullSourcesMirrorFromReference(t *testing.T) { - sys := &types.SystemContext{ - SystemRegistriesConfPath: "testdata/pull-sources-mirror-reference.conf", - SystemRegistriesConfDirPath: "testdata/this-does-not-exist", - } - registries, err := GetRegistries(sys) require.NoError(t, err) - assert.Equal(t, 7, len(registries)) + assert.Equal(t, 9, len(registries)) digest := "@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" tag := ":aaa" for _, tc := range []struct { - registry string - digestSources []string - tagSources []string + registry string + repo string + digestSources []string + digestInsecure []bool + tagSources []string + tagInsecure []bool }{ + // Registry A allowing any kind of pull from mirrors + { + "registry-a.com/foo", + "image", + []string{"mirror-1.registry-a.com", "mirror-2.registry-a.com", "registry-a.com/bar"}, + []bool{false, true, false}, + []string{"mirror-1.registry-a.com", "mirror-2.registry-a.com", "registry-a.com/bar"}, + []bool{false, true, false}, + }, + // Registry B allowing digests pull only from mirrors + { + "registry-b.com/foo", + "image", + []string{"mirror-1.registry-b.com", "mirror-2.registry-b.com", "registry-b.com/bar"}, + []bool{false, false, false}, + []string{"registry-b.com/bar"}, + []bool{false}, + }, // Registry A has mirrors allow any kind of pull { - "registry-a.com/foo/image", + "registry-a.com/baz", + "image", []string{"mirror-1.registry-a.com", "mirror-2.registry-a.com", "registry-a.com/bar"}, + []bool{false, true, false}, []string{"mirror-1.registry-a.com", "mirror-2.registry-a.com", "registry-a.com/bar"}, + []bool{false, true, false}, }, // Registry B has mirrors allow digests pull only { - "registry-b.com/foo/image", + "registry-b.com/baz", + "image", []string{"mirror-1.registry-b.com", "mirror-2.registry-b.com", "registry-b.com/bar"}, + []bool{false, false, false}, []string{"registry-b.com/bar"}, + []bool{false}, }, // Registry C has a mirror allows digest pull only and a mirror allows any kind of pull { - "registry-c.com/foo/image", + "registry-c.com/baz", + "image", []string{"mirror-1.registry-c.com", "mirror-2.registry-c.com", "registry-c.com/bar"}, + []bool{false, false, false}, []string{"mirror-1.registry-c.com", "registry-c.com/bar"}, + []bool{false, false}, }, // Registry D set digest-only for registry level, allows only digest pulls // Registry D has no digest-only set for mirrors table { - "registry-d.com/foo/image", + "registry-d.com/baz", + "image", []string{"mirror-1.registry-d.com", "mirror-2.registry-d.com", "registry-d.com/bar"}, + []bool{false, false, false}, []string{"registry-d.com/bar"}, + []bool{false}, }, // Registry E has mirrors only allows tag pull { - "registry-e.com/foo/image", + "registry-e.com/baz", + "image", []string{"registry-e.com/bar"}, + []bool{false}, []string{"mirror-1.registry-e.com", "mirror-2.registry-e.com", "registry-e.com/bar"}, + []bool{false, false, false}, }, // Registry F has one tag only mirror does not allow digest pull { - "registry-f.com/foo/image", + "registry-f.com/baz", + "image", []string{"mirror-1.registry-f.com", "registry-f.com/bar"}, + []bool{false, false}, []string{"mirror-1.registry-f.com", "mirror-2.registry-f.com", "registry-f.com/bar"}, + []bool{false, false, false}, }, // Registry G has one digest-only pull and one tag only pull { - "registry-g.com/foo/image", + "registry-g.com/baz", + "image", []string{"mirror-1.registry-g.com", "mirror-3.registry-g.com", "mirror-4.registry-g.com", "registry-g.com/bar"}, + []bool{false, false, false, false}, []string{"mirror-2.registry-g.com", "mirror-3.registry-g.com", "mirror-4.registry-g.com", "registry-g.com/bar"}, + []bool{false, false, false, false}, }, } { // Digest - digestedRef := toNamedRef(t, tc.registry+digest) + digestedRef := toNamedRef(t, filepath.Join(tc.registry, tc.repo)+digest) registry, err := FindRegistry(sys, digestedRef.Name()) require.NoError(t, err) require.NotNil(t, registry) @@ -758,9 +755,11 @@ func TestPullSourcesMirrorFromReference(t *testing.T) { require.NoError(t, err) for i, s := range tc.digestSources { assert.Equal(t, s, pullSource[i].Endpoint.Location) + assert.Equal(t, filepath.Join(s, tc.repo)+digest, pullSource[i].Reference.String()) + assert.Equal(t, tc.digestInsecure[i], pullSource[i].Endpoint.Insecure) } // Tag - taggedRef := toNamedRef(t, tc.registry+tag) + taggedRef := toNamedRef(t, filepath.Join(tc.registry, tc.repo)+tag) registry, err = FindRegistry(sys, taggedRef.Name()) require.NoError(t, err) require.NotNil(t, registry) @@ -768,6 +767,8 @@ func TestPullSourcesMirrorFromReference(t *testing.T) { require.NoError(t, err) for i, s := range tc.tagSources { assert.Equal(t, s, pullSource[i].Endpoint.Location) + assert.Equal(t, filepath.Join(s, tc.repo)+tag, pullSource[i].Reference.String()) + assert.Equal(t, tc.tagInsecure[i], pullSource[i].Endpoint.Insecure) } } } diff --git a/pkg/sysregistriesv2/testdata/pull-sources-from-reference.conf b/pkg/sysregistriesv2/testdata/pull-sources-from-reference.conf index f01176dbae..ee50fdc2fc 100644 --- a/pkg/sysregistriesv2/testdata/pull-sources-from-reference.conf +++ b/pkg/sysregistriesv2/testdata/pull-sources-from-reference.conf @@ -19,3 +19,90 @@ location = "mirror-1.registry-b.com" [[registry.mirror]] location = "mirror-2.registry-b.com" + +[[registry]] +prefix = "registry-a.com/baz" +location = "registry-a.com/bar" + +[[registry.mirror]] +location = "mirror-1.registry-a.com" + +[[registry.mirror]] +location = "mirror-2.registry-a.com" +insecure = true + +[[registry]] +prefix = "registry-b.com/baz" +location = "registry-b.com/bar" + +[[registry.mirror]] +pull-from-mirror = "digest-only" +location = "mirror-1.registry-b.com" + +[[registry.mirror]] +pull-from-mirror = "digest-only" +location = "mirror-2.registry-b.com" + +[[registry]] +prefix = "registry-c.com/baz" +location = "registry-c.com/bar" + +[[registry.mirror]] +location = "mirror-1.registry-c.com" + +[[registry.mirror]] +pull-from-mirror = "digest-only" +location = "mirror-2.registry-c.com" + +[[registry]] +prefix = "registry-d.com/baz" +location = "registry-d.com/bar" +mirror-by-digest-only = true + +[[registry.mirror]] +location = "mirror-1.registry-d.com" + +[[registry.mirror]] +location = "mirror-2.registry-d.com" + +[[registry]] +prefix = "registry-e.com/baz" +location = "registry-e.com/bar" + +[[registry.mirror]] +pull-from-mirror = "tag-only" +location = "mirror-1.registry-e.com" + +[[registry.mirror]] +pull-from-mirror = "tag-only" +location = "mirror-2.registry-e.com" + +[[registry]] +prefix = "registry-f.com/baz" +location = "registry-f.com/bar" + +[[registry.mirror]] +location = "mirror-1.registry-f.com" + +[[registry.mirror]] +pull-from-mirror = "tag-only" +location = "mirror-2.registry-f.com" + +[[registry]] +prefix = "registry-g.com/baz" +location = "registry-g.com/bar" + +[[registry.mirror]] +pull-from-mirror = "digest-only" +location = "mirror-1.registry-g.com" + +[[registry.mirror]] +pull-from-mirror = "tag-only" +location = "mirror-2.registry-g.com" + +[[registry.mirror]] +location = "mirror-3.registry-g.com" + +[[registry.mirror]] +pull-from-mirror = "all" +location = "mirror-4.registry-g.com" diff --git a/pkg/sysregistriesv2/testdata/pull-sources-mirror-reference.conf b/pkg/sysregistriesv2/testdata/pull-sources-mirror-reference.conf deleted file mode 100644 index 50d51c2892..0000000000 --- a/pkg/sysregistriesv2/testdata/pull-sources-mirror-reference.conf +++ /dev/null @@ -1,86 +0,0 @@ -[[registry]] -prefix = "registry-a.com/foo" -location = "registry-a.com/bar" - -[[registry.mirror]] -location = "mirror-1.registry-a.com" - -[[registry.mirror]] -location = "mirror-2.registry-a.com" -insecure = true - -[[registry]] -prefix = "registry-b.com/foo" -location = "registry-b.com/bar" - -[[registry.mirror]] -pull-from-mirror = "digest-only" -location = "mirror-1.registry-b.com" - -[[registry.mirror]] -pull-from-mirror = "digest-only" -location = "mirror-2.registry-b.com" - -[[registry]] -prefix = "registry-c.com/foo" -location = "registry-c.com/bar" - -[[registry.mirror]] -location = "mirror-1.registry-c.com" - -[[registry.mirror]] -pull-from-mirror = "digest-only" -location = "mirror-2.registry-c.com" - -[[registry]] -prefix = "registry-d.com/foo" -location = "registry-d.com/bar" -mirror-by-digest-only = true - -[[registry.mirror]] -location = "mirror-1.registry-d.com" - -[[registry.mirror]] -location = "mirror-2.registry-d.com" - -[[registry]] -prefix = "registry-e.com/foo" -location = "registry-e.com/bar" - -[[registry.mirror]] -pull-from-mirror = "tag-only" -location = "mirror-1.registry-e.com" - -[[registry.mirror]] -pull-from-mirror = "tag-only" -location = "mirror-2.registry-e.com" - -[[registry]] -prefix = "registry-f.com/foo" -location = "registry-f.com/bar" - -[[registry.mirror]] -location = "mirror-1.registry-f.com" - -[[registry.mirror]] -pull-from-mirror = "tag-only" -location = "mirror-2.registry-f.com" - -[[registry]] -prefix = "registry-g.com/foo" -location = "registry-g.com/bar" - -[[registry.mirror]] -pull-from-mirror = "digest-only" -location = "mirror-1.registry-g.com" - -[[registry.mirror]] -pull-from-mirror = "tag-only" -location = "mirror-2.registry-g.com" - -[[registry.mirror]] -location = "mirror-3.registry-g.com" - -[[registry.mirror]] -pull-from-mirror = "all" -location = "mirror-4.registry-g.com"