github.com/openshift/installer@v1.4.17/pkg/asset/ignition/bootstrap/registries.go (about)

     1  package bootstrap
     2  
     3  import (
     4  	"k8s.io/apimachinery/pkg/util/sets"
     5  
     6  	"github.com/openshift/installer/pkg/types"
     7  )
     8  
     9  // MergedMirrorSets consolidates a list of ImageDigestSources so that each
    10  // source appears only once.
    11  func MergedMirrorSets(sources []types.ImageDigestSource) []types.ImageDigestSource {
    12  	sourceSet := make(map[string][]string)
    13  	mirrorSet := make(map[string]sets.String)
    14  	orderedSources := []string{}
    15  
    16  	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()
    21  		}
    22  		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)
    26  			}
    27  		}
    28  	}
    29  
    30  	out := []types.ImageDigestSource{}
    31  	for _, source := range orderedSources {
    32  		out = append(out, types.ImageDigestSource{Source: source, Mirrors: sourceSet[source]})
    33  	}
    34  	return out
    35  }
    36  
    37  // ContentSourceToDigestMirror creates the ImageContentSource to ImageDigestSource struct
    38  // ImageContentSource is deprecated, use ImageDigestSource.
    39  func ContentSourceToDigestMirror(sources []types.ImageContentSource) []types.ImageDigestSource {
    40  	digestSources := []types.ImageDigestSource{}
    41  	for _, s := range sources {
    42  		digestSources = append(digestSources, types.ImageDigestSource(s))
    43  	}
    44  	return digestSources
    45  }