github.com/openshift/installer@v1.4.17/pkg/asset/imagebased/image/registriesconf.go (about) 1 package image 2 3 import ( 4 "context" 5 6 "github.com/containers/image/v5/pkg/sysregistriesv2" 7 "github.com/pelletier/go-toml" 8 9 "github.com/openshift/installer/pkg/asset" 10 "github.com/openshift/installer/pkg/asset/ignition/bootstrap" 11 "github.com/openshift/installer/pkg/types" 12 ) 13 14 // RegistriesConf generates the registries.conf data. 15 type RegistriesConf struct { 16 Data []byte 17 Config *sysregistriesv2.V2RegistriesConf 18 } 19 20 // Name returns a human friendly name for the asset. 21 func (*RegistriesConf) Name() string { 22 return "Mirror Registries Config" 23 } 24 25 // Dependencies returns all of the dependencies directly needed to generate 26 // the asset. 27 func (*RegistriesConf) Dependencies() []asset.Asset { 28 return []asset.Asset{ 29 &ImageBasedInstallationConfig{}, 30 } 31 } 32 33 // Generate generates the registries.conf data from the image-based-installation-config. 34 func (i *RegistriesConf) Generate(_ context.Context, dependencies asset.Parents) error { 35 ibiConfig := &ImageBasedInstallationConfig{} 36 dependencies.Get(ibiConfig) 37 38 if ibiConfig.Config == nil { 39 return nil 40 } 41 42 imageDigestSources := ibiConfig.Config.ImageDigestSources 43 44 if len(imageDigestSources) == 0 { 45 return nil 46 } 47 48 err := i.generateRegistriesConf(imageDigestSources) 49 if err != nil { 50 return err 51 } 52 53 i.Data, err = toml.Marshal(i.Config) 54 if err != nil { 55 return err 56 } 57 58 return nil 59 } 60 61 func (i *RegistriesConf) generateRegistriesConf(imageDigestSources []types.ImageDigestSource) error { 62 digestMirrorSources := []types.ImageDigestSource{} 63 digestMirrorSources = append(digestMirrorSources, imageDigestSources...) 64 65 registries := &sysregistriesv2.V2RegistriesConf{ 66 Registries: []sysregistriesv2.Registry{}, 67 } 68 for _, group := range bootstrap.MergedMirrorSets(digestMirrorSources) { 69 if len(group.Mirrors) == 0 { 70 continue 71 } 72 73 registry := sysregistriesv2.Registry{} 74 registry.Endpoint.Location = group.Source 75 registry.MirrorByDigestOnly = true 76 for _, mirror := range group.Mirrors { 77 registry.Mirrors = append(registry.Mirrors, sysregistriesv2.Endpoint{Location: mirror}) 78 } 79 registries.Registries = append(registries.Registries, registry) 80 } 81 i.Config = registries 82 83 return nil 84 }