@@ -10,6 +10,7 @@ import (
1010 "path/filepath"
1111 "time"
1212
13+ "github.com/openshift/machine-config-operator/pkg/imageutils"
1314 "github.com/openshift/machine-config-operator/pkg/osimagestream"
1415 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1516
@@ -220,33 +221,19 @@ func (b *Bootstrap) Run(destDir string) error {
220221 var osImageStream * mcfgv1alpha1.OSImageStream
221222 // Enable OSImageStreams if the FeatureGate is active and the deployment is not OKD
222223 if osimagestream .IsFeatureEnabled (fgHandler ) {
223- ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
224- defer cancel ()
225-
226- osImageStream , err = osimagestream .BuildOsImageStreamBootstrap (ctx ,
227- pullSecret ,
228- cconfig ,
229- imageStream ,
230- & osimagestream.OSImageTuple {
231- OSImage : cconfig .Spec .BaseOSContainerImage ,
232- OSExtensionsImage : cconfig .Spec .BaseOSExtensionsContainerImage ,
233- },
234- osimagestream .NewDefaultStreamSourceFactory (nil , & osimagestream.DefaultImagesInspectorFactory {}),
235- )
224+ osImageStream , err = b .fetchOSImageStream (imageStream , cconfig , icspRules , idmsRules , itmsRules , imgCfg , pullSecret )
236225 if err != nil {
237- return fmt . Errorf ( "error inspecting available OSImageStreams: %w" , err )
226+ return err
238227 }
239228
240- // If no error happened override the ControllerConfig URLs with the default stream ones
241- if err == nil {
242- defaultStreamSet , err := osimagestream .GetOSImageStreamSetByName (osImageStream , "" )
243- if err != nil {
244- // Should never happen
245- return fmt .Errorf ("error getting default OSImageStreamSet: %w" , err )
246- }
247- cconfig .Spec .BaseOSContainerImage = string (defaultStreamSet .OSImage )
248- cconfig .Spec .BaseOSExtensionsContainerImage = string (defaultStreamSet .OSExtensionsImage )
229+ // Override the ControllerConfig URLs with the default stream ones
230+ defaultStreamSet , err := osimagestream .GetOSImageStreamSetByName (osImageStream , "" )
231+ if err != nil {
232+ // Should never happen
233+ return fmt .Errorf ("error getting default OSImageStreamSet: %w" , err )
249234 }
235+ cconfig .Spec .BaseOSContainerImage = string (defaultStreamSet .OSImage )
236+ cconfig .Spec .BaseOSExtensionsContainerImage = string (defaultStreamSet .OSExtensionsImage )
250237 }
251238
252239 pullSecretBytes := pullSecret .Data [corev1 .DockerConfigJsonKey ]
@@ -416,6 +403,46 @@ func (b *Bootstrap) Run(destDir string) error {
416403
417404}
418405
406+ func (b * Bootstrap ) fetchOSImageStream (
407+ imageStream * imagev1.ImageStream ,
408+ cconfig * mcfgv1.ControllerConfig ,
409+ icspRules []* apioperatorsv1alpha1.ImageContentSourcePolicy ,
410+ idmsRules []* apicfgv1.ImageDigestMirrorSet ,
411+ itmsRules []* apicfgv1.ImageTagMirrorSet ,
412+ imgCfg * apicfgv1.Image ,
413+ pullSecret * corev1.Secret ,
414+ ) (* mcfgv1alpha1.OSImageStream , error ) {
415+
416+ ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
417+ defer cancel ()
418+
419+ sysCtxBuilder := imageutils .NewSysContextBuilder ().
420+ WithControllerConfig (cconfig ).
421+ WithSecret (pullSecret )
422+
423+ registriesConfig , err := imageutils .GenerateRegistriesConfig (imgCfg , icspRules , idmsRules , itmsRules )
424+ if err != nil {
425+ return nil , fmt .Errorf ("failed to generate registries config for OSImageStreams fetching: %w" , err )
426+ }
427+ if registriesConfig != nil {
428+ sysCtxBuilder .WithRegistriesConfig (registriesConfig )
429+ }
430+
431+ osImageStream , err := osimagestream .BuildOsImageStreamBootstrap (ctx ,
432+ sysCtxBuilder ,
433+ imageStream ,
434+ & osimagestream.OSImageTuple {
435+ OSImage : cconfig .Spec .BaseOSContainerImage ,
436+ OSExtensionsImage : cconfig .Spec .BaseOSExtensionsContainerImage ,
437+ },
438+ osimagestream .NewDefaultStreamSourceFactory (nil , & osimagestream.DefaultImagesInspectorFactory {}),
439+ )
440+ if err != nil {
441+ return nil , fmt .Errorf ("error inspecting available OSImageStreams: %w" , err )
442+ }
443+ return osImageStream , nil
444+ }
445+
419446func getValidPullSecretFromBytes (sData []byte ) (* corev1.Secret , error ) {
420447 obji , err := runtime .Decode (kscheme .Codecs .UniversalDecoder (corev1 .SchemeGroupVersion ), sData )
421448 if err != nil {
0 commit comments