Skip to content

Commit 58df567

Browse files
committed
Update image registry configuration on bootstrap host
A new policy was added to the ImageDigestSource configuration that allows the user to specify policy when there is a failure pulling an image from the source. Update the image registry configuration on the bootstrap host with this SourcePolicy.
1 parent fb1c669 commit 58df567

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-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/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: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,40 @@ 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+
type SourceSetKey struct {
11+
Source string
12+
SourcePolicy configv1.MirrorSourcePolicy
13+
}
14+
915
// MergedMirrorSets consolidates a list of ImageDigestSources so that each
1016
// source appears only once.
1117
func MergedMirrorSets(sources []types.ImageDigestSource) []types.ImageDigestSource {
12-
sourceSet := make(map[string][]string)
13-
mirrorSet := make(map[string]sets.String)
14-
orderedSources := []string{}
18+
sourceSet := make(map[SourceSetKey][]string)
19+
mirrorSet := make(map[SourceSetKey]sets.String)
20+
orderedSources := []SourceSetKey{}
1521

1622
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()
23+
key := SourceSetKey{Source: group.Source, SourcePolicy: group.SourcePolicy}
24+
if _, ok := sourceSet[key]; !ok {
25+
orderedSources = append(orderedSources, key)
26+
sourceSet[key] = nil
27+
mirrorSet[key] = sets.NewString()
2128
}
2229
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)
30+
if !mirrorSet[key].Has(mirror) {
31+
sourceSet[key] = append(sourceSet[key], mirror)
32+
mirrorSet[key].Insert(mirror)
2633
}
2734
}
2835
}
2936

3037
out := []types.ImageDigestSource{}
3138
for _, source := range orderedSources {
32-
out = append(out, types.ImageDigestSource{Source: source, Mirrors: sourceSet[source]})
39+
out = append(out, types.ImageDigestSource{Source: source.Source, Mirrors: sourceSet[source], SourcePolicy: source.SourcePolicy})
3340
}
3441
return out
3542
}

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) {

0 commit comments

Comments
 (0)