Skip to content

Commit 02535f7

Browse files
Merge pull request #10073 from sadasu/fix-mirrorSourcePolicy
OCPBUGS-56451: Use the ImageDigest SourcePolicy to configure image registry on bootstrap host
2 parents ccad892 + 4752371 commit 02535f7

File tree

6 files changed

+54
-11
lines changed

6 files changed

+54
-11
lines changed

data/data/bootstrap/files/etc/containers/registries.conf.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
location = "{{ $r.Endpoint.Location }}"
44
insecure = {{ $r.Endpoint.Insecure }}
55
mirror-by-digest-only = {{ $r.MirrorByDigestOnly }}
6+
blocked = {{ $r.Blocked }}
67

78
{{ range $m := $r.Mirrors -}}
89
[[registry.mirror]]

pkg/asset/agent/mirror/registriesconf.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/pkg/errors"
1313
"github.com/sirupsen/logrus"
1414

15+
configv1 "github.com/openshift/api/config/v1"
1516
"github.com/openshift/installer/pkg/asset"
1617
"github.com/openshift/installer/pkg/asset/agent"
1718
"github.com/openshift/installer/pkg/asset/agent/joiner"
@@ -220,6 +221,7 @@ func (i *RegistriesConf) generateRegistriesConf(imageDigestSources []types.Image
220221
registry := sysregistriesv2.Registry{}
221222
registry.Endpoint.Location = group.Source
222223
registry.MirrorByDigestOnly = true
224+
registry.Blocked = group.SourcePolicy == configv1.NeverContactSource
223225
for _, mirror := range group.Mirrors {
224226
registry.Mirrors = append(registry.Mirrors, sysregistriesv2.Endpoint{Location: mirror})
225227
}

pkg/asset/ignition/bootstrap/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ func (a *Common) getTemplateData(dependencies asset.Parents, bootstrapInPlace bo
308308
registry := sysregistriesv2.Registry{}
309309
registry.Endpoint.Location = group.Source
310310
registry.MirrorByDigestOnly = true
311+
registry.Blocked = group.SourcePolicy == configv1.NeverContactSource
311312
for _, mirror := range group.Mirrors {
312313
registry.Mirrors = append(registry.Mirrors, sysregistriesv2.Endpoint{Location: mirror})
313314
}

pkg/asset/ignition/bootstrap/registries.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,42 @@ package bootstrap
33
import (
44
"k8s.io/apimachinery/pkg/util/sets"
55

6+
configv1 "github.com/openshift/api/config/v1"
67
"github.com/openshift/installer/pkg/types"
78
)
89

10+
// sourceSetKey represents the set of fields that have to be unique to form
11+
// a merged list without duplicate entries for Image sources.
12+
type sourceSetKey struct {
13+
Source string
14+
SourcePolicy configv1.MirrorSourcePolicy
15+
}
16+
917
// MergedMirrorSets consolidates a list of ImageDigestSources so that each
1018
// source appears only once.
1119
func MergedMirrorSets(sources []types.ImageDigestSource) []types.ImageDigestSource {
12-
sourceSet := make(map[string][]string)
13-
mirrorSet := make(map[string]sets.String)
14-
orderedSources := []string{}
20+
sourceSet := make(map[sourceSetKey][]string)
21+
mirrorSet := make(map[sourceSetKey]sets.Set[string])
22+
orderedSources := []sourceSetKey{}
1523

1624
for _, group := range sources {
17-
if _, ok := sourceSet[group.Source]; !ok {
18-
orderedSources = append(orderedSources, group.Source)
19-
sourceSet[group.Source] = nil
20-
mirrorSet[group.Source] = sets.NewString()
25+
key := sourceSetKey{Source: group.Source, SourcePolicy: group.SourcePolicy}
26+
if _, ok := sourceSet[key]; !ok {
27+
orderedSources = append(orderedSources, key)
28+
sourceSet[key] = nil
29+
mirrorSet[key] = sets.New[string]()
2130
}
2231
for _, mirror := range group.Mirrors {
23-
if !mirrorSet[group.Source].Has(mirror) {
24-
sourceSet[group.Source] = append(sourceSet[group.Source], mirror)
25-
mirrorSet[group.Source].Insert(mirror)
32+
if !mirrorSet[key].Has(mirror) {
33+
sourceSet[key] = append(sourceSet[key], mirror)
34+
mirrorSet[key].Insert(mirror)
2635
}
2736
}
2837
}
2938

3039
out := []types.ImageDigestSource{}
3140
for _, source := range orderedSources {
32-
out = append(out, types.ImageDigestSource{Source: source, Mirrors: sourceSet[source]})
41+
out = append(out, types.ImageDigestSource{Source: source.Source, Mirrors: sourceSet[source], SourcePolicy: source.SourcePolicy})
3342
}
3443
return out
3544
}

pkg/asset/ignition/bootstrap/registries_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/stretchr/testify/assert"
77

8+
configv1 "github.com/openshift/api/config/v1"
89
"github.com/openshift/installer/pkg/types"
910
)
1011

@@ -117,6 +118,33 @@ func TestMergedMirrorSets(t *testing.T) {
117118
Source: "b",
118119
Mirrors: []string{"md", "mc"},
119120
}},
121+
}, {
122+
input: []types.ImageDigestSource{{
123+
Source: "a",
124+
Mirrors: []string{"ma"},
125+
SourcePolicy: configv1.NeverContactSource,
126+
}, {
127+
Source: "b",
128+
Mirrors: []string{"md", "mc"},
129+
SourcePolicy: configv1.NeverContactSource,
130+
}, {
131+
Source: "a",
132+
Mirrors: []string{"mb", "ma"},
133+
SourcePolicy: configv1.AllowContactingSource,
134+
}},
135+
expected: []types.ImageDigestSource{{
136+
Source: "a",
137+
Mirrors: []string{"ma"},
138+
SourcePolicy: configv1.NeverContactSource,
139+
}, {
140+
Source: "b",
141+
Mirrors: []string{"md", "mc"},
142+
SourcePolicy: configv1.NeverContactSource,
143+
}, {
144+
Source: "a",
145+
Mirrors: []string{"mb", "ma"},
146+
SourcePolicy: configv1.AllowContactingSource,
147+
}},
120148
}}
121149
for _, test := range tests {
122150
t.Run(test.name, func(t *testing.T) {

pkg/asset/imagebased/image/registriesconf.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/containers/image/v5/pkg/sysregistriesv2"
77
"github.com/pelletier/go-toml"
88

9+
configv1 "github.com/openshift/api/config/v1"
910
"github.com/openshift/installer/pkg/asset"
1011
"github.com/openshift/installer/pkg/asset/ignition/bootstrap"
1112
"github.com/openshift/installer/pkg/types"
@@ -73,6 +74,7 @@ func (i *RegistriesConf) generateRegistriesConf(imageDigestSources []types.Image
7374
registry := sysregistriesv2.Registry{}
7475
registry.Endpoint.Location = group.Source
7576
registry.MirrorByDigestOnly = true
77+
registry.Blocked = group.SourcePolicy == configv1.NeverContactSource
7678
for _, mirror := range group.Mirrors {
7779
registry.Mirrors = append(registry.Mirrors, sysregistriesv2.Endpoint{Location: mirror})
7880
}

0 commit comments

Comments
 (0)