Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
location = "{{ $r.Endpoint.Location }}"
insecure = {{ $r.Endpoint.Insecure }}
mirror-by-digest-only = {{ $r.MirrorByDigestOnly }}
blocked = {{ $r.Blocked }}

{{ range $m := $r.Mirrors -}}
[[registry.mirror]]
Expand Down
2 changes: 2 additions & 0 deletions pkg/asset/agent/mirror/registriesconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/agent"
"github.com/openshift/installer/pkg/asset/agent/joiner"
Expand Down Expand Up @@ -220,6 +221,7 @@ func (i *RegistriesConf) generateRegistriesConf(imageDigestSources []types.Image
registry := sysregistriesv2.Registry{}
registry.Endpoint.Location = group.Source
registry.MirrorByDigestOnly = true
registry.Blocked = group.SourcePolicy == configv1.NeverContactSource
for _, mirror := range group.Mirrors {
registry.Mirrors = append(registry.Mirrors, sysregistriesv2.Endpoint{Location: mirror})
}
Expand Down
1 change: 1 addition & 0 deletions pkg/asset/ignition/bootstrap/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ func (a *Common) getTemplateData(dependencies asset.Parents, bootstrapInPlace bo
registry := sysregistriesv2.Registry{}
registry.Endpoint.Location = group.Source
registry.MirrorByDigestOnly = true
registry.Blocked = group.SourcePolicy == configv1.NeverContactSource
for _, mirror := range group.Mirrors {
registry.Mirrors = append(registry.Mirrors, sysregistriesv2.Endpoint{Location: mirror})
}
Expand Down
31 changes: 20 additions & 11 deletions pkg/asset/ignition/bootstrap/registries.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,42 @@ package bootstrap
import (
"k8s.io/apimachinery/pkg/util/sets"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/installer/pkg/types"
)

// sourceSetKey represents the set of fields that have to be unique to form
// a merged list without duplicate entries for Image sources.
type sourceSetKey struct {
Source string
SourcePolicy configv1.MirrorSourcePolicy
}

// MergedMirrorSets consolidates a list of ImageDigestSources so that each
// source appears only once.
func MergedMirrorSets(sources []types.ImageDigestSource) []types.ImageDigestSource {
sourceSet := make(map[string][]string)
mirrorSet := make(map[string]sets.String)
orderedSources := []string{}
sourceSet := make(map[sourceSetKey][]string)
mirrorSet := make(map[sourceSetKey]sets.Set[string])
orderedSources := []sourceSetKey{}

for _, group := range sources {
if _, ok := sourceSet[group.Source]; !ok {
orderedSources = append(orderedSources, group.Source)
sourceSet[group.Source] = nil
mirrorSet[group.Source] = sets.NewString()
key := sourceSetKey{Source: group.Source, SourcePolicy: group.SourcePolicy}
if _, ok := sourceSet[key]; !ok {
orderedSources = append(orderedSources, key)
sourceSet[key] = nil
mirrorSet[key] = sets.New[string]()
}
for _, mirror := range group.Mirrors {
if !mirrorSet[group.Source].Has(mirror) {
sourceSet[group.Source] = append(sourceSet[group.Source], mirror)
mirrorSet[group.Source].Insert(mirror)
if !mirrorSet[key].Has(mirror) {
sourceSet[key] = append(sourceSet[key], mirror)
mirrorSet[key].Insert(mirror)
}
}
}

out := []types.ImageDigestSource{}
for _, source := range orderedSources {
out = append(out, types.ImageDigestSource{Source: source, Mirrors: sourceSet[source]})
out = append(out, types.ImageDigestSource{Source: source.Source, Mirrors: sourceSet[source], SourcePolicy: source.SourcePolicy})
}
return out
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/asset/ignition/bootstrap/registries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/stretchr/testify/assert"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/installer/pkg/types"
)

Expand Down Expand Up @@ -117,6 +118,33 @@ func TestMergedMirrorSets(t *testing.T) {
Source: "b",
Mirrors: []string{"md", "mc"},
}},
}, {
input: []types.ImageDigestSource{{
Source: "a",
Mirrors: []string{"ma"},
SourcePolicy: configv1.NeverContactSource,
}, {
Source: "b",
Mirrors: []string{"md", "mc"},
SourcePolicy: configv1.NeverContactSource,
}, {
Source: "a",
Mirrors: []string{"mb", "ma"},
SourcePolicy: configv1.AllowContactingSource,
}},
expected: []types.ImageDigestSource{{
Source: "a",
Mirrors: []string{"ma"},
SourcePolicy: configv1.NeverContactSource,
}, {
Source: "b",
Mirrors: []string{"md", "mc"},
SourcePolicy: configv1.NeverContactSource,
}, {
Source: "a",
Mirrors: []string{"mb", "ma"},
SourcePolicy: configv1.AllowContactingSource,
}},
}}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/asset/imagebased/image/registriesconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/containers/image/v5/pkg/sysregistriesv2"
"github.com/pelletier/go-toml"

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