github.com/openshift/installer@v1.4.17/pkg/asset/manifests/imagedigestmirrorset.go (about) 1 package manifests 2 3 import ( 4 "context" 5 "path/filepath" 6 7 "github.com/pkg/errors" 8 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 9 "sigs.k8s.io/yaml" 10 11 apicfgv1 "github.com/openshift/api/config/v1" 12 "github.com/openshift/installer/pkg/asset" 13 "github.com/openshift/installer/pkg/asset/installconfig" 14 ) 15 16 var imageDigestMirrorSetFilename = "image-digest-mirror-set.yaml" 17 18 // ImageDigestMirrorSet generates the image-digest-mirror-set.yaml file. 19 type ImageDigestMirrorSet struct { 20 File *asset.File 21 } 22 23 var _ asset.WritableAsset = (*ImageDigestMirrorSet)(nil) 24 25 // Name returns a human-friendly name for the asset. 26 func (*ImageDigestMirrorSet) Name() string { 27 return "Image Digest Mirror Set" 28 } 29 30 // Dependencies returns all of the dependencies directly needed to generate 31 // the asset. 32 func (*ImageDigestMirrorSet) Dependencies() []asset.Asset { 33 return []asset.Asset{ 34 &installconfig.InstallConfig{}, 35 } 36 } 37 38 // Generate generates the ImageDigestMirrorSet config and its CR. 39 func (p *ImageDigestMirrorSet) Generate(_ context.Context, dependencies asset.Parents) error { 40 installconfig := &installconfig.InstallConfig{} 41 dependencies.Get(installconfig) 42 43 if len(installconfig.Config.ImageDigestSources) > 0 { 44 policy := apicfgv1.ImageDigestMirrorSet{ 45 TypeMeta: metav1.TypeMeta{ 46 APIVersion: apicfgv1.SchemeGroupVersion.String(), 47 Kind: "ImageDigestMirrorSet", 48 }, 49 ObjectMeta: metav1.ObjectMeta{ 50 Name: "image-digest-mirror", 51 // not namespaced 52 }, 53 } 54 55 policy.Spec.ImageDigestMirrors = make([]apicfgv1.ImageDigestMirrors, len(installconfig.Config.ImageDigestSources)) 56 for gidx, group := range installconfig.Config.ImageDigestSources { 57 mirrors := []apicfgv1.ImageMirror{} 58 for _, m := range group.Mirrors { 59 mirrors = append(mirrors, apicfgv1.ImageMirror(m)) 60 } 61 policy.Spec.ImageDigestMirrors[gidx] = apicfgv1.ImageDigestMirrors{Source: group.Source, Mirrors: mirrors} 62 } 63 64 policyData, err := yaml.Marshal(policy) 65 if err != nil { 66 return errors.Wrapf(err, "failed to marshal ImageDigestMirrorSet") 67 } 68 p.File = &asset.File{ 69 Filename: filepath.Join(manifestDir, imageDigestMirrorSetFilename), 70 Data: policyData, 71 } 72 } 73 return nil 74 } 75 76 // Files returns the files generated by the asset. 77 func (p *ImageDigestMirrorSet) Files() []*asset.File { 78 if p.File == nil { 79 return nil 80 } 81 return []*asset.File{p.File} 82 } 83 84 // Load loads the already-rendered files back from disk. 85 func (p *ImageDigestMirrorSet) Load(f asset.FileFetcher) (bool, error) { 86 return false, nil 87 }